From fba9d831ef63d33315088a10e96de84fb3337cc7 Mon Sep 17 00:00:00 2001 From: Florian Dellekart Date: Wed, 3 Jul 2024 14:59:00 +0200 Subject: [PATCH] fix(grpc): Transform metadata into Metadata object in case it's a tuple Up until version 1.65.0 of grpcio, the metadata was not guaranteed to arrive as the type specified in annotations but could be a tuple. To support versions before that we check and transform it here. --- sentry_sdk/integrations/grpc/aio/client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sentry_sdk/integrations/grpc/aio/client.py b/sentry_sdk/integrations/grpc/aio/client.py index 5b687ef416..6230e311a7 100644 --- a/sentry_sdk/integrations/grpc/aio/client.py +++ b/sentry_sdk/integrations/grpc/aio/client.py @@ -23,6 +23,10 @@ def _update_client_call_details_metadata_from_scope( ) -> ClientCallDetails: if client_call_details.metadata is None: client_call_details = client_call_details._replace(metadata=Metadata()) + elif not isinstance(client_call_details.metadata, Metadata): + client_call_details = client_call_details._replace( + metadata=Metadata.from_tuple(client_call_details.metadata) + ) for key, value in Scope.get_current_scope().iter_trace_propagation_headers(): client_call_details.metadata.add(key, value) return client_call_details