OpenTelemetry Phoenix monitoring

Vladimir Mihailenco
September 30, 2024
3 min read

OpenTelemetry Phoenix is an implementation of the OpenTelemetry specification for Phoenix Framework. It provides a set of libraries and tools for instrumenting Phoenix applications to collect telemetry data such as metrics, traces, and logs.

Otel Phoenix provides the ability to trace Phoenix web requests and to measure the performance and resource utilization of these requests. You can then analyze this information to understand how an application is handling web traffic and to identify performance bottlenecks and other issues.

What is OpenTelemetry?

OpenTelemetry is an open-source observability framework that aims to standardize and simplify the collection, processing, and export of telemetry data from applications and systems.

OpenTelemetry supports multiple programming languages and platforms, making it suitable for a wide range of applications and environments.

OpenTelemetry enables developers to instrument their code and collect telemetry data, which can then be exported to various OpenTelemetry backends or observability platforms for analysis and visualization. The OpenTelemetry Collector can be deployed as a sidecar or standalone service to efficiently collect and process telemetry data from your Phoenix applications.

OpenTelemetry Phoenix

With OpenTelemetry Phoenix, developers can gain a deeper understanding of how their applications handle web requests. Then can use this information to improve the performance and reliability of their applications.

Otel Phoenix can help developers monitor and diagnose issues with their Phoenix-based applications, and it can provide valuable insights into the behavior of the applications in production.

Usage

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:

elixir
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 documentation for the full list of supported options.

What is Uptrace?

Uptrace is a OpenTelemetry APM that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues. For Elixir instrumentation, see the OpenTelemetry Erlang guide and compare with top APM tools.

Uptrace Overview

Uptrace comes with an intuitive query builder, rich dashboards, alerting rules with notifications, and integrations for most languages and frameworks.

Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.

In just a few minutes, you can try Uptrace by visiting the cloud demo (no login required) or running it locally with Docker. The source code is available on GitHub.

What's next?

To get start with OpenTelemetry, see OpenTelemetry Elixir.

To collect more telemetry data from your Phoenix application, you'll need to instrument your code using the OpenTelemetry Phoenix API. This typically involves adding calls to the OpenTelemetry Phoenix library at key points in your code, such as when a request is received or when a database query is executed.