gRPC
The gRPC integration instruments incoming unary-unary grpc requests and outgoing unary-unary, unary-stream grpc requests using grpcio channels.
Use this integration to start or continue transactions for incoming grpc requests, create spans for outgoing requests, and ensure traces are properly propagated to downstream services.
Install sentry-sdk
from PyPI with the grpcio
extra.
pip install --upgrade 'sentry-sdk[grpcio]'
Add GRPCIntegration()
to your integrations
list, and enable tracing.
This will add appropriate intercepters to your server/client to capture errors and performance data.
import grpc
import sentry_sdk
from sentry_sdk.integrations.grpc import GRPCIntegration
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
enable_tracing=True,
integrations=[
GRPCIntegration(),
],
)
...
# this works with synchronous servers:
server = grpc.server(thread_pool=...)
# ... and asynchronous servers:
server = grpc.aio.server()
import grpc
import sentry_sdk
from sentry_sdk.integrations.grpc import GRPCIntegration
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
enable_tracing=True,
integrations=[
GRPCIntegration(),
],
)
...
# this works with synchronous clients:
with grpc.insecure_channel("example.com:12345") as channel:
...
# ... and asynchronous clients:
async with grpc.aio.insecure_channel("example.com:12345") as channel:
...
Note:
In older versions of this integration you had to add the interceptors by hand. Since Python SDK version 1.35.0 you do not need to add any interceptors by hand but only add the GRPCIntegration as described above.
If you added the GRPCIntegration
as described above, the server will create a transaction for each call to a function and send it to sentry.io.
It takes a couple of moments for the data to appear in sentry.io.
import grpc
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
enable_tracing=True,
integrations=[
GRPCIntegration(),
],
)
...
with sentry_sdk.start_transaction(op="function", name="testing_sentry"):
with grpc.insecure_channel("example.com:12345") as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name="you"))
This will create a transaction called testing_sentry
in the Performance section of sentry.io and will create a span for the call to the SayHello
method on the server.
The transaction created in the client will also be connected to the transaction on the server, giving you a full trace of your request.
If you use a framework (like Django, Flask, FastAPI, etc.) the transaction will be created for you automatically.
It takes a couple of moments for the data to appear in sentry.io.
- grpcio: 1.21.1+
- Python: 3.5+
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- pypi:sentry-sdk
- Version:
- 1.45.0
- Repository:
- https://github.com/getsentry/sentry-python
- API Documentation:
- https://getsentry.github.io/sentry-python/