Installation

Add the official OpenTelemetry Erlang/Elixir packages, configure the OTLP exporter, and set environment variables to send traces from Phoenix or plain Elixir apps to Sophonz.

This wires up the upstream opentelemetry Erlang/Elixir packages — not a Sophonz package. Connection details (endpoint, protocol, headers, resource attributes) come from environment variables; a small amount of Application config selects the batch OTLP pipeline, which is standard practice for this SDK regardless of backend.

Quick start

Enter the collector URL, project, app, version and app key below to generate the snippet from those values — there are no tabs to pick. Advanced options are behind the "Advanced options" toggle.

# mix.exs — add to deps
{:opentelemetry, "~> 1.7"},
{:opentelemetry_api, "~> 1.5"},
{:opentelemetry_exporter, "~> 1.10"},
{:opentelemetry_phoenix, "~> 2.0"},
{:opentelemetry_bandit, "~> 0.3"}, # Phoenix 1.7+ default adapter
# {:opentelemetry_cowboy, "~> 1.0"}, # use instead if you're still on Cowboy
{:opentelemetry_ecto, "~> 1.2"}

# config/runtime.exs
config :opentelemetry,
  span_processor: :batch,
  traces_exporter: :otlp,
  resource: %{
    service: %{
      name: "next-sample",
      namespace: "sophonz",
      version: "1.0.0",
      key: "sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz"
    },
    deployment: %{environment: %{name: "production"}}
  }

config :opentelemetry_exporter,
  otlp_endpoint: "https://in.sophonz.ai",
  otlp_headers: [{"authorization", "sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz"}],
  otlp_protocol: :http_protobuf

# lib/my_app/application.ex — in start/2, before the supervision tree starts
OpentelemetryPhoenix.setup(adapter: :bandit)
OpentelemetryEcto.setup([:my_app, :repo])

Prerequisites

  • Elixir 1.15+ / OTP 25+.
  • A service registered in the Sophonz console, and the sk_... API key issued for it.

Add the dependencies

# mix.exs
def deps do
  [
    {:opentelemetry, "~> 1.7"},
    {:opentelemetry_api, "~> 1.5"},
    {:opentelemetry_exporter, "~> 1.10"},
 
    # Phoenix apps: pick the instrumentation that matches your stack
    {:opentelemetry_phoenix, "~> 2.0"},
    {:opentelemetry_bandit, "~> 0.3"}, # Phoenix 1.7+ default adapter
    # {:opentelemetry_cowboy, "~> 1.0"}, # use instead if you're still on Cowboy
    {:opentelemetry_ecto, "~> 1.2"}
  ]
end

TIP — Get your API key

Log in to the Sophonz console, register the service, and copy the issued sk_... key. It carries your tenant identity — see service.key below.

Configure the OTLP exporter

In config/runtime.exs (or config/config.exs for a non-release setup), select the batch OTLP pipeline:

# config/runtime.exs
config :opentelemetry,
  span_processor: :batch,
  traces_exporter: :otlp

opentelemetry_exporter itself needs no extra config — it reads OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL, and OTEL_EXPORTER_OTLP_HEADERS from the OS environment automatically. Set those (and OTEL_RESOURCE_ATTRIBUTES) at deploy time — see below.

Attach the instrumentation

In your Application.start/2, before your supervision tree starts (or right after, for the Ecto repo which needs to exist first):

# lib/my_app/application.ex
def start(_type, _args) do
  OpentelemetryPhoenix.setup(adapter: :bandit) # or :cowboy2
  OpentelemetryEcto.setup([:my_app, :repo])
 
  children = [
    # ... your existing children
  ]
 
  Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end

OpentelemetryPhoenix.setup/1 and OpentelemetryEcto.setup/1 attach :telemetry handlers to the events Phoenix and Ecto already emit — there's no separate span-creation code to write.

Configure environment variables

OTEL_EXPORTER_OTLP_ENDPOINT=https://in.sophonz.ai
OTEL_EXPORTER_OTLP_PROTOCOL=http_protobuf
OTEL_EXPORTER_OTLP_HEADERS=authorization=sk_your_api_key
OTEL_RESOURCE_ATTRIBUTES=service.name=my-elixir-service,service.key=sk_your_api_key,service.namespace=my-project,deployment.environment.name=production
VariableValueNotes
OTEL_EXPORTER_OTLP_ENDPOINThttps://in.sophonz.aiBase OTLP endpoint. opentelemetry_exporter derives v1/traces from it.
OTEL_EXPORTER_OTLP_PROTOCOLhttp_protobufNote the underscore — opentelemetry_exporter accepts the same value as the standard OTEL_EXPORTER_OTLP_PROTOCOL env var, mapped internally to the otlp_protocol: :http_protobuf config key.
OTEL_EXPORTER_OTLP_HEADERSauthorization=sk_your_api_keySent as an HTTP header on every export request.
OTEL_RESOURCE_ATTRIBUTESservice.name=...,service.key=sk_your_api_key,service.namespace=...,deployment.environment.name=...Read automatically by the SDK's default otel_resource_env_var detector. service.key is the tenant identity the collector checks — required.

CAUTION — OTEL_SERVICE_NAME is not read by this SDK

Unlike Node, Go, Java, or Ruby, the Erlang/Elixir SDK does not read the plain OTEL_SERVICE_NAME variable — only OTEL_RESOURCE_ATTRIBUTES is picked up by its resource detector. Set service.name as part of OTEL_RESOURCE_ATTRIBUTES (as shown above), or your service will report as unknown_service and its telemetry won't join the service you registered in the console even if service.key is correct.

CAUTION — service.key is required

The collector runs in enforce mode: telemetry without a resolvable service.key resource attribute is dropped silently. Your app keeps running and nothing errors — the console simply stays empty. Always include service.key in OTEL_RESOURCE_ATTRIBUTES, and send the same key as the authorization header via OTEL_EXPORTER_OTLP_HEADERS.

Phoenix and Ecto notes

  • Adapter matters: pass adapter: :bandit to OpentelemetryPhoenix.setup/1 if your Phoenix app uses Bandit (the default since Phoenix 1.7), or adapter: :cowboy2 if it's still on Cowboy. Add the matching opentelemetry_bandit or opentelemetry_cowboy dependency.
  • Ecto: OpentelemetryEcto.setup([:my_app, :repo]) takes the telemetry prefix for your repo — the same atom list you'd pass to :telemetry.attach, typically your app's :telemetry_prefix config on the Ecto.Repo (defaults to [:my_app, :repo] for a repo named MyApp.Repo).
  • LiveView: opentelemetry_phoenix instruments LiveView mount/handle_event telemetry events in addition to controller actions, so no separate package is needed.

Verify

Start your app with the environment variables set:

OTEL_EXPORTER_OTLP_ENDPOINT=https://in.sophonz.ai \
OTEL_EXPORTER_OTLP_PROTOCOL=http_protobuf \
OTEL_EXPORTER_OTLP_HEADERS=authorization=sk_your_api_key \
OTEL_RESOURCE_ATTRIBUTES=service.name=my-elixir-service,service.key=sk_your_api_key,service.namespace=my-project,deployment.environment.name=production \
mix phx.server

Export failures are logged by the OTLP exporter at the :error level rather than crashing your app, so a clean boot doesn't guarantee telemetry arrived — an invalid or missing service.key fails exactly the same way as a working setup, just with nothing to show for it. Generate some requests, then check the Sophonz console for the service you registered.

TIP — This is just the beginning

Now ship your app. Sophonz surfaces the problems real users hit — so your app evolves on its own.