OpenTelemetry Datadog Exporter¶
pip install opentelemetry-exporter-datadog
The Datadog exporter provides a span processor that must be added along with the exporter. In addition, a formatter is provided to handle propagation of trace context between OpenTelemetry-instrumented and Datadog-instrumented services in a distributed trace.
from opentelemetry import propagators, trace from opentelemetry.exporter.datadog import DatadogExportSpanProcessor, DatadogSpanExporter from opentelemetry.exporter.datadog.propagator import DatadogFormat 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) # Optional: use Datadog format for propagation in distributed traces propagators.set_global_httptextformat(DatadogFormat()) with tracer.start_as_current_span("foo"): print("Hello world!")
The docs/examples/datadog_exporter includes examples for using the Datadog exporter with OpenTelemetry instrumented applications.
DatadogSpanExporter(agent_url=None, service=None, env=None, version=None, tags=None)¶
Datadog span exporter for OpenTelemetry.
agent_url – The url of the Datadog Agent or use
service – The service name to be used for the application or use
env – Set the application’s environment or use
version – Set the application’s version or use
tags – A list of default tags to be added to every span or use
Exports a batch of telemetry data.
spans – The list of
opentelemetry.trace.Spanobjects to be exported
The result of the export
Shuts down the exporter.
Called when the SDK is shut down.
DatadogExportSpanProcessor(span_exporter, schedule_delay_millis=5000, max_trace_size=4096)¶
Datadog exporter span processor
DatadogExportSpanProcessor is an implementation of
SpanProcessorthat 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.
Called when a
This method is called synchronously on the thread that starts the span, therefore it should not block or throw an exception.
Called when a
This method is called synchronously on the thread that ends the span, therefore it should not block or throw an exception.
Exports traces with finished spans.
- Return type
Export all ended spans to the configured Exporter that have not yet been exported.