Skip to content
Created by

Observability

Connect uses ASGI and WSGI for the server side, which means any logging, tracing, or metrics that work with them will also work with Connect. In particular, the opentelemetry-instrumentation-asgi and opentelemetry-instrumentation-wsgi OpenTelemetry packages both integrate seamlessly with Connect servers. The Connect client includes HTTP observability out of the box.

For more detailed, RPC-focused telemetry, use the connectrpc-otel package. connectrpc-otel works with your OpenTelemetry metrics and tracing setup to capture information such as:

  • rpc.system.name: Was this call handled by a Connect server or client?
  • rpc.method: What service and method was called?
  • error.type/rpc.response.status_code: What specific Connect error was returned?

OpenTelemetry can be quite complex, so this guide assumes that readers are familiar with:

Once you have OpenTelemetry set up in your application, add the connectrpc-otel dependency in your project. If you are using auto-instrumentation, such as with opentelemetry-instrument, you are done - servers and clients will be automatically instrumented and generate telemetry.

To manually instrument your app instead, just register the OpenTelemetryInterceptor when initializing a server or client.

from connectrpc_otel import OpenTelemetryInterceptor
from greet.v1.greet_connect import GreetServiceASGIApplication, GreetServiceClient
from greet.v1.greet_pb2 import GreetRequest
from server import Greeter
app = GreetServiceASGIApplication(Greeter(), interceptors=[OpenTelemetryInterceptor()])
client = GreetServiceClient(
"http://localhost:8080",
interceptors=[OpenTelemetryInterceptor(client=True)],
)

By default, this will use the global TextMapPropagator, MeterProvider, and TraceProvider from OpenTelemetry. To customize them, pass the components you initialized to the OpenTelemetryInterceptor constructor.