44from sentry_sdk .consts import OP , SPANDATA
55from sentry_sdk .integrations import DidNotEnable
66from sentry_sdk .integrations .grpc .consts import SPAN_ORIGIN
7- from sentry_sdk .tracing_utils import has_span_streaming_enabled
87
98if TYPE_CHECKING :
109 from typing import Any , Callable , Iterable , Iterator , Union
@@ -31,54 +30,27 @@ def intercept_unary_unary(
3130 ) -> "_UnaryOutcome" :
3231 method = client_call_details .method
3332
34- span_streaming = has_span_streaming_enabled (sentry_sdk .get_client ().options )
35- if span_streaming :
36- if sentry_sdk .traces .get_current_span () is None :
37- client_call_details = (
38- self ._update_client_call_details_metadata_from_scope (
39- client_call_details
40- )
41- )
42- return continuation (client_call_details , request )
43- with sentry_sdk .traces .start_span (
44- name = "unary unary call to %s" % method ,
45- attributes = {
46- "sentry.op" : OP .GRPC_CLIENT ,
47- "sentry.origin" : SPAN_ORIGIN ,
48- SPANDATA .RPC_METHOD : method ,
49- },
50- ) as span :
51- client_call_details = (
52- self ._update_client_call_details_metadata_from_scope (
53- client_call_details
54- )
55- )
56-
57- response = continuation (client_call_details , request )
58- span .set_attribute (
59- SPANDATA .RPC_RESPONSE_STATUS_CODE , response .code ().name
60- )
61-
62- return response
63- else :
64- with sentry_sdk .start_span (
65- op = OP .GRPC_CLIENT ,
66- name = "unary unary call to %s" % method ,
67- origin = SPAN_ORIGIN ,
68- ) as span :
69- span .set_data ("type" , "unary unary" )
70- span .set_data ("method" , method )
71-
72- client_call_details = (
73- self ._update_client_call_details_metadata_from_scope (
74- client_call_details
75- )
76- )
77-
78- response = continuation (client_call_details , request )
79- span .set_data ("code" , response .code ().name )
80-
81- return response
33+ if sentry_sdk .traces .get_current_span () is None :
34+ client_call_details = self ._update_client_call_details_metadata_from_scope (
35+ client_call_details
36+ )
37+ return continuation (client_call_details , request )
38+ with sentry_sdk .traces .start_span (
39+ name = "unary unary call to %s" % method ,
40+ attributes = {
41+ "sentry.op" : OP .GRPC_CLIENT ,
42+ "sentry.origin" : SPAN_ORIGIN ,
43+ SPANDATA .RPC_METHOD : method ,
44+ },
45+ ) as span :
46+ client_call_details = self ._update_client_call_details_metadata_from_scope (
47+ client_call_details
48+ )
49+
50+ response = continuation (client_call_details , request )
51+ span .set_attribute (SPANDATA .RPC_RESPONSE_STATUS_CODE , response .code ().name )
52+
53+ return response
8254
8355 def intercept_unary_stream (
8456 self : "ClientInterceptor" ,
@@ -88,55 +60,29 @@ def intercept_unary_stream(
8860 ) -> "Union[Iterator[Message], Call]" :
8961 method = client_call_details .method
9062
91- span_streaming = has_span_streaming_enabled (sentry_sdk .get_client ().options )
9263 response : "UnaryStreamCall"
93- if span_streaming :
94- if sentry_sdk .traces .get_current_span () is None :
95- client_call_details = (
96- self ._update_client_call_details_metadata_from_scope (
97- client_call_details
98- )
99- )
100- return continuation (client_call_details , request )
101- with sentry_sdk .traces .start_span (
102- name = "unary stream call to %s" % method ,
103- attributes = {
104- "sentry.op" : OP .GRPC_CLIENT ,
105- "sentry.origin" : SPAN_ORIGIN ,
106- SPANDATA .RPC_METHOD : method ,
107- },
108- ) as span :
109- client_call_details = (
110- self ._update_client_call_details_metadata_from_scope (
111- client_call_details
112- )
113- )
114-
115- response = continuation (client_call_details , request )
116- # Setting code on unary-stream leads to execution getting stuck
117- # span.set_data("code", response.code().name)
118-
119- return response
120- else :
121- with sentry_sdk .start_span (
122- op = OP .GRPC_CLIENT ,
123- name = "unary stream call to %s" % method ,
124- origin = SPAN_ORIGIN ,
125- ) as span :
126- span .set_data ("type" , "unary stream" )
127- span .set_data ("method" , method )
128-
129- client_call_details = (
130- self ._update_client_call_details_metadata_from_scope (
131- client_call_details
132- )
133- )
134-
135- response = continuation (client_call_details , request )
136- # Setting code on unary-stream leads to execution getting stuck
137- # span.set_data("code", response.code().name)
138-
139- return response
64+ if sentry_sdk .traces .get_current_span () is None :
65+ client_call_details = self ._update_client_call_details_metadata_from_scope (
66+ client_call_details
67+ )
68+ return continuation (client_call_details , request )
69+ with sentry_sdk .traces .start_span (
70+ name = "unary stream call to %s" % method ,
71+ attributes = {
72+ "sentry.op" : OP .GRPC_CLIENT ,
73+ "sentry.origin" : SPAN_ORIGIN ,
74+ SPANDATA .RPC_METHOD : method ,
75+ },
76+ ):
77+ client_call_details = self ._update_client_call_details_metadata_from_scope (
78+ client_call_details
79+ )
80+
81+ response = continuation (client_call_details , request )
82+ # Setting code on unary-stream leads to execution getting stuck
83+ # span.set_data("code", response.code().name)
84+
85+ return response
14086
14187 @staticmethod
14288 def _update_client_call_details_metadata_from_scope (
0 commit comments