denoland/deno · warning
Failed to inject with ${propagator.constructor.name}.
Error message
Failed to inject with ${propagator.constructor.name}. What it means
Deno's vendored OpenTelemetry SDK (ext/telemetry/telemetry.ts) wraps CompositePropagator.inject: each registered propagator runs inside try/catch, and a throw is reduced to this warning carrying the propagator's constructor name and the error, then the loop continues with the remaining propagators. Trace/context headers may be partially or fully missing from outgoing carriers afterwards.
Source
Thrown at ext/telemetry/telemetry.ts:1829
ArrayPrototypeReduce(
ArrayPrototypeMap(
this.#propagators,
(p) => p.fields(),
),
(x, y) => ArrayPrototypeConcat(x, y),
[],
),
),
);
}
inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
for (const propagator of new SafeArrayIterator(this.#propagators)) {
try {
propagator.inject(context, carrier, setter);
} catch (err) {
// deno-lint-ignore no-console
console.warn(
`Failed to inject with ${propagator.constructor.name}.`,
err,
);
}
}
}
extract(context: Context, carrier: unknown, getter: TextMapGetter): Context {
return ArrayPrototypeReduce(this.#propagators, (ctx, propagator) => {
try {
return propagator.extract(ctx, carrier, getter);
} catch (err) {
// deno-lint-ignore no-console
console.warn(
`Failed to extract with ${propagator.constructor.name}.`,
err,
);
}View on GitHub (pinned to a961cdec3b)
Solutions
- Inspect the err logged right after the message; invalid trace/span ids are the most common cause
- Build contexts only through the otel API (trace.setSpan, valid SpanContext objects) instead of assembling ids manually
- Upgrade Deno, since fixes to the vendored propagators land in runtime releases
- If a custom propagator is registered, unit-test its inject() against your exact carrier and setter types before registration
Example fix
// before: hand-built context with a bad trace id -> propagator.inject throws, warning logged
const ctx = trace.setSpan(ROOT_CONTEXT, { spanContext: { traceId: "xyz", spanId: "1", ... } });
propagator.inject(ctx, outgoingHeaders, defaultSetter);
// after: use the API to build valid contexts
const span = tracer.startSpan("out");
propagator.inject(trace.setSpan(ROOT_CONTEXT, span), outgoingHeaders, defaultSetter);
span.end(); Defensive patterns
Strategy: try-catch
Validate before calling
// verify the active context is injectable before propagating
const span = trace.getSpan(activeContext);
const sc = span?.spanContext();
const safeContext = sc && /^[\da-f]{32}$/.test(sc.traceId) && /^[\da-f]{16}$/.test(sc.spanId)
? activeContext
: ROOT_CONTEXT;
propagator.inject(safeContext, carrier, setter); Type guard
function hasValidTrace(ctx: Context): boolean {
const sc = trace.getSpan(ctx)?.spanContext();
return !!sc && /^[\da-f]{32}$/.test(sc.traceId) && /^[\da-f]{16}$/.test(sc.spanId) && sc.traceFlags !== undefined;
} Try / catch
// never let a broken propagator take down the request path
try {
propagator.inject(context, carrier, setter);
} catch (err) {
diag.warn?.("trace inject failed; continuing without propagation", err);
} Prevention
- Create contexts only through the otel API (trace.setSpan, propagation.setGlobalPropagator)
- Never hand-assemble trace ids; use samplers and the tracer API
- Unit-test custom propagators' inject against your real carrier/setter types before registering them
When it happens
Trigger: Calling the inject path (directly or via automatic outbound instrumentation) while the active Context holds an invalid SpanContext (malformed traceId/spanId, usually from hand-built contexts or custom samplers), or a registered custom propagator throwing against the supplied carrier/setter. W3CTraceContextPropagator and B3 variants are the usual constructor names in the message.
Common situations: Hand-crafted trace ids that are the wrong length or contain non-hex characters; custom propagators registered via propagation.setGlobalPropagator that assume a header-map carrier but receive something else; context lost/reset mid-request leaving inconsistent state; SDK version drift after Deno upgrades.
Related errors
- Failed to extract with ${propagator.constructor.name}.
- TracerProvider can not be constructed
- startActiveSpan requires a function argument
- vsock is not supported on this platform
- invalid vsock addr
AI-assisted analysis of denoland/deno@a961cdec3b (2026-08-20).
Data as JSON: /api/errors/5c88ccede0e946b3.
Report an issue: GitHub.