Elixir Opentelemetry Instrumentation

This document contains OpenTelemetry instrumentation instructions for Elixir Phoenix + Ecto framework.

Send Traces to SigNoz Cloud

Based on your application environment, you can choose the setup below to send traces to SigNoz Cloud.

From VMs, there are two ways to send data to SigNoz Cloud.

Send traces directly to SigNoz Cloud

Step 1. Add dependencies

Install dependencies related to OpenTelemetry by adding them to mix.exs file

    {:opentelemetry_exporter, "~> 1.6"},
    {:opentelemetry_api, "~> 1.2"},
    {:opentelemetry, "~> 1.3"},
    {:opentelemetry_semantic_conventions, "~> 0.2"},
    {:opentelemetry_cowboy, "~> 0.2.1"},
    {:opentelemetry_phoenix, "~> 1.1"},
    {:opentelemetry_ecto, "~> 1.1"}

In your application start, usually the application.ex file, setup the telemetry handlers

    :opentelemetry_cowboy.setup()
    OpentelemetryPhoenix.setup(adapter: :cowboy2)
    OpentelemetryEcto.setup([:YOUR_APP_NAME, :repo])

YOUR_APP_NAME - Name of your application or service.

As an example, this is how you can setup the handlers in your application.ex file for an application called demo :

# application.ex
@impl true
def start(_type, _args) do
  :opentelemetry_cowboy.setup()
  OpentelemetryPhoenix.setup(adapter: :cowboy2)
  OpentelemetryEcto.setup([:demo, :repo])

end

Step 2. Configure Application

You need to configure your application to send telemtry data by adding the follwing config to your runtime.exs file:

config :opentelemetry, :resource, service: %{name: "<service_name>"}

config :opentelemetry, :processors,
  otel_batch_processor: %{
    exporter: {
      :opentelemetry_exporter,
      %{
        endpoints: ["https://ingest.<region>.signoz.cloud:443"],
        headers: [
          {"signoz-ingestion-key", <your-ingestion-key>}
        ]
      }
    }
  }
  • Set the <region> to match your SigNoz Cloud region
  • Replace <your-ingestion-key> with your SigNoz ingestion key.
  • <service_name> is name of your service

Send traces via OTel Collector binary

Step 1. Install OTel Collector binary

OTel Collector binary helps to collect logs, hostmetrics, resource and infra attributes.

You can find instructions to install OTel Collector binary here in your VM.

Step 2. Add dependencies

Install dependencies related to OpenTelemetry by adding them to mix.exs file

    {:opentelemetry_exporter, "~> 1.6"},
    {:opentelemetry_api, "~> 1.2"},
    {:opentelemetry, "~> 1.3"},
    {:opentelemetry_semantic_conventions, "~> 0.2"},
    {:opentelemetry_cowboy, "~> 0.2.1"},
    {:opentelemetry_phoenix, "~> 1.1"},
    {:opentelemetry_ecto, "~> 1.1"}

In your application start, usually the application.ex file, setup the telemetry handlers

    :opentelemetry_cowboy.setup()
    OpentelemetryPhoenix.setup(adapter: :cowboy2)
    OpentelemetryEcto.setup([:YOUR_APP_NAME, :repo])

As an example, this is how you can setup the handlers in your application.ex file for an application called demo :

# application.ex
@impl true
def start(_type, _args) do
  :opentelemetry_cowboy.setup()
  OpentelemetryPhoenix.setup(adapter: :cowboy2)
  OpentelemetryEcto.setup([:demo, :repo])

end

Step 3. Configure Application

You need to configure your application to send telemtry data by adding the follwing config to your runtime.exs file:

config :opentelemetry, :resource, service: %{name: "YOUR_APP_NAME"}

config :opentelemetry, :processors,
    otel_batch_processor: %{
      exporter: 
      {:opentelemetry_exporter, 
      %{endpoints: ["http://localhost:4318"]}
      }
  }

YOUR_APP_NAME: Your application or service name.

Sample Examples

Here's a tutorial with step by step guide on how to install SigNoz and start monitoring a sample Elixir app.

Thanks to our community member Ricardo for creating this guide.

Was this page helpful?