nhttp_otel (nhttp v1.0.0)

View Source

OpenTelemetry integration for nhttp server.

Provides distributed tracing (spans) and metrics for connection and request lifecycle events. Telemetry is configurable via the otel option in server settings.

Configuration:

  • otel => #{traces => true, metrics => true} - Enable both
  • otel => true - Shorthand for both
  • otel => false - Disabled (default)

Spans follow HTTP semantic conventions:

  • Connection span: long-lived, parent of request spans
  • Request spans: method, path, status, duration

Active requests counter: Use nhttp_otel:active_requests/0 to query the current count of in-flight requests across all connections.

Summary

Functions

Get the current count of active (in-flight) requests. Returns 0 if the counter hasn't been initialized.

Parse otel configuration from server options.

Types

config()

-type config() :: #{metrics := boolean(), traces := boolean()} | false.

conn_attrs()

-type conn_attrs() ::
          #{version := nhttp_lib:version(),
            remote_ip := inet:ip_address(),
            remote_port := inet:port_number(),
            server_port => inet:port_number(),
            transport := tcp | ssl | udp}.

conn_end_attrs()

-type conn_end_attrs() :: #{reason := atom(), requests := non_neg_integer()}.

req_attrs()

-type req_attrs() ::
          #{method := binary(), path := binary(), scheme := binary(), stream_id := non_neg_integer()}.

req_end_attrs()

-type req_end_attrs() :: #{response_body_size => non_neg_integer(), status := 100..599}.

span_ctx()

-type span_ctx() :: opentelemetry:span_ctx() | undefined.

Functions

active_requests()

-spec active_requests() -> non_neg_integer().

Get the current count of active (in-flight) requests. Returns 0 if the counter hasn't been initialized.

config(Opts)

-spec config(map()) -> config().

Parse otel configuration from server options.