Skip to content

feat: add opt-in OTLP trace export to the CLI - #2613

Open
ymotongpoo wants to merge 2 commits into
chainguard-dev:mainfrom
ymotongpoo:feat/cli-otlp-tracing
Open

ymotongpoo wants to merge 2 commits into
chainguard-dev:mainfrom
ymotongpoo:feat/cli-otlp-tracing

Conversation

@ymotongpoo

Copy link
Copy Markdown

The standalone CLI already creates OpenTelemetry spans internally, but it has no SDK/exporter initialization. This adds opt-in OTLP export so users can inspect those spans without modifying the CLI.

Closes #2609.

Behavior

  • OTEL_TRACES_EXPORTER=otlp enables a command root span and the existing internal spans. Export stays disabled by default; OTEL_SDK_DISABLED=true also skips initialization.
  • Support gRPC (default) and HTTP/protobuf, including trace-specific protocol overrides and the exporters' standard endpoint, header, timeout, and TLS environment variables.
  • Preserve the original context, provider, and command result when tracing is disabled. Keep initialization in the executable; library callers retain their own SDK configuration.
  • End the root span and allow up to five seconds to flush after success, errors, or cancellation. Report telemetry failures separately without replacing or wrapping the command error.

Validation

  • go test ./..., make test (all packages with the race detector), and golangci-lint 2.14 passed.
  • make generate left tracked generated files unchanged; go mod tidy completed.
  • Compared --help, version, and a missing-config build against unmodified main. With VCS stamping disabled for comparison, stdout, stderr, and exit codes match.
  • Built an image containing a locally packaged GNU Hello. It printed Hello, world!; Tempo returned 130 spans with one root and complete recorded parent relationships.
  • Local OTLP receivers test both transports, resource attributes, existing child spans, command failures, cancellation, and exporter failures. Removing the opt-in guard makes the tests fail with disabled tracing changed the command context.

Scope

Existing build logic and internal span placement stay unchanged. Propagating context between separate CLI invocations remains a separate proposal. This implements the compatibility policy discussed in the issue; transport and configuration choices remain open to maintainer feedback.

Initialize the SDK only when OTEL_TRACES_EXPORTER=otlp and keep
telemetry setup/export failures separate from the command result.

Test disabled behavior, both OTLP transports, parent-child context,
resource configuration, cancellation, and exporter failures.

Refs chainguard-dev#2609

Signed-off-by: Yoshi Yamaguchi <ymotongpoo@gmail.com>
Signed-off-by: Yoshi Yamaguchi <ymotongpoo@gmail.com>
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.

Support opt-in OTLP trace export from the standalone CLI

1 participant