Monitor Erlang/Elixir applications with Uptrace

This document explains how to configure OpenTelemetry Erlang/Elixir SDK to export spans to Uptrace using OTLP/gRPC.

Configuration

OpenTelemetry SDK starts up its supervision tree on boot, so initial configuration must be done through the Application or environment variables.

To send data to a self-managed Uptraceopen in new window installation:

config :opentelemetry,
  span_processor: :batch,
  traces_exporter: :otlp

config :opentelemetry_exporter,
  otlp_protocol: :grpc,
  otlp_compression: :gzip,
  otlp_endpoint: "http://localhost:14317"
  otlp_headers: [{"uptrace-dsn", "http://project2_secret_token@localhost:14318?grpc=14317"}]
[
 {opentelemetry,
  [{span_processor, batch},
   {traces_exporter, otlp}]},

 {opentelemetry_exporter,
  [{otlp_protocol, grpc},
   {otlp_compression, gzip},
   {otlp_endpoint, "http://localhost:14317"},
   {otlp_headers, [{"uptrace-dsn", "http://project2_secret_token@localhost:14318?grpc=14317"}]]}]}
].

To send data to Uptrace Cloudopen in new window:

config :opentelemetry,
  span_processor: :batch,
  traces_exporter: :otlp

config :opentelemetry_exporter,
  otlp_protocol: :grpc,
  otlp_compression: :gzip,
  otlp_endpoint: "https://otlp.uptrace.dev:4317"
  otlp_headers: [{"uptrace-dsn", "https://FIXME@api.uptrace.dev?grpc=4317"}]
[
 {opentelemetry,
  [{span_processor, batch},
   {traces_exporter, otlp}]},

 {opentelemetry_exporter,
  [{otlp_protocol, grpc},
   {otlp_compression, gzip},
   {otlp_endpoint, "https://otlp.uptrace.dev:4317"},
   {otlp_headers, [{"uptrace-dsn", "https://FIXME@api.uptrace.dev?grpc=4317"}]]}]}
].

See the official documentationopen in new window for the full list of available options.

Environment variables

You can also configure OpenTelemetry using the environment variables.

To send data to a self-managed Uptraceopen in new window installation:

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:14317
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=gzip
OTEL_EXPORTER_OTLP_TRACES_HEADERS="uptrace-dsn=http://project2_secret_token@localhost:14318?grpc=14317"

To send data to Uptrace Cloudopen in new window:

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://otlp.uptrace.dev:4317
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=gzip
OTEL_EXPORTER_OTLP_TRACES_HEADERS="uptrace-dsn=https://FIXME@api.uptrace.dev?grpc=4317"

See the official documentationopen in new window for the full list of available options.

OpenTelemetry Phoenix

To use OpenTelemetry Phoenix, you'll need to add the opentelemetry_phoenix library to your application's dependencies in the mix.exs file.

In your application start:

def start(_type, _args) do
  :opentelemetry_cowboy.setup()
  OpentelemetryPhoenix.setup(adapter: :cowboy2)

  children = [
    {Phoenix.PubSub, name: MyApp.PubSub},
    MyAppWeb.Endpoint
  ]

  opts = [strategy: :one_for_one, name: MyStore.Supervisor]
  Supervisor.start_link(children, opts)
end

See the official documentationopen in new window for the full list of supported options.

OpenTelemetry Ecto

OpenTelemetry Ecto is a set of packages and libraries for instrumenting the Ecto library with OpenTelemetry.

OpenTelemetry Ecto provides the ability to trace Ecto database operations, such as database queries and changes, and to measure the performance and resource utilization of these operations. This information can then be analyzed to understand how an application is using the database and to identify performance bottlenecks and other issues.

To use OpenTelemetry Elixir Ecto, you'll need to add the opentelemetry_ecto library to your application's dependencies in the mix.exs file.

In your application start:

OpentelemetryEcto.setup([:blog, :repo])

See the official documentationopen in new window for the full list of supported options.

Last Updated: