Erlang/Elixir
Integration
Section titled “Integration”Instrument your Erlang and Elixir applications to send traces, logs, and metrics to Kopai.
Installation (Elixir)
Section titled “Installation (Elixir)”Add to your mix.exs:
defp deps do [ {:opentelemetry_api, "~> 1.5"}, {:opentelemetry, "~> 1.7"}, {:opentelemetry_exporter, "~> 1.10"}, {:opentelemetry_cowboy, "~> 1.0"} # for auto HTTP instrumentation ]endInstallation (Erlang)
Section titled “Installation (Erlang)”Add to your rebar.config:
{deps, [ {opentelemetry_api, "~> 1.5"}, {opentelemetry, "~> 1.7"}, {opentelemetry_exporter, "~> 1.10"}]}.Configuration (Elixir)
Section titled “Configuration (Elixir)”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
Section titled “Creating Spans”# In your application moduledefmodule 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) endend
# In your handler modulesdefmodule 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 endendRunning Your Application
Section titled “Running Your Application”Set the required environment variables and run:
export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp.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
Section titled “Working Example”For a complete working example: