feat(telemetry): OTel plumbing#1214
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1214 +/- ##
==========================================
+ Coverage 52.85% 53.27% +0.41%
==========================================
Files 77 81 +4
Lines 6472 6572 +100
==========================================
+ Hits 3421 3501 +80
- Misses 2576 2589 +13
- Partials 475 482 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dfd994e to
076cff2
Compare
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
…jection Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
076cff2 to
fc53d28
Compare
There was a problem hiding this comment.
Pull request overview
Adds foundational OpenTelemetry plumbing to sbomscanner so the four binaries can optionally export traces/metrics over OTLP/gRPC when OTEL_EXPORTER_OTLP_ENDPOINT is set, while remaining no-op otherwise. This introduces a shared internal/telemetry package, wires it into each binary’s startup/shutdown flow, and adds build-time version injection for telemetry metadata.
Changes:
- Introduce
internal/telemetrywithSetup, slog trace/span correlation handler, NATS header propagation carrier, and Tracer/Meter scope helpers. - Wire telemetry setup + bounded shutdown into
cmd/{controller,worker,storage,mcp}/main.go. - Add
internal/versionand Dockerfile-ldflagsinjection to embed build version into binaries (used by telemetry scope/version metadata).
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/version/version.go | Adds an injectable build-version variable (Version) defaulting to dev. |
| internal/version/doc.go | Package doc for internal/version. |
| internal/telemetry/slog.go | Adds a slog.Handler wrapper to inject trace_id/span_id from context. |
| internal/telemetry/slog_test.go | Tests slog trace/span correlation behavior and wrapper semantics. |
| internal/telemetry/scope.go | Adds Tracer/Meter helpers with spec-conformant instrumentation scope names and version. |
| internal/telemetry/scope_test.go | Tests scope name formatting and non-nil tracer/meter helpers. |
| internal/telemetry/otel.go | Implements OTel bootstrap (Setup) gated on OTEL_EXPORTER_OTLP_ENDPOINT, with OTLP exporters and resources. |
| internal/telemetry/otel_test.go | Tests no-endpoint behavior (no-op shutdown + propagators installed). |
| internal/telemetry/nats.go | Adds a NATS header TextMapCarrier plus inject/extract helpers for propagation. |
| internal/telemetry/nats_test.go | Tests NATS header propagation round-trip and nil-safety. |
| internal/telemetry/doc.go | Package doc for internal/telemetry. |
| internal/mcp/server.go | Uses errors.Is for http.ErrServerClosed checks. |
| go.mod | Promotes OpenTelemetry modules to direct dependencies needed by new telemetry package. |
| Dockerfile.worker | Adds VERSION build arg and ldflags injection for embedded version. |
| Dockerfile.storage | Adds VERSION build arg and ldflags injection for embedded version. |
| Dockerfile.mcp | Adds VERSION build arg and ldflags injection for embedded version. |
| Dockerfile.controller | Adds VERSION build arg and ldflags injection for embedded version. |
| cmd/worker/main.go | Initializes telemetry on startup, wraps slog handler for trace/span correlation, and adds bounded shutdown. |
| cmd/storage/main.go | Initializes telemetry on startup, wraps slog handler for trace/span correlation, and adds bounded shutdown. |
| cmd/mcp/main.go | Initializes telemetry on startup, wraps slog handler for trace/span correlation, and adds bounded shutdown. |
| cmd/controller/main.go | Initializes telemetry on startup, wraps slog handler for trace/span correlation, and adds bounded shutdown earlier in boot sequence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4f87de8 to
d1f1358
Compare
…pper, and NATS carrier Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
…inaries Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
…ushes on error Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
…n error Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
…s on error Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
d1f1358 to
e28fcdc
Compare
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Description
Introduces the shared OpenTelemetry bootstrap for the four sbomscanner binaries, gated on
OTEL_EXPORTER_OTLP_ENDPOINT.When the variable is unset, the binaries install no-op providers and behave exactly as before; when it is set, traces and metrics are exported over OTLP/gRPC to any collector the operator provides.
All runtime configuration is done via the standard OpenTelemetry environment variables; no new CLI flags are introduced.
The new
internal/telemetrypackage holds theSetupentry point, anslog.Handlerwrapper that decorates log records with the activetrace_idandspan_idfor log-to-trace correlation, aTextMapCarrierover NATS headers used by the messaging layer, and smallTracer/Meterhelpers that expose the spec-conformant instrumentation scope.Each
cmd/*/main.gonow callstelemetry.Setupright after slog init and defers a bounded shutdown.Also, it adds build-time version injecitonm, which is used as metadata in the telemetry.
Fixes #1215