Documentation
¶
Overview ¶
Package tracing configures OpenTelemetry for dtctl using the OTLP HTTP exporter.
OneAgent does not reliably instrument short-lived processes; dtctl therefore uses the OpenTelemetry SDK directly so spans are exported before the process exits.
Span lifecycle ¶
Init creates a single root span covering the entire CLI invocation and registers a SimpleSpanProcessor (synchronous exporter) backed by an OTLP HTTP exporter (when configured). A synchronous processor is used instead of a batching one because dtctl is a short-lived process that produces only a single span — the OTel documentation recommends SimpleSpanProcessor for this use case. The caller MUST defer the returned shutdown function so the span is ended and the provider is cleanly shut down.
W3C Trace Context propagation ¶
TRACEPARENT and TRACESTATE environment variables are read on startup. When a valid TRACEPARENT is present, the CLI span becomes a child of the caller's span, allowing dtctl to participate in an existing distributed trace (e.g. from a CI pipeline or orchestrator). Invalid values are silently ignored per the W3C spec: a new root span is created instead.
OTLP export ¶
An OTLP HTTP exporter is initialised only when OTEL_EXPORTER_OTLP_ENDPOINT is set. All standard OTEL_* env vars (OTEL_EXPORTER_OTLP_HEADERS, OTEL_SERVICE_NAME, etc.) are forwarded to the SDK automatically. When no endpoint is configured the SDK still generates valid span contexts that are propagated to Dynatrace API requests via the traceparent header, but no spans are exported. The overhead in this case is negligible (no network I/O, only in-memory span context generation).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(ctx context.Context, spanName string, safeArgs []string, verbosity int) (context.Context, func(context.Context), error)
Init initialises OpenTelemetry for the current dtctl invocation and returns:
- a context carrying the root CLI span (use as parent for all further work)
- a shutdown function that MUST be deferred to flush spans before process exit
- a non-nil error only when OTEL_EXPORTER_OTLP_ENDPOINT is set but the exporter cannot be created; the returned context and span are always valid
safeArgs are the sanitised command-line arguments (verb + resource only, no flags or IDs) used for the span name and the process.command_args resource attribute.
verbosity controls OTel-internal error output: at level 0 SDK-internal errors (e.g. failed span exports) are silently discarded; at level 1+ they are printed to stderr. This avoids noisy output in normal CLI usage when an OTLP endpoint is misconfigured.
Types ¶
This section is empty.