OpenTelemetry is an open source observability framework that provides IT teams with standardized protocols and tools for collecting and routing observability data from software applications. OpenTelemetry provides a consistent format for
Instrumentation is the process of adding code to your application to capture and report observability data to Datadog, such as traces, metrics, and logs., generating, gathering, and exporting application observability data—namely metrics, logs, and traces—to monitoring platforms for analysis and insight.
This guide demonstrates how to configure a sample OpenTelemetry application to send observability data to Datadog using the OpenTelemetry SDK, OpenTelemetry Collector, and Datadog Exporter. This guide also shows you how to explore this data in the Datadog UI.
(Optional) Use Linux to send infrastructure metrics.
The Calendar application uses OpenTelemetry tools to generate and collect metrics, logs, and traces. The following steps explain how to get this observability data into Datadog.
The Calendar application is already configured to send data from the OpenTelemetry SDK to the OpenTelemetry Protocol (OTLP) receiver in the OpenTelemetry Collector.
Go to the Collector configuration file located at: ./src/main/resources/otelcol-config.yaml.
The following lines configure the OTLP Receiver to receive metrics, traces, and logs:
The Datadog Exporter sends data collected by the OTLP Receiver to the Datadog backend.
Go to the otelcol-config.yaml file.
The following lines configure the Datadog Exporter to send observability data to Datadog:
otelcol-config.yaml
exporters:datadog:traces:span_name_as_resource_name:truetrace_buffer:500hostname:"otelcol-docker"api:key:${DD_API_KEY}site:datadoghq.comconnectors:datadog/connector:service:pipelines:metrics:receivers:[otlp, datadog/connector]# <- update this lineexporters:[datadog]traces:exporters:[datadog, datadog/connector]logs:exporters:[datadog]
Set exporters.datadog.api.site to your Datadog site. Otherwise, it defaults to US1.
This configuration allows the Datadog Exporter to send runtime metrics, traces, and logs to Datadog. However, sending infrastructure metrics requires additional configuration.
In this example, configure your OpenTelemetry Collector to send infrastructure metrics.
To send infrastructure metrics from the OpenTelemetry Collector to Datadog, you must use Linux. This is a limitation of the Docker Stats receiver.
To collect container metrics, configure the Docker stats receiver in your Datadog Exporter:
Add a docker_stats block to the receivers section of otel-config.yaml:
otelcol-config.yaml
receivers:otlp:protocols:grpc:endpoint:0.0.0.0:4317http:endpoint:0.0.0.0:4318# add the following blockdocker_stats:endpoint:unix:///var/run/docker.sock# default; if this is not the Docker socket path, update to the correct pathmetrics:container.network.io.usage.rx_packets:enabled:truecontainer.network.io.usage.tx_packets:enabled:truecontainer.cpu.usage.system:enabled:truecontainer.memory.rss:enabled:truecontainer.blockio.io_serviced_recursive:enabled:truecontainer.uptime:enabled:truecontainer.memory.hierarchical_memory_limit:enabled:true
Update service.pipelines.metrics.receivers to include docker_stats:
otelcol-config.yaml
service:pipelines:metrics:receivers:[otlp, datadog/connector, docker_stats]# <- update this line
This configuration allows the Calendar application to send container metrics to Datadog for you to explore in Datadog.
To start generating and forwarding observability data to Datadog, you need to run the Calendar application with the OpenTelemetry SDK:
Run the application from the calendar/ folder:
docker compose -f deploys/docker/docker-compose-otel.yml up
This command creates a Docker container with the OpenTelemetry Collector and the Calendar service.
To test that the Calendar application is running correctly, execute the following command from another terminal window:
curl localhost:9090/calendar
Verify that you receive a response like:
{"date":"2022-12-30"}
Run the curl command several times to ensure at least one trace exports to the Datadog backend.
The Calendar application uses the probabilistic sampler processor, so only 30% of traces sent through the application reach the target backend.
Each call to the Calendar application results in metrics, traces, and logs being forwarded to the OpenTelemetry Collector, then to the Datadog Exporter, and finally to the Datadog backend.
To start, click on a trace to open the trace side panel and find more details about the trace and its spans. For example, the Flame Graph captures how much time was spent in each component of the Calendar execution path:
Notice that you can select Infrastructure, Metrics, or Logs in the bottom panel to correlate your trace with other observability data.