Skip to content

feat(telemetry): per-signal OTLP switches under telemetry.otlp - #224

Merged
M0Rf30 merged 11 commits into
mainfrom
feat/otlp-signals
Oct 27, 2026
Merged

M0Rf30 merged 11 commits into
mainfrom
feat/otlp-signals

Conversation

@gjed

@gjed gjed commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #221. Design context: #196 (answer 2).

telemetry.otlp.enabled stays the master switch and keeps the shared endpoint, protocol, headers and TLS settings. It now has a switch per signal:

Key Env Default
traces OTEL_TRACES_EXPORTER true
metrics OTEL_METRICS_EXPORTER false
logs OTEL_LOGS_EXPORTER false
audit OPENARTIFACT_OTLP_AUDIT false

The OTEL_*_EXPORTER variables are comma-separated lists, as in the spec: a list containing otlp turns the signal on, otherwise none turns it off, and any other value is ignored.

  • Setup creates a provider only for the signals that are on. The tracer provider, Install (and with it Enabled()) and HTTPMiddleware only exist with traces.
  • logs or audit start one sdklog.LoggerProvider (otlploggrpc/otlploghttp), installed with otel.SetLoggerProvider. Both switches are documented as reserved: nothing writes to the provider until Telemetry: export application logs over OTLP #192 (logs) and Telemetry: stream audit events as OTLP logs #193 (audit).
  • enabled with every signal off installs nothing and logs one warning at startup.
  • An existing enabled: true keeps tracing exactly as before. See the upgrading note.
  • docker/otel-collector.yaml is a baseline otelcol-contrib config: OTLP in on localhost, memory_limiter + batch, otlp_http out to OTELCOL_EXPORT_ENDPOINT with the Authorization header from OTELCOL_EXPORT_AUTHORIZATION.
  • The opt-in compose profile otel-collector runs that config as its own service on artifact-repo-network, with OTELCOL_LISTEN_HOST=0.0.0.0 and no published ports. The server's compose endpoint defaults to http://otel-collector:4317, so either container can restart on its own. Outside compose the yaml binds localhost. The per-signal switches are passed through only when docker/.env sets them, so they never override a mounted config. OTELCOL_EXPORT_ENDPOINT is required with the profile.
  • The new keys are in .env.example, openartifact.example.yaml and docker/.env.example, docs/reference/config.md is regenerated, and docs/operations/monitoring.md and docs/getting-started/upgrading.md are updated.
  • New direct deps: otel/sdk/log, otlploggrpc, otlploghttp. otel/log and otel/metric move from indirect to direct.

Verification

  • make test, make deadcode and make docs-check pass, and go mod tidy -diff is clean.
  • make lint: the only finding locally is a nolintlint in pkg/rpm/dependencies.go:72. That file is unchanged here; the finding comes from the local golangci-lint 2.13.2.
  • TestSetupSignalMatrix covers traces only, metrics only, logs only, audit only, all off (with the warning) and master switch off. Each case checks which tracer, meter and logger providers are installed, Enabled() and the HTTP middleware.
  • The OTLP/HTTP test checks the /v1/logs export: auth header, scope and resource.
  • Config tests cover each env variable in both directions, exporter lists, and a file that only sets enabled: true. They clear the OpenTelemetry environment first, so the developer's shell cannot change the result.
  • End to end on an isolated compose stack (-p oa-otlp, --profile otel-collector, the Collector forwarding to a throwaway OTLP/HTTP sink):
    • Default: gRPC from the server to the Collector, then /v1/traces at the sink with Authorization: Bearer …. The span was named GET /api/v1/system/info, and /health was not traced.
    • OTEL_TRACES_EXPORTER=none with OTEL_METRICS_EXPORTER=otlp: no traces, and /v1/metrics carried the openartifact_*/go_* families.
    • logs + audit only: the server is healthy and nothing is exported yet.
    • All signals off: the warning appears.
    • Restarting openartifact and otel-collector one at a time: traces keep arriving and the server logs no export errors.
    • Without OTELCOL_EXPORT_ENDPOINT the Collector exits with at least one endpoint must be specified, which is now documented. docker compose config passes with and without the profile.
    • otelcol-contrib validate passes, and the deprecated otlphttp alias is replaced by otlp_http.

@gjed gjed self-assigned this Oct 26, 2026
@gjed
gjed requested a review from M0Rf30 October 26, 2026 14:31
@gjed
gjed marked this pull request as draft October 26, 2026 14:32

