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 is the OTP application name atom from your mix.exs (e.g., :my_app).
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 telemetry data by adding the following config to your runtime.exs file:
config :opentelemetry, :resource, service: %{name: "<service-name>", version: "<service-version>"}
config :opentelemetry, :processors,
otel_batch_processor: %{
exporter: {
:opentelemetry_exporter,
%{
endpoints: ["https://ingest.<region>.signoz.cloud:443"],
headers: [
{"signoz-ingestion-key", "<your-ingestion-key>"}
]
}
}
}
Verify these values:
<region>: Your SigNoz Cloud region<your-ingestion-key>: Your SigNoz ingestion key<service-name>: A descriptive name for your service (e.g.,my-phoenix-app).<service-version>(optional): Your release version, image tag, or git SHA (e.g.,1.4.2,a01dbef8).
Set service.version to a per-build value, not a static string. SigNoz detects a deployment each time this value changes. Common sources:
- Bash / shell:
service.version=$(git rev-parse --short HEAD) - GitHub Actions:
service.version=${{ github.sha }} - GitLab CI:
service.version=$CI_COMMIT_SHORT_SHA - Kubernetes: inject from your Helm chart image tag or CI variable
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 telemetry data by adding the following config to your runtime.exs file:
config :opentelemetry, :resource, service: %{name: "<service-name>", version: "<service-version>"}
config :opentelemetry, :processors,
otel_batch_processor: %{
exporter:
{:opentelemetry_exporter,
%{endpoints: ["http://localhost:4318"]}
}
}
Verify these values:
<service-name>: A descriptive name for your service (e.g.,my-phoenix-app).<service-version>(optional): Your release version, image tag, or git SHA (e.g.,1.4.2,a01dbef8).
Set service.version to a per-build value, not a static string. SigNoz detects a deployment each time this value changes. Common sources:
- Bash / shell:
service.version=$(git rev-parse --short HEAD) - GitHub Actions:
service.version=${{ github.sha }} - GitLab CI:
service.version=$CI_COMMIT_SHORT_SHA - Kubernetes: inject from your Helm chart image tag or CI variable
For Elixir (Phoenix + Ecto) application deployed on Kubernetes, you need to install OTel Collector agent in your k8s infra to collect and send traces to SigNoz Cloud. You can find the instructions to install OTel Collector agent here.
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])
Step 2. Configure Application
You need to configure your application to send telemetry data by adding the following config to your runtime.exs file:
config :opentelemetry, :resource, service: %{name: "<service-name>", version: "<service-version>"}
config :opentelemetry, :processors,
otel_batch_processor: %{
exporter:
{:opentelemetry_exporter,
%{endpoints: ["http://localhost:4318"]}
}
}
Verify these values:
<service-name>: A descriptive name for your service (e.g.,my-phoenix-app).<service-version>(optional): Your release version, image tag, or git SHA (e.g.,1.4.2,a01dbef8).
Set service.version to a per-build value, not a static string. SigNoz detects a deployment each time this value changes. Common sources:
- Bash / shell:
service.version=$(git rev-parse --short HEAD) - GitHub Actions:
service.version=${{ github.sha }} - GitLab CI:
service.version=$CI_COMMIT_SHORT_SHA - Kubernetes: inject from your Helm chart image tag or CI variable
From Windows, there are two ways to send data to SigNoz Cloud.
- Send traces directly to SigNoz Cloud
- Send traces via OTel Collector binary (recommended)
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 is the OTP application name atom from your mix.exs (e.g., :my_app).
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 telemetry data by adding the following config to your runtime.exs file:
config :opentelemetry, :resource, service: %{name: "<service-name>", version: "<service-version>"}
config :opentelemetry, :processors,
otel_batch_processor: %{
exporter: {
:opentelemetry_exporter,
%{
endpoints: ["https://ingest.<region>.signoz.cloud:443"],
headers: [
{"signoz-ingestion-key", "<your-ingestion-key>"}
]
}
}
}
Verify these values:
<region>: Your SigNoz Cloud region<your-ingestion-key>: Your SigNoz ingestion key<service-name>: A descriptive name for your service (e.g.,my-phoenix-app).<service-version>(optional): Your release version, image tag, or git SHA (e.g.,1.4.2,a01dbef8).
Set service.version to a per-build value, not a static string. SigNoz detects a deployment each time this value changes. Common sources:
- Bash / shell:
service.version=$(git rev-parse --short HEAD) - GitHub Actions:
service.version=${{ github.sha }} - GitLab CI:
service.version=$CI_COMMIT_SHORT_SHA - Kubernetes: inject from your Helm chart image tag or CI variable
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 telemetry data by adding the following config to your runtime.exs file:
config :opentelemetry, :resource, service: %{name: "<service-name>", version: "<service-version>"}
config :opentelemetry, :processors,
otel_batch_processor: %{
exporter:
{:opentelemetry_exporter,
%{endpoints: ["http://localhost:4318"]}
}
}
Verify these values:
<service-name>: A descriptive name for your service (e.g.,my-phoenix-app).<service-version>(optional): Your release version, image tag, or git SHA (e.g.,1.4.2,a01dbef8).
Set service.version to a per-build value, not a static string. SigNoz detects a deployment each time this value changes. Common sources:
- Bash / shell:
service.version=$(git rev-parse --short HEAD) - GitHub Actions:
service.version=${{ github.sha }} - GitLab CI:
service.version=$CI_COMMIT_SHORT_SHA - Kubernetes: inject from your Helm chart image tag or CI variable
Send Traces to Self-Hosted SigNoz
We'll focus on instrumenting one of the most common combos of the Elixir world: Phoenix + Ecto.
Step 1: Add dependencies
The first step to instrument your Elixir application with OpenTelemetry is to add the required dependencies to your mix.exs file and fetch them with mix deps.get
{:opentelemetry, "~> 1.0.3"},
{:opentelemetry_exporter, "~> 1.0.3"},
{:opentelemetry_phoenix, "~> 1.0.0"},
{:opentelemetry_ecto, "~> 1.0.0"}
Step 2: Configure Elixir application
Then we need to configure our application to export telemetry data. There are two things that you need to set:
<service-name>: Your application or service name for identification in SigNoz.OTEL Collector endpoint
The OTEL collector comes bundled with SigNoz installation. Since we installed SigNoz on our local machine, the endpoint ishttp://localhost:4318.
config :opentelemetry, :resource, service: %{name: "<service-name>", version: "<service-version>"}
config :opentelemetry, :processors,
otel_batch_processor: %{
exporter: {
:opentelemetry_exporter,
%{endpoints: ["http://localhost:4318"]}
}
}
Verify these values:
<service-name>: A descriptive name for your service (e.g.,my-phoenix-app).<service-version>(optional): Your release version, image tag, or git SHA (e.g.,1.4.2,a01dbef8).
Set service.version to a per-build value, not a static string. SigNoz detects a deployment each time this value changes. Common sources:
- Bash / shell:
service.version=$(git rev-parse --short HEAD) - GitHub Actions:
service.version=${{ github.sha }} - GitLab CI:
service.version=$CI_COMMIT_SHORT_SHA - Kubernetes: inject from your Helm chart image tag or CI variable
Step 3: Initialize telemetry handlers
As it is documented in the opentelemetry_phoenix and opentelemetry_ecto hexdocs.pm pages, we need to initialize both telemetry handlers.
OpentelemetryPhoenix.setup()
OpentelemetryEcto.setup([:your_app_name, :repo])
:your_app_name should be replaced by your OTP application name atom and congratulations, you have instrumented your application with OpenTelemetry.