Repository navigation
feat(telemetry): per-signal OTLP switches under telemetry.otlp - #224
Conversation
gjed
left a comment
There was a problem hiding this comment.
Copilot review overview
Reviewer is the PR author — review event submitted as COMMENT.
Review effort: Standard
Findings: 1
Open (4)
Withnetwork_mode: service:openartifactthe Collector loses its network whenever theopenartifact… · NewOTEL_*_EXPORTERis a comma-separated list in the spec, sootlp,consoleis ignored here instead… · New The comment still names only theOTEL_EXPORTER_OTLP_TRACES_*variables, but the metric and log… · New Theendpointrow lists the/v1/tracesand/v1/metricssuffixes but not/v1/logs. · New
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:
Setupbuilds the resource and error handler once, then starts a provider only for each enabled signal; the tracer provider,Install/Enabled()andHTTPMiddlewareexist only withtraces.logsorauditstart one OTLPsdklog.LoggerProvider(gRPC or HTTP,/v1/logs) installed withotel.SetLoggerProvider; nothing writes to it yet.enabled: truewith 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) andOPENARTIFACT_OTLP_AUDIT;OTEL_METRICS_EXPORTERmoves to the sharedoverrideExporterhelper. - Compose gains an
otel-collectorprofile runningotelcol-contribin the app container's network namespace with a baseline config, and passes the OTEL variables through fromdocker/.env. - Docs, example configs and the upgrading note describe the new keys;
otel/sdk/logand theotlplogexporters 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 |
M0Rf30
left a comment
There was a problem hiding this comment.
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
logs/auditdo nothing yet. Turning either on starts an OTLP log exporter and batch processor, but nothing writes to them until #192/#193 land.config.mdand.env.exampledescribelogsas "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 theconfig.mdtable and.env.example, not only inmonitoring.md.- 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 separateotel-collectorservice athttp://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.
78ad09e to
cc5d682
Compare
|
@M0Rf30 thanks, all six addressed; branch also rebased on main (the upgrading note moved to the new Unreleased section after 0.11.0).
|
Coverage
No baseline from Go by area
Web by area (lines)
|
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
….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
cc5d682 to
bc8e1df
Compare
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]>


Closes #221. Design context: #196 (answer 2).
telemetry.otlp.enabledstays the master switch and keeps the shared endpoint, protocol, headers and TLS settings. It now has a switch per signal:tracesOTEL_TRACES_EXPORTERtruemetricsOTEL_METRICS_EXPORTERfalselogsOTEL_LOGS_EXPORTERfalseauditOPENARTIFACT_OTLP_AUDITfalseThe
OTEL_*_EXPORTERvariables are comma-separated lists, as in the spec: a list containingotlpturns the signal on, otherwisenoneturns it off, and any other value is ignored.Setupcreates a provider only for the signals that are on. The tracer provider,Install(and with itEnabled()) andHTTPMiddlewareonly exist withtraces.logsorauditstart onesdklog.LoggerProvider(otlploggrpc/otlploghttp), installed withotel.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).enabledwith every signal off installs nothing and logs one warning at startup.enabled: truekeeps tracing exactly as before. See the upgrading note.docker/otel-collector.yamlis a baselineotelcol-contribconfig: OTLP in on localhost,memory_limiter+batch,otlp_httpout toOTELCOL_EXPORT_ENDPOINTwith theAuthorizationheader fromOTELCOL_EXPORT_AUTHORIZATION.otel-collectorruns that config as its own service onartifact-repo-network, withOTELCOL_LISTEN_HOST=0.0.0.0and no published ports. The server's compose endpoint defaults tohttp://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 whendocker/.envsets them, so they never override a mounted config.OTELCOL_EXPORT_ENDPOINTis required with the profile..env.example,openartifact.example.yamlanddocker/.env.example,docs/reference/config.mdis regenerated, anddocs/operations/monitoring.mdanddocs/getting-started/upgrading.mdare updated.otel/sdk/log,otlploggrpc,otlploghttp.otel/logandotel/metricmove from indirect to direct.Verification
make test,make deadcodeandmake docs-checkpass, andgo mod tidy -diffis clean.make lint: the only finding locally is anolintlintinpkg/rpm/dependencies.go:72. That file is unchanged here; the finding comes from the local golangci-lint 2.13.2.TestSetupSignalMatrixcovers 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./v1/logsexport: auth header, scope and resource.enabled: true. They clear the OpenTelemetry environment first, so the developer's shell cannot change the result.-p oa-otlp,--profile otel-collector, the Collector forwarding to a throwaway OTLP/HTTP sink):/v1/tracesat the sink withAuthorization: Bearer …. The span was namedGET /api/v1/system/info, and/healthwas not traced.OTEL_TRACES_EXPORTER=nonewithOTEL_METRICS_EXPORTER=otlp: no traces, and/v1/metricscarried theopenartifact_*/go_*families.logs+auditonly: the server is healthy and nothing is exported yet.openartifactandotel-collectorone at a time: traces keep arriving and the server logs no export errors.OTELCOL_EXPORT_ENDPOINTthe Collector exits withat least one endpoint must be specified, which is now documented.docker compose configpasses with and without the profile.otelcol-contrib validatepasses, and the deprecatedotlphttpalias is replaced byotlp_http.