![]() |
VOOZH | about |
Learn the fundamentals of OpenTelemetry, including its capabilities and benefits, key components, and how OTel and Datadog work together.
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.
Follow this guide to:
To complete this guide, you need the following:
export DD_API_KEY=<Your API Key>opentelemetry-examples repository to your device:git clone https://github.com/DataDog/opentelemetry-examples.git/calendar directory:cd opentelemetry-examples/apps/rest-services/java/calendarThe 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 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:
CalendarService.java
@WithSpan(kind=SpanKind.CLIENT)publicStringgetDate(){Spanspan=Span.current();span.setAttribute("peer.service","random-date-service");...}When the Calendar application runs, the getDate() call generates traces and spans.
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:
otelcol-config.yaml
receivers:otlp:protocols:grpc:endpoint:0.0.0.0:4317http:endpoint:0.0.0.0:4318...service:pipelines:traces:receivers:[otlp]metrics:receivers:[otlp]logs:receivers:[otlp]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:compute_stats_by_span_kind:truetrace_buffer:500hostname:"otelcol-docker"api:key:${DD_API_KEY}site:datadoghq.comconnectors:datadog/connector:traces:compute_stats_by_span_kind:trueservice: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 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:trueUpdate service.pipelines.metrics.receivers to include docker_stats:
otelcol-config.yaml
service:pipelines:metrics:receivers:[otlp, datadog/connector, docker_stats]# <- update this lineThis configuration allows the Calendar application to send container metrics to Datadog for you to explore in Datadog.
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:
logback.xml
<appender name="OpenTelemetry" class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
<immediateFlush>true</immediateFlush>
<captureExperimentalAttributes>true</captureExperimentalAttributes>
<captureKeyValuePairAttributes>true</captureKeyValuePairAttributes>
</appender>The <appender-ref ref="OpenTelemetry"/> line references the OpenTelemetry appender in the root level configuration:
logback.xml
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="OpenTelemetry"/>
</root>Additionally, environment variables configure the OpenTelemetry environment to export logs, metrics, and traces:
./deploys/docker/docker-compose-otelcol.yml.OTEL_EXPORTER_OTLP_ENDPOINT=http://otelcol:4317 configuration allows the metrics, traces, and logs to be sent with OTLP.Unified service tagging ties observability data together in Datadog so you can navigate across metrics, traces, and logs with consistent tags.
The Calendar application is already configured with unified service tagging:
Go to the Calendar application’s Docker Compose file at ./deploys/docker/docker-compose-otelcol.yml.
The following lines enable the correlation between application traces and other observability data:
docker-compose-otelcol.yml
environment:- OTEL_SERVICE_NAME=calendar-otel- OTEL_RESOURCE_ATTRIBUTES=deployment.environment=docker,host.name=otelcol-docker,service.version=<IMAGE_TAG>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-otelcol.yml upTo test that the Calendar application is running correctly, execute the following command from another terminal window:
curl localhost:9090/calendarVerify 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.
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.
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.
View runtime and infrastructure metrics to visualize, monitor, and measure the performance of your applications, hosts, containers, and processes.
Go to APM > Catalog.
Hover over the calendar-otel service and select Full Page.
Scroll to the bottom panel and select:
View logs to monitor and troubleshoot application and system operations.
@service.name:calendar-otel to the Search for field to only see logs from the Calendar application.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:
Explore your 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.
Additional helpful documentation, links, and articles:
| |