Skip to content

Erlang/Elixir

This guide demonstrates how to instrument an Erlang or Elixir application with OpenTelemetry to send traces and metrics to FusionReactor Cloud.

Platform Status

OpenTelemetry Erlang/Elixir is stable for traces and metrics. Logs are in beta. Works with both Erlang and Elixir applications.

Prerequisites

  • FusionReactor API Key: Obtain this from Account Settings > API Keys in FusionReactor Cloud.
  • Erlang/OTP: 22+ or Elixir: 1.11+ installed on your system.
  • Telemetry Pipeline: You must have either an OpenTelemetry Collector or Grafana Alloy configured and running to receive data from your application.

Set up your telemetry pipeline first

Before instrumenting your application, ensure you have completed either the Collector setup guide or Grafana Alloy setup guide so your telemetry data has a destination.

For Elixir Applications

Step 1: Add dependencies

Add to your mix.exs:

def deps do
  [
    {:opentelemetry, "~> 1.3"},
    {:opentelemetry_exporter, "~> 1.6"},
    {:opentelemetry_api, "~> 1.2"}
  ]
end

Install dependencies:

mix deps.get

Step 2: Configure OpenTelemetry

Add to your config/config.exs:

config :opentelemetry, :resource,
  service: [
    name: "fibonacci-service"
  ]

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

Step 3: Create your instrumented application

Create lib/fibonacci.ex:

defmodule Fibonacci do
  require OpenTelemetry.Tracer, as: Tracer

  def calculate(n) do
    Tracer.with_span "calculate_fibonacci", %{iterations: n} do
      Enum.reduce(1..n, {0, 1}, fn i, {prev, current} ->
        Tracer.with_span "fibonacci_iteration", %{iteration: i, value: current} do
          IO.puts("Iteration #{i}: #{current}")
          Process.sleep(100)
          {current, prev + current}
        end
      end)
    end
  end

  def main(args) do
    case args do
      [n_str | _] ->
        n = String.to_integer(n_str)
        IO.puts("Starting Fibonacci calculator")
        IO.puts("Fibonacci by Iteration - #{n} rounds")

        calculate(n)

        IO.puts("Fibonacci complete")
      _ ->
        IO.puts("Usage: mix run -e 'Fibonacci.main([\"20\"])'")
    end
  end
end

Step 4: Run locally

mix run -e 'Fibonacci.main(["20"])'

The application will calculate 20 Fibonacci numbers and send telemetry to your local collector.

Cannot connect to collector?

If you see: Connection errors Fix: Your collector is not running. Start it first using the Collector setup guide.

For Erlang Applications

Dependencies

Add to your rebar.config:

{deps, [
    {opentelemetry_api, "~> 1.2"},
    {opentelemetry, "~> 1.3"},
    {opentelemetry_exporter, "~> 1.6"}
]}.

Configuration

Add to config/sys.config:

[
  {opentelemetry,
   [{resource, #{service => #{name => <<"fibonacci-service">>}}},
    {processors, [
      {otel_batch_processor, #{
        exporter => {opentelemetry_exporter, #{
          endpoints => [<<"http://localhost:4318/v1/traces">>],
          protocol => http_protobuf
        }}
      }}
    ]}
   ]}
].

Step 5: Verify in FusionReactor Cloud

  1. Log in to FusionReactor Cloud
  2. Navigate to Explore:
  3. Traces: Select Resource Service Name = fibonacci-service
  4. Metrics: Search for application metrics

You should see: - Trace spans showing the execution flow - Span attributes with iteration information - Timing data for operations

Next steps

  • Instrument Phoenix applications with opentelemetry_phoenix
  • Add Ecto instrumentation with opentelemetry_ecto
  • Instrument HTTP clients with automatic libraries
  • Create custom dashboards in FusionReactor Cloud


Need more help?

Contact support in the chat bubble and let us know how we can assist.