OpenTelemetry

Observability

Traces and metrics for BEAM apps (OTLP/HTTP JSON export).

Call configure from boot with an opaque Config. The runtime does not read OTEL_* env vars; bind whatever names you want with Env and pass them in.

Until configure runs, spans and metrics are no-ops. HTTP (Server), outbound Req, and Repo transactions are instrumented automatically once configured.

Types

Config

type Config = Config

Exporter and signal settings.

Examples

OpenTelemetry.defaultConfig

Values

defaultConfig

defaultConfig : Config

Disabled config (no export).

Examples

OpenTelemetry.defaultConfig

serviceName

serviceName : String -> Config -> Config

Resource service.name.

Examples

OpenTelemetry.serviceName "my-app" config

otlpEndpoint

otlpEndpoint : String -> Config -> Config

OTLP collector base URL (for example http://127.0.0.1:4318).

Examples

OpenTelemetry.otlpEndpoint "http://127.0.0.1:4318" config

tracesEnabled

tracesEnabled : Bool -> Config -> Config

Enable or disable trace export (default true when an endpoint is set).

Examples

OpenTelemetry.tracesEnabled True config

metricsEnabled

metricsEnabled : Bool -> Config -> Config

Enable or disable metrics export (default true when an endpoint is set).

Examples

OpenTelemetry.metricsEnabled True config

configure

configure : Config -> ()

Install config and start the SDK once. Call from application boot.

Examples

OpenTelemetry.defaultConfig
    |> OpenTelemetry.serviceName "my-app"
    |> OpenTelemetry.otlpEndpoint "http://127.0.0.1:4318"
    |> OpenTelemetry.configure

withSpan

withSpan : String -> List (String, String) -> (() -> a) -> a

Run thunk inside a named span with string attributes.

Examples

OpenTelemetry.withSpan "checkout" [ ("cart_id", id) ] (\() -> charge cart)

setAttribute

setAttribute : String -> String -> ()

Set an attribute on the current span.

Examples

OpenTelemetry.setAttribute "user.id" userId

addEvent

addEvent : String -> List (String, String) -> ()

Add a timed event on the current span.

Examples

OpenTelemetry.addEvent "cache.miss" [ ("key", key) ]

counter

counter : String -> Int -> ()

Add n to a counter instrument.

Examples

OpenTelemetry.counter "http.requests" 1

histogram

histogram : String -> Float -> ()

Record a histogram measurement.

Examples

OpenTelemetry.histogram "http.duration_ms" 12.5

traceId

traceId : () -> Maybe String

Current trace id when a span is active.

Examples

OpenTelemetry.traceId ()

spanId

spanId : () -> Maybe String

Current span id when a span is active.

Examples

OpenTelemetry.spanId ()