Skip to content

An example Phoenix app using OpenTelemetry to report traces to Datadog

Notifications You must be signed in to change notification settings

kamilkowalski/elixir_opentelemetry_datadog_example

Repository files navigation

Elixir + OpenTelemetry + Datadog Example

This is an example Phoenix application that makes use of OpenTelemetry tracing and sends traces to Datadog over the OpenTelemetry Collector.

Running it

You'll need Elixir, Docker and PostgreSQL to run the example app.

First, setup the app:

mix setup

Then export your Datadog configuration:

export DD_ENV=`whoami`-local
export DD_SERVICE=test-service
export DD_VERSION=1.0
export DD_API_KEY=<your Datadog API key>

In the same shell, start the collector using:

docker-compose up -d

Finally, run the application:

mix phx.server

Visit http://localhost:4000/posts a couple of times for the traces to be sent to Datadog and observe them in Datadog's APM page.

Moving parts

Here's an outline of the important parts of this example.

Phoenix app

Most of the source code is that of a Phoenix application with OpenTelemetry configured. In order to do that, we needed the following dependencies:

Instrumented code can be seen in PostController's index function.

The exporter is configured in config/config.exs and by default reports traces to localhost:9090.

Docker Compose file

The docker-compose.yaml file specifies an otel-collector service based on the opentelemetry-collector-contrib image.

The -contrib version of the collector is used because it includes the Datadog exporter.

We're passing our environment variables to the service and mounting the collector config file in a volume accessible to it.

Collector config

OpenTelemetry Collector is configured via otel-collector-config.yaml according to the Configuration guide.

In this simple setup, we're using:

  • the OTLP receiver using an HTTP interface to receive traces from our application,
  • the batch processor with a timeout of 10s as suggested by the Datadog exporter,
  • and the Datadog exporter that actually sends traces to Datadog.

All of the above are used in a single traces pipeline.

About

An example Phoenix app using OpenTelemetry to report traces to Datadog

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published