OpenTelemetry Datadog Exporter

The OpenTelemetry Datadog Exporter provides a span exporter from OpenTelemetry traces to Datadog by using the Datadog Agent.

Usage

from opentelemetry import trace
from opentelemetry.ext.datadog import DatadogExportSpanProcessor, DatadogSpanExporter
from opentelemetry.sdk.trace import TracerProvider

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

exporter = DatadogSpanExporter(
    agent_url="http://agent:8126", service="my-helloworld-service"
)

span_processor = DatadogExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

with tracer.start_as_current_span("foo"):
    print("Hello world!")

API

class opentelemetry.ext.datadog.DatadogSpanExporter(agent_url=None, service=None)[source]

Bases: opentelemetry.sdk.trace.export.SpanExporter

Datadog span exporter for OpenTelemetry.

Parameters
  • agent_url – The url of the Datadog Agent or use DD_TRACE_AGENT_URL environment variable

  • service – The service to be used for the application or use DD_SERVICE environment variable

property agent_writer
export(spans)[source]

Exports a batch of telemetry data.

Parameters

spans – The list of opentelemetry.trace.Span objects to be exported

Returns

The result of the export

shutdown()[source]

Shuts down the exporter.

Called when the SDK is shut down.

class opentelemetry.ext.datadog.DatadogExportSpanProcessor(span_exporter, schedule_delay_millis=5000, max_trace_size=4096)[source]

Bases: opentelemetry.sdk.trace.SpanProcessor

Datadog exporter span processor

DatadogExportSpanProcessor is an implementation of SpanProcessor that batches all opened spans into a list per trace. When all spans for a trace are ended, the trace is queues up for export. This is required for exporting to the Datadog Agent which expects to received list of spans for each trace.

on_start(span)[source]

Called when a opentelemetry.trace.Span is started.

This method is called synchronously on the thread that starts the span, therefore it should not block or throw an exception.

Parameters

span (Span) – The opentelemetry.trace.Span that just started.

Return type

None

on_end(span)[source]

Called when a opentelemetry.trace.Span is ended.

This method is called synchronously on the thread that ends the span, therefore it should not block or throw an exception.

Parameters

span (Span) – The opentelemetry.trace.Span that just ended.

Return type

None

worker()[source]
is_trace_exportable(trace_id)[source]
export()[source]

Exports traces with finished spans.

Return type

None

force_flush(timeout_millis=30000)[source]

Export all ended spans to the configured Exporter that have not yet been exported.

Parameters

timeout_millis (int) – The maximum amount of time to wait for spans to be exported.

Return type

bool

Returns

False if the timeout is exceeded, True otherwise.

shutdown()[source]

Called when a opentelemetry.sdk.trace.Tracer is shutdown.

Return type

None