@gjed gjed left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Reviewer is the PR author — review event submitted as COMMENT.

Review effort: Standard
Findings: 1 Medium severity · 3 Low severity

Open (4)
What changed in this PR

Splits telemetry.otlp into a master switch plus per-signal switches (traces, metrics, logs, audit) sharing one endpoint, and adds an opt-in local Collector to the compose stack (closes #221).

Changes:

  • Setup builds the resource and error handler once, then starts a provider only for each enabled signal; the tracer provider, Install/Enabled() and HTTPMiddleware exist only with traces.
  • logs or audit start one OTLP sdklog.LoggerProvider (gRPC or HTTP, /v1/logs) installed with otel.SetLoggerProvider; nothing writes to it yet.
  • enabled: true with every signal off installs nothing and logs one startup warning; shutdown restores the no-op meter and logger providers.
  • New env overrides OTEL_TRACES_EXPORTER, OTEL_LOGS_EXPORTER (otlp/none) and OPENARTIFACT_OTLP_AUDIT; OTEL_METRICS_EXPORTER moves to the shared overrideExporter helper.
  • Compose gains an otel-collector profile running otelcol-contrib in the app container's network namespace with a baseline config, and passes the OTEL variables through from docker/.env.
  • Docs, example configs and the upgrading note describe the new keys; otel/sdk/log and the otlplog exporters become direct dependencies.
File Description
internal/telemetry/setup.go Per-signal provider startup (startProviders), log provider, all-off warning, shutdown restores no-op providers
internal/telemetry/config.go Traces/Logs/Audit fields, anySignal, traces: true default
internal/telemetry/setup_test.go Signal matrix test and /v1/logs export check over OTLP/HTTP
internal/config/telemetry.go overrideExporter and the new env overrides
internal/config/telemetry_test.go Signal defaults, enabled-only file, env overrides both directions
cmd/server/app_startup.go Startup log lists every signal switch
docker/otel-collector.yaml New baseline Collector config: OTLP in on localhost, memory_limiter + batch, otlp_http out
docker/docker-compose.yml OTEL env pass-through and the otel-collector profile service
docker/.env.example, .env.example, openartifact.example.yaml New switches and Collector export variables
docs/operations/monitoring.md Signal table rows, log records section, local Collector section
docs/reference/config.md Regenerated for the new keys
docs/getting-started/upgrading.md Upgrade note: enabled: true keeps tracing
go.mod, go.sum otel/sdk/log, otlploggrpc, otlploghttp added; otel/log, otel/metric direct

Comment thread docker/docker-compose.yml Resolved
Comment thread internal/config/telemetry.go Resolved
Comment thread internal/telemetry/config.go Resolved
Comment thread docs/operations/monitoring.md Resolved
@gjed
gjed marked this pull request as ready for review October 26, 2026 14:56

@M0Rf30 M0Rf30 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall: traces defaulting to true keeps existing enabled: true setups tracing, partial start-up failures are cleaned up, shutdown restores the no-op providers, the signal-matrix test is thorough, and the Collector image is digest-pinned and hardened. Telemetry and config tests pass locally with -race.

Should fix

  1. logs/audit do nothing yet. Turning either on starts an OTLP log exporter and batch processor, but nothing writes to them until #192/#193 land. config.md and .env.example describe logs as "application log records over OTLP", so users will enable it and get nothing. Either land the keys together with #192/#193, or mark them "reserved, no records yet" in the config.md table and .env.example, not only in monitoring.md.
  2. The PR description doesn't match the code. It says the Collector runs "in the app container's network namespace … localhost:4317", but compose and the docs use a separate otel-collector service at http://otel-collector:4317. Please fix the description before squashing, since it becomes the commit message.

Nits
3. Compose env overrides YAML. docker-compose.yml always sets OTEL_*_EXPORTER and OPENARTIFACT_OTLP_AUDIT, using the :-otlp/:-none defaults when unset. Env wins over YAML, so a mounted config with metrics: true would be silently forced off. This is latent, because compose mounts no server config today, but it's safer to pass these only when the user sets them.
4. Collector without an export endpoint. With --profile otel-collector and no OTELCOL_EXPORT_ENDPOINT, otlp_http gets an empty endpoint. I expect the Collector to fail its config check and restart in a loop, but I haven't run it. Consider ${OTELCOL_EXPORT_ENDPOINT:?…} in compose. Also, an empty OTELCOL_EXPORT_AUTHORIZATION sends an empty authorization header.
5. Tests depend on the shell environment. With OTEL_TRACES_EXPORTER=none set, TestTelemetryDefaultsOff and TestTelemetryEnabledKeepsTracesByDefault fail. main already has the same issue with OPENARTIFACT_OTLP_ENABLED, so it isn't new here; clearing the variables in the tests would fix both.
6. Section title. The "OpenTelemetry tracing" section in monitoring.md now also covers metrics and logs, so "OpenTelemetry" would fit better. If you rename it, update the #opentelemetry-tracing link in .env.example.

Happy to approve once 1 and 2 are addressed and CI is green.

@gjed
gjed force-pushed the feat/otlp-signals branch from 78ad09e to cc5d682 Compare October 27, 2026 06:00
@gjed

gjed commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

@M0Rf30 thanks, all six addressed; branch also rebased on main (the upgrading note moved to the new Unreleased section after 0.11.0).

  1. logs/audit are marked reserved (no records until Telemetry: export application logs over OTLP #192/Telemetry: stream audit events as OTLP logs #193) in the Logs/Audit doc comments (so config.md), .env.example, docker/.env.example, openartifact.example.yaml and the monitoring table: edd763e.
  2. PR description updated to the separate otel-collector service at http://otel-collector:4317.
  3. The switches are now valueless keys in compose, so they reach the server only when docker/.env sets them; OPENARTIFACT_OTLP_ENABLED had the same problem and is included: d4dc5ae.
  4. Confirmed: without OTELCOL_EXPORT_ENDPOINT the Collector exits (at least one endpoint must be specified) and restarts, and an empty OTELCOL_EXPORT_AUTHORIZATION goes out as an empty header. ${OTELCOL_EXPORT_ENDPOINT:?…} isn't usable: compose interpolates every service, so docker compose config fails without the profile too (tested). Both are documented as required, with the "remove the headers block" option for a backend without auth: ade3584.
  5. clearTelemetryEnv unsets every variable applyTelemetryEnv reads in each TestTelemetry*, which also covers the OPENARTIFACT_OTLP_ENABLED case from main: 2cdd9d8.
  6. Section renamed to "OpenTelemetry", links updated: cc5d682.

@github-actions

Copy link
Copy Markdown

Coverage

Coverage vs main
Go, unit + integration 77.6% n/a
Go, unit tests only 63.4% n/a
Go, integration tests only 59.2% n/a
Web, lines 87.6% n/a
Web, functions 82.3% n/a

No baseline from main available yet; deltas appear once a main run has stored one.

Go by area
Area Coverage vs main
cmd/docgen 81.8% n/a
cmd/oa 80.2% n/a
cmd/resetpw 0.0% n/a
cmd/server 68.9% n/a
internal/ai 89.8% n/a
internal/api 67.7% n/a
internal/attest 84.7% n/a
internal/audit 92.9% n/a
internal/auth 89.9% n/a
internal/backup 66.7% n/a
internal/bgtask 96.2% n/a
internal/branding 93.4% n/a
internal/clientsetup 90.2% n/a
internal/config 95.5% n/a
internal/cron 90.2% n/a
internal/crypto 90.7% n/a
internal/database 67.8% n/a
internal/declarative 75.5% n/a
internal/dtrack 85.1% n/a
internal/federation 80.1% n/a
internal/format 77.3% n/a
internal/gpgkeys 86.9% n/a
internal/group 88.1% n/a
internal/httpcache 100.0% n/a
internal/httpx 100.0% n/a
internal/importmeta 93.3% n/a
internal/iocopy 100.0% n/a
internal/license 99.4% n/a
internal/licensemeta 92.4% n/a
internal/licensepolicy 92.6% n/a
internal/mcp 87.1% n/a
internal/metrics 96.1% n/a
internal/middleware 87.8% n/a
internal/netutil 93.0% n/a
internal/ocimanifest 100.0% n/a
internal/ocipath 100.0% n/a
internal/passwd 86.5% n/a
internal/pathseg 100.0% n/a
internal/pkgdeps 93.0% n/a
internal/presign 98.8% n/a
internal/promote 86.5% n/a
internal/proxy 79.5% n/a
internal/pypisimple 97.3% n/a
internal/quarantine 100.0% n/a
internal/quota 87.8% n/a
internal/recovery 84.2% n/a
internal/replication 76.3% n/a
internal/repodispatch 84.9% n/a
internal/repotype 100.0% n/a
internal/sbom 89.7% n/a
internal/scanexport 95.6% n/a
internal/search 90.6% n/a
internal/secrets 87.7% n/a
internal/storage 70.9% n/a
internal/telemetry 83.0% n/a
internal/tiering 81.4% n/a
internal/trash 95.6% n/a
internal/urlparams 100.0% n/a
internal/vuln 88.4% n/a
internal/webhook 84.7% n/a
internal/worker 82.3% n/a
internal/xzutil 80.0% n/a
pkg/cargo 95.3% n/a
pkg/deb 76.1% n/a
pkg/delta 71.4% n/a
pkg/gpg 70.2% n/a
pkg/helm 95.9% n/a
pkg/logger 96.0% n/a
pkg/maven 96.7% n/a
pkg/npm 89.4% n/a
pkg/nuget 97.6% n/a
pkg/rpm 91.8% n/a
pkg/rpmsign 71.4% n/a
pkg/rubymarshal 86.7% n/a
web 95.5% n/a
Web by area (lines)
Area Coverage vs main
src 23.5% n/a
src/api 87.8% n/a
src/components 85.8% n/a
src/composables 90.3% n/a
src/i18n 96.5% n/a
src/lib 98.6% n/a
src/pages 87.8% n/a
src/pwa 98.8% n/a
src/router 99.3% n/a
src/stores 98.9% n/a

Full report (HTML, merged profile) in the CI run artifacts

@gjed
gjed requested a review from M0Rf30 October 27, 2026 06:38
gjed and others added 11 commits October 27, 2026 10:14
telemetry.otlp.enabled stays the master switch and owns the shared
endpoint, protocol, headers and TLS. Under it: traces (default true,
OTEL_TRACES_EXPORTER), metrics (OTEL_METRICS_EXPORTER), logs
(OTEL_LOGS_EXPORTER) and audit (OPENARTIFACT_OTLP_AUDIT).

Setup builds the resource and error handler once and one provider per
enabled signal. The tracer provider, Install and HTTPMiddleware exist only
with traces, so Enabled() means traces on. Logs or audit start a single
sdklog.LoggerProvider (otlploggrpc/otlploghttp) installed process-wide;
nothing writes to it until #192 and #193. Enabled with every signal off
installs nothing and logs one warning. Shutdown restores the no-op
providers.

Refs #221
…rofile

docker/otel-collector.yaml receives OTLP on localhost, runs memory_limiter
and batch, and exports OTLP/HTTP to OTELCOL_EXPORT_ENDPOINT with the
Authorization header from OTELCOL_EXPORT_AUTHORIZATION. The otel-collector
compose profile runs it in the openartifact container's network namespace,
like a pod sidecar, and the app service passes the OpenTelemetry variables
from docker/.env. Referenced from docs/operations/monitoring.md.

Refs #221
The specification makes the exporter variables a list, so a value such as
otlp,console copied from another service was ignored. A list naming otlp now
switches the signal on, otherwise none switches it off, and any other list
leaves the setting unchanged.

Refs #221
…v1/logs suffix

With endpoint empty the metric and log exporters read their own
OTEL_EXPORTER_OTLP_METRICS_* and OTEL_EXPORTER_OTLP_LOGS_* variables, and the
HTTP log exporter appends /v1/logs to the endpoint prefix.

Refs #221
…ose network

With network_mode: service:openartifact the Collector kept the namespace of
the first openartifact container, so a crash or docker restart of the server
left nothing on localhost:4317 until the Collector restarted too. The
Collector now joins artifact-repo-network and listens on 0.0.0.0 there (no
published ports); the server endpoint defaults to http://otel-collector:4317.
otel-collector.yaml binds ${env:OTELCOL_LISTEN_HOST:-localhost}, so the same
file stays loopback-only on a host or as a sidecar.

Refs #221
The telemetry config tests read the developer's shell, so OTEL_TRACES_EXPORTER
or OPENARTIFACT_OTLP_ENABLED set there failed them. clearTelemetryEnv unsets
every variable applyTelemetryEnv reads for the duration of each test.

Refs #221
…itten

Both switches start the OTLP log provider, but nothing writes to it until
#192 (logs) and #193 (audit). Say so in the config reference, the example
files and the monitoring table.

Refs #221
….env

The compose file set OPENARTIFACT_OTLP_ENABLED, OTEL_*_EXPORTER and
OPENARTIFACT_OTLP_AUDIT with defaults, and the environment wins over the
YAML file, so a mounted config could never turn a signal on. The keys now
have no value: compose passes them only when docker/.env sets them.

Refs #221
Without OTELCOL_EXPORT_ENDPOINT the Collector exits ("at least one endpoint
must be specified") and compose restarts it; an empty
OTELCOL_EXPORT_AUTHORIZATION is still sent as an empty header. A compose
${VAR:?} guard is not usable: compose interpolates every service, so it
would fail without the profile too.

Refs #221
The section covers traces, metrics and log records now; links to

Refs #221
@M0Rf30
M0Rf30 force-pushed the feat/otlp-signals branch from cc5d682 to bc8e1df Compare October 27, 2026 09:15
@M0Rf30
M0Rf30 merged commit 50a80ef into main Oct 27, 2026
16 checks passed
@M0Rf30
M0Rf30 deleted the feat/otlp-signals branch October 27, 2026 09:16
M0Rf30 added a commit to openartifact/helm-charts that referenced this pull request Oct 27, 2026
Items 2, 3 and 4 of #16. Item 1 (per-signal values) follows in a
separate PR once an app release includes openartifact/openartifact#224.

- **Egress port fix.** The OTLP egress rule now opens the port the
exporter dials: the port of a URL endpoint, else 443 for `https://` and
80 for `http://`; the port of a `host:port` endpoint, else 4317 (grpc)
or 4318 (`http`, `http/protobuf`). `networkPolicy.egress.otlp.port`
still wins.
- **pprof.** `pprof.enabled` renders `OPENARTIFACT_PPROF_ENABLED=true`.
- **Collector sidecar.** `telemetry.collector.enabled` (off by default)
runs `otel/opentelemetry-collector-contrib:0.163.2` as a native sidecar
(init container with `restartPolicy: Always`, so it starts before the
app and stops after it). It has the app's securityContext, a
`health_check` liveness probe and no readiness probe. The default
ConfigMap has OTLP receivers on `127.0.0.1:4317/4318`, `memory_limiter`,
`batch`, and `otlp_grpc`/`otlp_http` to `telemetry.collector.exporter.*`
with a `file_storage` sending queue on an `emptyDir`.
`telemetry.collector.config` replaces the rendered config. The app then
exports to `localhost:4317` or `http://localhost:4318`, and the egress
rule follows the exporter endpoint.
- **Experimental pprof scrape.** `telemetry.collector.pprof.enabled`
adds one contrib `pprof` receiver per profile type (CPU, heap,
goroutine, mutex, block) with a bearer token from a Secret, plus a
`profiles` pipeline behind `service.profilesSupport`. OTLP profiles is
Alpha, so there is no compatibility promise.
- **Docs and CI.** README OpenTelemetry section and values table,
`ci/collector-sidecar-values.yaml`, chart 0.10.0.

Not in the issue:
- **Backend headers format.**
`telemetry.collector.exporter.headersExistingSecret` holds a YAML/JSON
map such as `{"authorization": "Bearer ..."}`, not the app's `k=v` form,
because the Collector cannot parse `k=v`.
- **Endpoint port.** grpc endpoints without a port get the port their
scheme implies, because the Collector rejects a missing port.
- **Extra fail paths:**
  - a missing `exporter.endpoint` without `config`;
  - `protocol=http` with a non-URL endpoint;
- `collector.pprof` without `collector.enabled` or
`tokenExistingSecret`.
- **Bootstrap token.** The pprof scrape token can be the admin token
from `bootstrap.createSecret` (`tokenExistingSecret:
<fullname>-bootstrap`, `tokenSecretKey: admin-token`).

Checked:
- `ct lint`, plus `helm lint` on every commit.
- `helm template` for each acceptance line in #16. With the sidecar off,
output is identical to `main` for the defaults and every `ci/` file.
- `otelcol validate` on the rendered configs.
- Trivy on the Collector image: 0 fixable HIGH/CRITICAL.
- Local kind e2e (CNPG, app 0.11.0, a second Collector as backend that
requires the bearer token):
- Traces, metrics and profiles arrive at the backend over both http and
grpc exporters. The headers map is accepted, and the scrape works with
the bootstrap admin token.
  - A wrong `egress.otlp.port` blocks export.
- Spans queued while blocked survive a sidecar container restart and
arrive once unblocked.
- Switching the sidecar off removes it and its ConfigMap, and the app
exports directly again.
- The logs pipeline stays empty until the app exports OTLP logs (#221).

---------

Co-authored-by: Gianluca Boiano <[email protected]>
Co-authored-by: gjed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telemetry: per-signal switches under the shared OTLP endpoint

2 participants