Repository navigation
feat(observability): OpenTelemetry logs+traces with secret redaction and slog standardization - #290
Conversation
Part of #265. Adds opt-in OpenTelemetry (logs + traces) alongside the existing stderr + opslog pipeline, plus secret redaction on all sinks. Default-off: with no OTEL_* / SILO_OTEL_ENABLED config, behavior is unchanged. Bootstrap (internal/telemetry): - Setup() builds one shared resource, a TracerProvider (parent-based trace-id ratio sampler), a LoggerProvider, and the W3C TraceContext+Baggage propagator from env. It installs NO MeterProvider — metrics stay on Prometheus, and the built-in no-op global MeterProvider keeps the trace instrumentation libs from double-emitting. Shutdown is deferred with a flush timeout. - Logs are bridged via otelslog fan-out (slog.MultiHandler), level-gated by the shared LevelVar and best-effort so a failing collector can't break the console or DB branches. stderr + opslog stay untouched. Secret redaction (internal/logredact): - A slog.Handler masks secret-keyed attributes (password, token, api_key, authorization, cookie, ...) — including .With-bound attrs, nested groups, secret-keyed group subtrees, and values behind a LogValuer — on the console and OTLP sinks, with a no-op fast path when a record has no secret keys. opslog.shouldRedact delegates to logredact.SecretKey so all sinks share one marker list. Rotation is infra-managed (no custom file sink): container runtime for stderr, collector/backend for OTLP, opslog partition-pruning for the DB. Documented in docs/architecture/observability.md. Verification: go build ./..., go vet, gofmt -l — clean; go test ./internal/telemetry/ ./internal/logredact/ -race pass. AI-use disclosure: implemented with AI assistance (Claude Code), including adversarial reviews that hardened the bootstrap and fixed two redaction leak paths; reviewed by the author.
…(phase 3) Part of #265. Builds on the OTel bootstrap + redaction commit. Standardizes every log call site onto the context-carrying slog variants so records correlate with the active OpenTelemetry trace, and locks the standard in with a machine gate so future code (human- or AI-authored) can't drift back. - Call-site sweep: converted the remaining slog.<Level>(...) calls to the slog.<Level>Context(ctx, ...) form wherever a context.Context is in scope (background/init calls with no ctx are left as-is), across 183 files. Applied via a type-aware AST codemod. Log levels and message strings are preserved verbatim; a component attr (canonical per-package name) is added to direct package-level slog calls. Bound-logger calls keep their existing .With bindings. The main.go and telemetry package conversions rode with their file in the previous commit to keep each file within a single commit. - Enforcement (.golangci.yml): enable sloglint with context=scope, static-msg, key-naming-case=snake, no-mixed-args. After the sweep all four report zero violations repo-wide (tests included), so make lint / CI now blocks any regression to the non-context form. The gate ships with the sweep because it cannot be green until the legacy sites are converted. Metrics remain on Prometheus; no behavior change to /metrics or Grafana. Verification: go build ./..., go vet ./..., gofmt -l — clean; sloglint (all 4 rules) 0 violations repo-wide; log levels verified unchanged. AI-use disclosure: implemented with AI assistance (Claude Code), including the codemod; reviewed by the author.
|
Important Review skippedToo many files! This PR contains 209 files, which is 59 over the limit of 150. To get a review, narrow the scope: Upgrade to a paid plan to raise the limit. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (209)
You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5da1aa42d2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // WithGroup delegates to the inner handler; grouped attributes are still | ||
| // redacted by leaf key at Handle/WithAttrs time. | ||
| func (h *Handler) WithGroup(name string) slog.Handler { | ||
| return &Handler{inner: h.inner.WithGroup(name)} |
There was a problem hiding this comment.
Honor secret group names in WithGroup
When code builds a logger with WithGroup("authorization") (or another secret marker) and then logs a non-secret leaf such as "value", this branch passes the secret group name straight to the inner handler; the later redaction pass only sees the leaf key, so stderr/OTLP can emit the token under the secret group. slog.Group("authorization", ...) is already masked as a subtree, so WithGroup needs the same treatment before delegating.
Useful? React with 👍 / 👎.
| protocol := ProtocolGRPC | ||
| switch strings.ToLower(strings.TrimSpace(os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL"))) { | ||
| case "http/protobuf", "http": | ||
| protocol = ProtocolHTTP | ||
| case "grpc", "": | ||
| protocol = ProtocolGRPC | ||
| } |
There was a problem hiding this comment.
Honor per-signal OTLP protocol overrides
If an operator uses the standard signal-specific env vars, for example OTEL_EXPORTER_OTLP_LOGS_PROTOCOL=http/protobuf with an HTTP logs endpoint while leaving the generic OTEL_EXPORTER_OTLP_PROTOCOL unset, this defaults cfg.Protocol to gRPC and Setup constructs gRPC exporters; the per-signal protocol env cannot switch the exporter package after that. That breaks common mixed or signal-specific OTLP collector configs even though the exporters are otherwise expected to read OTEL_EXPORTER_OTLP_* settings from the environment.
Useful? React with 👍 / 👎.
…up names Two Codex review findings on PR #290: - telemetry: OTEL_EXPORTER_OTLP_{TRACES,LOGS}_PROTOCOL now override the generic OTEL_EXPORTER_OTLP_PROTOCOL per signal, so mixed collector setups (e.g. HTTP logs + gRPC traces) build the right exporter. - logredact: entering a group whose name is secret-bearing (e.g. WithGroup("authorization")) now masks every leaf in that subtree, matching how slog.Group("authorization", ...) is masked as a whole.
|
Addressed the two Codex findings in be5ad6e:
build / vet / tests pass. |
- Telemetry setup failure no longer kills boot: Setup returns usable no-op providers alongside the error and main logs and continues with telemetry disabled, honoring the best-effort contract. - Honor OTEL_TRACES_SAMPLER (always_on/off, traceidratio, parentbased_* variants); unsupported values fall back to parentbased_traceidratio. - Attach node identity as semconv service.instance.id instead of the non-semconv node.name. - Rename opslog retention-scope log attrs to target_component/target_level so they no longer collide with the canonical component routing key, and tag those lines with component=opslog. - Fix stale levelGated comment casing; use WarnContext in the telemetry shutdown defer; document the LogValuer double-resolve on the redaction slow path. Co-Authored-By: Claude Fable 5 <[email protected]>
Resolves conflicts against main (audiobooks enrichment provider-error handling, autoscan transient-resolve stats, go.mod/go.sum dep union) and converts the slog call sites that landed on main after the sweep to the context+component convention so the sloglint gate stays green repo-wide (admin_split, libraries, policy handlers, policy decision-log cleanup, abs handlers, jellycompat, metadata, playback, plugins, scanner extras, watchsync, clientip reload; test loggers moved to slog.DiscardHandler). Adds "policy" to the canonical component list. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Pushed two commits addressing the review and resolving the conflict with main: ec2c73a — review feedback
f14a949 — merge main
Verification: 🤖 Generated with Claude Code |
…and slog standardization (#290) * feat(observability): OpenTelemetry logs+traces with secret redaction Part of #265. Adds opt-in OpenTelemetry (logs + traces) alongside the existing stderr + opslog pipeline, plus secret redaction on all sinks. Default-off: with no OTEL_* / SILO_OTEL_ENABLED config, behavior is unchanged. Bootstrap (internal/telemetry): - Setup() builds one shared resource, a TracerProvider (parent-based trace-id ratio sampler), a LoggerProvider, and the W3C TraceContext+Baggage propagator from env. It installs NO MeterProvider — metrics stay on Prometheus, and the built-in no-op global MeterProvider keeps the trace instrumentation libs from double-emitting. Shutdown is deferred with a flush timeout. - Logs are bridged via otelslog fan-out (slog.MultiHandler), level-gated by the shared LevelVar and best-effort so a failing collector can't break the console or DB branches. stderr + opslog stay untouched. Secret redaction (internal/logredact): - A slog.Handler masks secret-keyed attributes (password, token, api_key, authorization, cookie, ...) — including .With-bound attrs, nested groups, secret-keyed group subtrees, and values behind a LogValuer — on the console and OTLP sinks, with a no-op fast path when a record has no secret keys. opslog.shouldRedact delegates to logredact.SecretKey so all sinks share one marker list. Rotation is infra-managed (no custom file sink): container runtime for stderr, collector/backend for OTLP, opslog partition-pruning for the DB. Documented in docs/architecture/observability.md. Verification: go build ./..., go vet, gofmt -l — clean; go test ./internal/telemetry/ ./internal/logredact/ -race pass. AI-use disclosure: implemented with AI assistance (Claude Code), including adversarial reviews that hardened the bootstrap and fixed two redaction leak paths; reviewed by the author. * refactor(observability): slog context+component sweep, sloglint gate (phase 3) Part of #265. Builds on the OTel bootstrap + redaction commit. Standardizes every log call site onto the context-carrying slog variants so records correlate with the active OpenTelemetry trace, and locks the standard in with a machine gate so future code (human- or AI-authored) can't drift back. - Call-site sweep: converted the remaining slog.<Level>(...) calls to the slog.<Level>Context(ctx, ...) form wherever a context.Context is in scope (background/init calls with no ctx are left as-is), across 183 files. Applied via a type-aware AST codemod. Log levels and message strings are preserved verbatim; a component attr (canonical per-package name) is added to direct package-level slog calls. Bound-logger calls keep their existing .With bindings. The main.go and telemetry package conversions rode with their file in the previous commit to keep each file within a single commit. - Enforcement (.golangci.yml): enable sloglint with context=scope, static-msg, key-naming-case=snake, no-mixed-args. After the sweep all four report zero violations repo-wide (tests included), so make lint / CI now blocks any regression to the non-context form. The gate ships with the sweep because it cannot be green until the legacy sites are converted. Metrics remain on Prometheus; no behavior change to /metrics or Grafana. Verification: go build ./..., go vet ./..., gofmt -l — clean; sloglint (all 4 rules) 0 violations repo-wide; log levels verified unchanged. AI-use disclosure: implemented with AI assistance (Claude Code), including the codemod; reviewed by the author. * fix(observability): honor per-signal OTLP protocol and secret WithGroup names Two Codex review findings on PR #290: - telemetry: OTEL_EXPORTER_OTLP_{TRACES,LOGS}_PROTOCOL now override the generic OTEL_EXPORTER_OTLP_PROTOCOL per signal, so mixed collector setups (e.g. HTTP logs + gRPC traces) build the right exporter. - logredact: entering a group whose name is secret-bearing (e.g. WithGroup("authorization")) now masks every leaf in that subtree, matching how slog.Group("authorization", ...) is masked as a whole. * fix(observability): address review feedback on telemetry bootstrap - Telemetry setup failure no longer kills boot: Setup returns usable no-op providers alongside the error and main logs and continues with telemetry disabled, honoring the best-effort contract. - Honor OTEL_TRACES_SAMPLER (always_on/off, traceidratio, parentbased_* variants); unsupported values fall back to parentbased_traceidratio. - Attach node identity as semconv service.instance.id instead of the non-semconv node.name. - Rename opslog retention-scope log attrs to target_component/target_level so they no longer collide with the canonical component routing key, and tag those lines with component=opslog. - Fix stale levelGated comment casing; use WarnContext in the telemetry shutdown defer; document the LogValuer double-resolve on the redaction slow path. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Quick <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
Part of #265.
Supersedes #264. Opened in response to @darthShadow's feedback (#265 (comment)) to adopt OpenTelemetry rather than a custom file sink.
Two commits: the OpenTelemetry logs+traces foundation with secret redaction, and the repo-wide
slogcall-site standardization plus a lint gate that keeps it from regressing.Problem
Logs disappear when the container is recreated. Silo only ever wrote logs to stderr, so under Docker the only record lives in the daemon's
json-filelog, which is wiped on every redeploy or image bump. An operator investigating something that happened "before the last restart" has nothing to look at.There was no standard, tool-agnostic way to ship logs and traces off the box. The earlier attempt (#264) solved durability with a bespoke rotating file sink. On review the maintainer asked us to build observability on OpenTelemetry instead of custom sinks, so a collector/backend of the operator's choice can own retention and correlation. This PR follows that direction.
Secrets could reach the logs unmasked. Redaction only ran on the operational-log database path. Anything written to stderr — and, once telemetry exists, to a collector — emitted API keys, tokens, and cookies verbatim.
Log lines were inconsistent and uncorrelated. Most call sites used the non-context
slogform, so a log line could not be tied to the request/trace it belongs to, and nothing stopped new code from staying that way.Solution
Design and rationale are captured in
docs/architecture/observability.mdand the plan underdocs/superpowers/plans/.feat(observability): OpenTelemetry logs+traces with secret redaction
Opt-in, gated entirely on
SILO_OTEL_ENABLED/OTEL_EXPORTER_OTLP_ENDPOINT. With no config the behaviour is byte-for-byte the same as today (stderr +opslog).internal/telemetrypackage.Setupbuilds one shared resource, aTracerProvider(parent-based trace-id-ratio sampler), aLoggerProvider, and the W3CTraceContext+Baggagepropagator fromOTEL_*env. It deliberately installs noMeterProvider— metrics stay on Prometheus, and leaving the global meter as the built-in no-op stops the trace instrumentation libraries from double-emitting (internal/telemetry/telemetry.go).otelsloghandler is added to the existing chain via fan-out (slog.MultiHandler), so records still reach stderr and theopslogDB/admin pipeline unchanged. The OTel branch is level-gated by the sharedLevelVar(otherwiseMultiHandler.Enabledwould OR the branches and export Debug atlog_level=info) and best-effort (a failing collector can't break the console/DB branches) —cmd/silo/main.gobuildBaseHandler,internal/telemetry/loghandler.go.internal/logredact). Aslog.Handlermasks secret-keyed attributes (password,token,api_key,authorization,cookie, …) — including.With-bound attrs, nested groups, secret-keyed group subtrees, and values behind aLogValuer(resolved before inspection) — with a zero-alloc fast path when a record has no secret keys.opslog.shouldRedactnow delegates tologredact.SecretKey, so the DB path and the console/OTLP sinks share one marker list and can't drift.json-filemax-size/max-file+ mounted volume), the collector/backend for OTLP, andopslog's existing daily-partition pruning for the DB path.refactor(observability): slog context+component sweep, sloglint gate (phase 3)
slog.<Level>(...)calls toslog.<Level>Context(ctx, …)wherever acontext.Contextis in scope (background/init calls with no ctx are left as-is), across 183 files, via a type-aware AST codemod. Log levels and message strings are preserved verbatim; acomponentattr (canonical per-package name) is added to direct package-level calls.main.goand the telemetry package's own conversions ride with their file in the first commit so no file is split across commits..golangci.yml). Enabledsloglintwithcontext=scope,static-msg,key-naming-case=snake,no-mixed-args. After the sweep all four report zero violations repo-wide, somake lint/ CI now blocks any regression to the non-context form. The gate ships with the sweep because it can't be green until the legacy sites are converted.Risk / follow-ups
log_quietalso suppresses OTel logs — the fan-out mirrors the console stream, so quieting a subsystem empties its OTLP stream too.opslogbehaviour.silo-plugin-sdkand is a coordination follow-up./metricsand Grafana are untouched.Verification
go build ./...,go vet ./...,gofmt -l— all clean.sloglint(all four rules) — 0 violations repo-wide, tests included.go test ./internal/telemetry/ ./internal/logredact/ -race— pass (bootstrap enable/disable + no-op MeterProvider guard; redaction of record attrs,.With-bound, nested groups, secret group keys,LogValuer,WithGroup, clean pass-through, andslogtestconformance).AI-use disclosure
Implemented with AI assistance (Claude Code): drafting, the AST codemod for the sweep, two rounds of adversarial review (which hardened the SDK bootstrap and found/fixed two secret-leak paths in the redaction handler), and this description. All changes were reviewed by the author.