# Erlang/Elixir Instrument Erlang and Elixir applications with OpenTelemetry # Integration Instrument your Erlang and Elixir applications to send traces, logs, and metrics to Kopai. ## Installation (Elixir) Add to your `mix.exs`: ```elixir defp deps do [ {:opentelemetry_api, "~> 1.5"}, {:opentelemetry, "~> 1.7"}, {:opentelemetry_exporter, "~> 1.10"}, {:opentelemetry_cowboy, "~> 1.0"} # for auto HTTP instrumentation ] end ``` ## Installation (Erlang) Add to your `rebar.config`: ```erlang {deps, [ {opentelemetry_api, "~> 1.5"}, {opentelemetry, "~> 1.7"}, {opentelemetry_exporter, "~> 1.10"} ]}. ``` ## Configuration (Elixir) ```elixir # config/runtime.exs config :opentelemetry, span_processor: :batch, traces_exporter: :otlp config :opentelemetry_exporter, otlp_protocol: :http_protobuf, otlp_endpoint: System.get_env("OTEL_EXPORTER_OTLP_ENDPOINT") ``` ## Creating Spans ```elixir # In your application module defmodule MyApp.Application do use Application require OpenTelemetry.Tracer, as: Tracer def start(_type, _args) do # Initialize auto-instrumentation for Cowboy :opentelemetry_cowboy.setup() children = [ # your supervision tree ] Supervisor.start_link(children, strategy: :one_for_one) end end # In your handler modules defmodule MyApp.Handler do require OpenTelemetry.Tracer, as: Tracer def handle_request do Tracer.with_span "process_request" do Tracer.set_attributes([ {"http.method", "GET"}, {"custom.attribute", "value"} ]) # ... your code end end end ``` ## Running Your Application Set the required environment variables and run: ```bash export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-http.kopai.app" export OTEL_SERVICE_NAME="my-service" mix run --no-halt ``` | Variable | Description | |----------|-------------| | `OTEL_EXPORTER_OTLP_ENDPOINT` | Kopai OTLP endpoint | | `OTEL_SERVICE_NAME` | Name shown in Kopai UI | ## Working Example For a complete working example: **[Elixir Example](https://github.com/kopai-app/kopai-integration-examples/tree/main/erlang)**