Package codes.grow.packages.datadogapm
Class DatadogPropagator
java.lang.Object
codes.grow.packages.datadogapm.DatadogPropagator
- All Implemented Interfaces:
io.opentelemetry.context.propagation.TextMapPropagator
public final class DatadogPropagator
extends Object
implements io.opentelemetry.context.propagation.TextMapPropagator
Datadog header propagation (
x-datadog-*) with ddtrace's conflict rules (API.md section 3,
DECISIONS.md #5). Implemented from Datadog's documented header format; no ddtrace code is used.
Injects and extracts x-datadog-trace-id (low 64 bits, decimal),
x-datadog-parent-id (decimal), x-datadog-sampling-priority (1/0) and,
for 128-bit ids, x-datadog-tags: _dd.p.tid=<high 64 bits hex>.
Conflict rules on extract (ddtrace's behaviour with style order datadog,tracecontext):
when the carrier also holds a valid traceparent,
- same trace id: the W3C parent id wins (the context from
traceparentis kept); - different trace id: the Datadog context wins and the W3C context is remembered in the
returned context (
terminatedContext(Context)). Spans exported throughDatadogTracing.initTracing()that are direct children of the winning context get a link to it withreason=terminated_context(seeterminatedContextLinks(Context)).
The rules apply whatever position datadog has in the propagator list; DatadogTracing.orderPropagators(java.util.List<java.lang.String>) puts tracecontext first so an existing tracestate is
kept.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA W3C context that lost against Datadog headers inextract(io.opentelemetry.context.Context, C, io.opentelemetry.context.propagation.TextMapGetter<C>). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of this propagator inTracingConfigpropagator lists.static final Stringx-datadog-origin: origin of the trace (synthetics, rum, ...).static final Stringx-datadog-parent-id: span id, unsigned decimal.static final Stringx-datadog-sampling-priority:1sampled,0not sampled.static final Stringx-datadog-tags: propagated tags, e.g.static final Stringx-datadog-trace-id: low 64 bits of the trace id, unsigned decimal. -
Method Summary
Modifier and TypeMethodDescription<C> io.opentelemetry.context.Contextextract(io.opentelemetry.context.Context context, C carrier, io.opentelemetry.context.propagation.TextMapGetter<C> getter) static <C> Optional<io.opentelemetry.api.trace.SpanContext> extractDatadogContext(C carrier, io.opentelemetry.context.propagation.TextMapGetter<C> getter) Reads the Datadog headers of a carrier into a remote span context.static Optional<io.opentelemetry.api.trace.SpanContext> extractDatadogContext(Map<String, String> headers) extractDatadogContext(Object, TextMapGetter)for a string map (keys match case-insensitively).fields()static DatadogPropagatorThe shared instance.<C> voidinject(io.opentelemetry.context.Context context, C carrier, io.opentelemetry.context.propagation.TextMapSetter<C> setter) terminatedContext(io.opentelemetry.context.Context context) The W3C context that lost against Datadog headers during extract.static List<io.opentelemetry.sdk.trace.data.LinkData> terminatedContextLinks(io.opentelemetry.context.Context context) The span links for a span started from an extracted context: one link to the terminated W3C context (reason=terminated_context,context_headers=tracecontext), or none.toString()
-
Field Details
-
TRACE_ID_HEADER
x-datadog-trace-id: low 64 bits of the trace id, unsigned decimal.- See Also:
-
PARENT_ID_HEADER
x-datadog-parent-id: span id, unsigned decimal.- See Also:
-
SAMPLING_PRIORITY_HEADER
x-datadog-sampling-priority:1sampled,0not sampled.- See Also:
-
TAGS_HEADER
x-datadog-tags: propagated tags, e.g._dd.p.tid=<high 64 bits hex>.- See Also:
-
ORIGIN_HEADER
x-datadog-origin: origin of the trace (synthetics, rum, ...).- See Also:
-
NAME
Name of this propagator inTracingConfigpropagator lists.- See Also:
-
-
Method Details
-
getInstance
The shared instance.- Returns:
- propagator
-
extractDatadogContext
public static <C> Optional<io.opentelemetry.api.trace.SpanContext> extractDatadogContext(C carrier, io.opentelemetry.context.propagation.TextMapGetter<C> getter) Reads the Datadog headers of a carrier into a remote span context. A missing sampling priority counts as sampled.- Type Parameters:
C- carrier type- Parameters:
carrier- carriergetter- getter- Returns:
- the context, or empty when the headers are missing or invalid
-
extractDatadogContext
public static Optional<io.opentelemetry.api.trace.SpanContext> extractDatadogContext(Map<String, String> headers) extractDatadogContext(Object, TextMapGetter)for a string map (keys match case-insensitively).- Parameters:
headers- headers- Returns:
- the context, or empty
-
inject
public <C> void inject(io.opentelemetry.context.Context context, C carrier, io.opentelemetry.context.propagation.TextMapSetter<C> setter) - Specified by:
injectin interfaceio.opentelemetry.context.propagation.TextMapPropagator
-
extract
public <C> io.opentelemetry.context.Context extract(io.opentelemetry.context.Context context, C carrier, io.opentelemetry.context.propagation.TextMapGetter<C> getter) - Specified by:
extractin interfaceio.opentelemetry.context.propagation.TextMapPropagator
-
fields
- Specified by:
fieldsin interfaceio.opentelemetry.context.propagation.TextMapPropagator
-
toString
-
terminatedContext
public static Optional<DatadogPropagator.TerminatedContext> terminatedContext(io.opentelemetry.context.Context context) The W3C context that lost against Datadog headers during extract.- Parameters:
context- extracted context- Returns:
- the terminated context, or empty
-
terminatedContextLinks
public static List<io.opentelemetry.sdk.trace.data.LinkData> terminatedContextLinks(io.opentelemetry.context.Context context) The span links for a span started from an extracted context: one link to the terminated W3C context (reason=terminated_context,context_headers=tracecontext), or none. Add them (for example withSpanBuilder.addLink) when you export spans withoutDatadogTracing.initTracing().- Parameters:
context- extracted context- Returns:
- zero or one link
-