trevrpc/opentelemetry
OpenTelemetry for TrevRPC servers and clients, following the semantic
conventions for RPC with rpc.system.name trevrpc.
let assert Ok(Nil) = opentelemetry.attach_metrics()
server.Config(
..config,
telemetry: True,
// First, so that its span covers the interceptors after it.
interceptors: [opentelemetry.interceptor(opentelemetry.options())],
)
// On clients, and in handlers that call other servers:
greeter.say_hello(channel, request, opentelemetry.propagate(client.options()))
Each uses the global tracer provider, meter provider and propagator of
the OpenTelemetry SDK, which an application starts and configures with
the opentelemetry and opentelemetry_experimental Erlang packages.
See trevrpc_opentelemetry for the spans’ and the measurements’
attributes.
Types
pub type Options {
Options(trust_remote: Bool)
}
Constructors
-
Options(trust_remote: Bool)Arguments
- trust_remote
-
Whether the interceptor continues the trace a client propagated: each server span is then a child of the client’s span, and the handler’s context carries the client’s baggage. Otherwise, as suits a public API, a server span links to the client’s span instead, and the client’s baggage is dropped, so clients cannot choose the trace a server records its work in, or its sampling.
Values
pub fn attach_metrics() -> Result(Nil, Nil)
Records the duration and body sizes of every call that a server in this
node with telemetry: True handles, including the calls it rejects
before a handler runs, as rpc.server.call.duration,
rpc.server.request.size and rpc.server.response.size. It creates the
instruments with the global meter, so call it once the metrics SDK has
started. Error(Nil) means the metrics are attached already.
pub fn detach_metrics() -> Nil
Stops recording the metrics attach_metrics records.
pub fn interceptor(options: Options) -> server.Interceptor
An interceptor that traces each call a handler serves in a server span,
which is the current span of the call’s process, so that the spans the
handler starts, and the calls it makes with propagate, belong to it.
The span ends with the call, with its status code, and an error status
when the code means the server failed. Calls the server rejects before
handlers run have no span; the metrics record them.
pub fn propagate(options: client.Options) -> client.Options
Adds the trace context of the current process’s context, and its baggage, to a call’s metadata, so that a server whose interceptor trusts it continues the trace.