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.
Instrumenting the application
The Calendar sample application is already partially instrumented:
Go to the main CalendarService.java file located at: ./src/main/java/com/otel/service/CalendarService.java.
The following code instruments getDate() using the OpenTelemetry annotations and API:
When the Calendar application runs, the getDate() call generates traces and spans.
Configuring the application
OTLP Receiver
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.
OpenTelemetry Collector
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.
Sending observability data with OTLP
The Calendar application uses the OpenTelemetry logging exporter in its Logback configuration to send logs with OpenTelemetry Layer Processor (OTLP).
Go to the Calendar application’s Logback XML configuration file at /src/main/resources/logback.xml.
The following lines define the OpenTelemetry appender:
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.
Exploring observability data in Datadog
Use the Datadog UI to explore the Calendar application’s observability data.
Note: It may take a few minutes for your trace data to appear.
Runtime and infrastructure metrics
View runtime and infrastructure metrics to visualize, monitor, and measure the performance of your applications, hosts, containers, and processes.
Go to APM > Service Catalog.
Hover over the calendar-otel service and select Full Page.
Scroll to the bottom panel and select:
Infrastructure Metrics to see your Docker container metrics, such as CPU and memory usage.
JVM Metrics to see runtime metrics, such as heap usage and thread count.
Logs
View logs to monitor and troubleshoot application and system operations.
Go to Logs.
If you have other logs in the list, add @service.name:calendar-otel to the Search for field to only see logs from the Calendar application.
Select a log from the list to see more details.
Traces
View traces and spans to observe the status and performance of requests processed by your application.
Go to APM > Traces.
Find the Service section in the filter menu, and select the calendar-otel facet to display all calendar-otel traces:
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.