Install & Compatibility
Where this runs
tested against v1.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 45.2MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 5.7s · import 0.000s · 43MB
42MB installed
● package 42MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
OpenTracingServerInterceptor
✓ from grpc_opentracing.server_interceptor import OpenTracingServerInterceptor
OpenTracingClientInterceptor
✓ from grpc_opentracing.client_interceptor import OpenTracingClientInterceptor
set_global_tracer
✓ import opentracing
opentracing.set_global_tracer(...)
✗ from opentracing import set_global_tracer
While `set_global_tracer` exists in the module, the common pattern is to import `opentracing` and call it as `opentracing.set_global_tracer`.
This quickstart demonstrates how to initialize `OpenTracingServerInterceptor` and `OpenTracingClientInterceptor`. It uses a `MockTracer` for simplicity; in a real application, you would configure a concrete tracer (e.g., Jaeger, Zipkin) and ensure it's made available to the interceptors, either globally or explicitly.
import grpc
from grpc_opentracing.server_interceptor import OpenTracingServerInterceptor
from grpc_opentracing.client_interceptor import OpenTracingClientInterceptor
import opentracing
from opentracing.mocktracer import MockTracer # For demonstration
# 1. Initialize an OpenTracing-compliant tracer (e.g., Jaeger, MockTracer)
mock_tracer = MockTracer()
# 2. Set the global tracer (optional, but common for simplicity)
opentracing.set_global_tracer(mock_tracer)
# 3. Create a server interceptor
server_interceptor = OpenTracingServerInterceptor(tracer=mock_tracer)
# To apply: server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), interceptors=[server_interceptor])
# 4. Create a client interceptor
client_interceptor = OpenTracingClientInterceptor(tracer=mock_tracer)
# To apply: channel = grpc.intercept_channel(grpc.insecure_channel('localhost:50051'), client_interceptor)
print("OpenTracing interceptors created successfully.")
print("Ensure a tracer is configured, either globally or passed explicitly to the interceptor.")
Debug
Known issues
breakingThe OpenTracing project is officially deprecated in favor of OpenTelemetry. This library, `grpcio-opentracing`, has not seen active development since 2019, making it a legacy solution for distributed tracing.fixFor new projects, strongly consider using `opentelemetry-instrumentation-grpc` from the OpenTelemetry Python Contrib project instead. For existing projects, be aware of the lack of ongoing support.
affects: All versions (1.x.x)
gotchaThe interceptors require an `opentracing.Tracer` instance to be configured, either globally via `opentracing.set_global_tracer()` or passed directly to the interceptor constructor (`tracer=my_tracer`). If no tracer is found, tracing will not occur and may lead to `NoneType` errors or silent failures.fixBefore using the interceptors, ensure you initialize and set an OpenTracing-compliant tracer, for example: `from jaeger_client import Config; config = Config(config={'sampler': {'type': 'const', 'param': 1}}, service_name='my-grpc-app'); opentracing.set_global_tracer(config.initialize_tracer())` affects: All versions (1.x.x)
gotchaDue to the lack of recent maintenance, `grpcio-opentracing` might have untested or unstable compatibility with newer versions of `grpcio` or Python. This could lead to unexpected behavior or runtime errors.fixThoroughly test `grpcio-opentracing` with your specific `grpcio` and Python versions. Consider pinning exact versions of `grpcio` if stability issues arise. Migrating to OpenTelemetry is the recommended long-term solution.
affects: All versions (1.x.x)
Upgrade
Version history
1.1.4latest on PyPI · released Apr 18, 2019
Audit
Dependencies
grpciorequiredCore gRPC library for which interceptors are provided.
opentracingrequiredThe OpenTracing API, which this library implements extensions for.