Skip to content

feat(agent,registrar): export component logs to the otel-collector over OTLP - #222

Merged
bpalermo merged 1 commit into
mainfrom
feat/component-logs-otlp
Jun 18, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/component-logs-otlp

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

What

The agent and registrar only emitted zap JSON to stderr (kubectl logs); their application logs weren't queryable in VictoriaLogs alongside the proxy access logs, metrics, and traces that already flow through the collector. This adds in-process OTLP log export for both components.

zap logger
  ├── existing stderr JSON core   (unchanged → kubectl logs keeps working)
  └── otelzap core → sdklog.LoggerProvider → OTLP gRPC → otel-collector:4317
                                              → logs pipeline → VictoriaLogs

No collector change — the existing logs pipeline (otlp receiver → otlphttp/victorialogs, the same one the proxy access logs use) is reused.

Changes

  • common/telemetry: new SetupLogs (mirrors SetupTracing), reusing newResource so logs carry the same service.name/version + env resource attrs as metrics/traces. New logs_test.go.
  • common/log: NewLoggerWithCore tees an extra zapcore.Core into the stderr core.
  • common/manager: new SetupManagerLogging builds the LoggerProvider + otelzap core when --logs-enabled and an OTLP endpoint are set; returns a flush-on-exit shutdown. Plain SetupLogging is kept for the proxy supervisor (different config shape).
  • agent/registrar root: PersistentPreRunE + a deferred final log flush.
  • charts: telemetry.logs.enabled flag (default off) for both charts; add OTEL_RESOURCE_ATTRIBUTES (k8s.node/pod/namespace) so logs are filterable per node/pod. This also closes a gap — the agent container had no resource attrs, so its own metrics/traces now carry node identity too (consistent with the proxy's fix(telemetry): per-node identity for static infra cluster stats (agent_xds) #210 attrs).
  • Chart bumps: agent 0.2.4→0.2.5, registrar 0.2.0→0.2.1.

Result

Component logs land in VictoriaLogs under service.name=aether-agent / aether-registrar (vs access logs which use log_name=aether_access_logs), so they're cleanly distinguishable.

Tradeoffs (accepted)

  • Logs emitted before OTel init or during a hard crash aren't exported over OTLP (still on stderr/kubectl logs).
  • Trace correlation is partial: otelzap injects trace context only for log calls carrying a span context.

Test

  • bazel build //agent/... //registrar/... //common/... //charts/... green.
  • bazel test //common/... //agent/internal/cmd/... //registrar/internal/cmd/... //charts/... pass (incl. new logs_test.go).
  • helm template with telemetry.logs.enabled=true renders --logs-enabled=true + OTEL_RESOURCE_ATTRIBUTES on both; absent when disabled.

Post-merge validation plan: deploy to talos-main with --set telemetry.logs.enabled=true and confirm service.name=aether-agent/aether-registrar streams appear in VictoriaLogs via the grafana MCP, with kubectl logs unchanged.

🤖 Generated with Claude Code

…er OTLP

The agent and registrar only logged zap JSON to stderr (kubectl logs); their
application logs weren't queryable in VictoriaLogs alongside the proxy access
logs, metrics, and traces that already flow through the collector.

Add an OTel LoggerProvider + OTLP gRPC log exporter, tee'd into the existing zap
core via the otelzap bridge, so records go to BOTH stderr (unchanged) and
OTLP -> collector -> VictoriaLogs. No collector change is needed: the existing
logs pipeline (otlp receiver -> victorialogs) is reused.

- common/telemetry: new SetupLogs (mirrors SetupTracing), reusing newResource so
  logs carry the same service.name/version + env resource attrs as metrics/traces.
- common/log: NewLoggerWithCore tees an extra zapcore.Core into the stderr core.
- common/manager: new SetupManagerLogging wires the provider + otelzap core when
  --logs-enabled and an OTLP endpoint are set; returns a flush-on-exit shutdown.
  Plain SetupLogging is kept for the proxy supervisor (different config shape).
- agent/registrar root: PersistentPreRunE + a deferred final log flush.
- charts: telemetry.logs.enabled flag (default off) for both charts; add
  OTEL_RESOURCE_ATTRIBUTES (k8s.node/pod/namespace) so logs are filterable per
  node/pod in VictoriaLogs. This also closes a gap: the agent container had no
  resource attrs, so its own metrics/traces now carry node identity too.
- Bump agent chart 0.2.4->0.2.5, registrar 0.2.0->0.2.1.

Component logs land in VictoriaLogs under service.name=aether-agent /
aether-registrar (vs access logs which use log_name=aether_access_logs).
Tradeoff: logs before OTel init / during a hard crash aren't exported (still on
stderr); trace correlation is partial (only log calls carrying a span context).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pihqn5RmVPhV9HTdBnqbvY
@bpalermo
bpalermo merged commit 372f2b0 into main Jun 18, 2026
14 checks passed
@bpalermo
bpalermo deleted the feat/component-logs-otlp branch June 18, 2026 12:48
bpalermo added a commit that referenced this pull request Jun 18, 2026
…ace correlation (#223)

logr's sink API is context-free, so a log line cannot see the active span — the
reason #222's OTLP logs carry no trace correlation. Move the agent, registrar,
CNI server and registry logging to stdlib log/slog, whose Handle(ctx, record) is
context-aware: the otelslog bridge now populates trace_id/span_id natively on the
OTLP LogRecord from the ctx passed to the *Context log methods.

Foundation (common/log, common/manager):
- common/log builds *slog.Logger over a fanout handler: stderr JSON (timestamp/
  level/logger/caller/message parity with the old zap output) + an optional extra
  handler (otelslog), each gated by a shared level. Named() replaces WithName;
  V(n) collapses to slog Debug.
- common/manager.SetupManagerLogging returns a *slog.Logger and wires the otelslog
  OTLP handler when --logs-enabled is set. controller-runtime is logr-only, so it
  rides logr.FromSlogHandler over the same handler — one output pipeline.
- common/telemetry.SetupLogs is reused; only the bridge changes (otelzap -> otelslog).

Components: every logr.Logger field/param becomes *slog.Logger. Calls use the
...Context(ctx, ...) variants wherever a ctx is in scope (handlers, traced funcs)
so spanned operations carry trace_id; ctx-less sites (background goroutines,
constructors) use the plain methods. logr.Error(err, msg, kv) -> slog
Error(msg, "error", err, kv).

Holdouts kept on logr (no spans, use the controller-runtime global logger):
common/file and the cni-install binary (bridged to the same slog handler). The
CNI plugin keeps its own separate zap logging stack.

Drops the otelzap dependency added in #222.


Claude-Session: https://claude.ai/code/session_01Pihqn5RmVPhV9HTdBnqbvY

Co-authored-by: Claude Opus 4.8 <[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.

1 participant