dd-trace includes an OpenTelemetry-compatibleDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/datadog/dd-trace-js/llms.txt
Use this file to discover all available pages before exploring further.
TracerProvider that can be registered with @opentelemetry/api. This allows you to write instrumentation using the standard OTel API while sending data to Datadog.
Setup
provider.register(), all calls to @opentelemetry/api will use dd-trace as the backend.
TracerProvider
TheTracerProvider is a constructor available at tracer.TracerProvider.
getTracer(name, version?, options?)
Returns an OTel-compatible Tracer for the given instrumentation scope.
The name of the tracer or instrumentation library.
The version of the tracer or instrumentation library.
An OTel-compatible
Tracer instance backed by dd-trace.register()
Registers this provider with @opentelemetry/api.
OTel Tracer methods
startSpan(name, options?, context?)
Starts a new span without activating it on the context.
startActiveSpan(name, fn) / startActiveSpan(name, options, fn) / startActiveSpan(name, options, context, fn)
Starts a new span and activates it in the context for the duration of the callback.
OTel Span methods
The OTelSpan interface is backed by dd-trace spans. The following methods are available:
| Method | Description |
|---|---|
setAttribute(key, value) | Sets a single attribute |
setAttributes(attributes) | Sets multiple attributes |
addEvent(name, attributes?, time?) | Adds a span event |
setStatus(status) | Sets the span status |
updateName(name) | Updates the span name |
end(endTime?) | Ends the span |
isRecording() | Whether the span is recording |
recordException(exception, time?) | Records an exception as a span event |
addLink(link) | Adds a causal link |
addLinks(links) | Adds multiple causal links |
spanContext() | Returns the SpanContext |
Attribute mapping to Datadog tags
OpenTelemetry span attributes map to Datadog tags. The following attributes have special meaning:| OTel attribute | Datadog tag | Description |
|---|---|---|
service.name | service | Service name for the span |
resource.name | resource | Resource name for the span |
span.type | span.type | Span type (falls back to custom) |
Context propagation
dd-trace supports W3C Trace Context (traceparent/tracestate) by default. Use the OTel propagation API to inject and extract context:
