OpenTelemetry

June 3, 2026 · View on GitHub

Server-side OpenTelemetry instrumentation for distributed tracing and metrics. Requires pip install vgi-rpc[otel].

Usage

from vgi_rpc import RpcServer
from vgi_rpc.otel import OtelConfig, instrument_server

server = RpcServer(MyService, MyServiceImpl())
instrument_server(server)  # uses global TracerProvider / MeterProvider

This creates spans and records metrics for every RPC call:

  • Span: includes method name, service name, auth context, duration, error status, and per-call I/O statistics
  • Counter: rpc.server.requests — number of RPC requests handled
  • Histogram: rpc.server.duration — duration in seconds

Trace context propagates automatically: from contextvars (pipe transport) or W3C headers (HTTP transport).

Span Attributes

Each span carries the following attributes:

AttributeTypeDescription
rpc.systemstrAlways "vgi_rpc"
rpc.servicestrProtocol class name
rpc.methodstrMethod name
rpc.vgi_rpc.method_typestr"unary" or "stream"
rpc.vgi_rpc.server_idstrServer instance identifier
rpc.vgi_rpc.auth.principalstrCaller principal (when authenticated)
rpc.vgi_rpc.auth.domainstrAuth scheme (when authenticated)
rpc.vgi_rpc.auth.authenticatedstr"true" or "false"
client.addressstrClient IP address (HTTP only)
user_agent.originalstrUser agent string (HTTP only)
rpc.vgi_rpc.input_batchesintNumber of input batches read by the server
rpc.vgi_rpc.output_batchesintNumber of output batches written by the server
rpc.vgi_rpc.input_rowsintTotal rows across all input batches
rpc.vgi_rpc.output_rowsintTotal rows across all output batches
rpc.vgi_rpc.input_bytesintApproximate logical bytes across all input batches
rpc.vgi_rpc.output_bytesintApproximate logical bytes across all output batches
rpc.vgi_rpc.error_typestrException class name (error spans only)

The I/O statistics attributes (input_batches through output_bytes) are populated from CallStatistics — see CallStatistics for counting semantics.

Note: Byte counts use pa.RecordBatch.get_total_buffer_size() — logical Arrow buffer sizes without IPC framing overhead.

API Reference

OtelConfig

::: vgi_rpc.otel.OtelConfig

instrument_server

::: vgi_rpc.otel.instrument_server