Skip to content

Commit 9fc0720

Browse files
chore(grpc): Remove transaction-based tracing (#7234)
Closes #7092
1 parent a7e8778 commit 9fc0720

4 files changed

Lines changed: 428 additions & 965 deletions

File tree

sentry_sdk/integrations/grpc/client.py

Lines changed: 43 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from sentry_sdk.consts import OP, SPANDATA
55
from sentry_sdk.integrations import DidNotEnable
66
from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN
7-
from sentry_sdk.tracing_utils import has_span_streaming_enabled
87

98
if 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(

sentry_sdk/integrations/grpc/server.py

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from sentry_sdk.integrations import DidNotEnable
66
from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN
77
from sentry_sdk.traces import SegmentNameSource
8-
from sentry_sdk.tracing import TransactionSource
9-
from sentry_sdk.tracing_utils import has_span_streaming_enabled
108

119
if TYPE_CHECKING:
1210
from typing import Callable, Optional
@@ -48,39 +46,22 @@ def behavior(request: "Message", context: "ServicerContext") -> "Message":
4846
if name:
4947
metadata = dict(context.invocation_metadata())
5048

51-
span_streaming = has_span_streaming_enabled(
52-
sentry_sdk.get_client().options
53-
)
54-
if span_streaming:
55-
sentry_sdk.traces.continue_trace(metadata)
49+
sentry_sdk.traces.continue_trace(metadata)
5650

57-
with sentry_sdk.traces.start_span(
58-
name=name,
59-
attributes={
60-
"sentry.op": OP.GRPC_SERVER,
61-
"sentry.segment.name.source": SegmentNameSource.CUSTOM.value,
62-
"sentry.origin": SPAN_ORIGIN,
63-
},
64-
parent_span=None,
65-
):
66-
try:
67-
return handler.unary_unary(request, context)
68-
except BaseException as e:
69-
raise e
70-
else:
71-
transaction = sentry_sdk.continue_trace(
72-
metadata,
73-
op=OP.GRPC_SERVER,
74-
name=name,
75-
source=TransactionSource.CUSTOM,
76-
origin=SPAN_ORIGIN,
77-
)
51+
with sentry_sdk.traces.start_span(
52+
name=name,
53+
attributes={
54+
"sentry.op": OP.GRPC_SERVER,
55+
"sentry.segment.name.source": SegmentNameSource.CUSTOM.value,
56+
"sentry.origin": SPAN_ORIGIN,
57+
},
58+
parent_span=None,
59+
):
60+
try:
61+
return handler.unary_unary(request, context)
62+
except BaseException as e:
63+
raise e
7864

79-
with sentry_sdk.start_transaction(transaction=transaction):
80-
try:
81-
return handler.unary_unary(request, context)
82-
except BaseException as e:
83-
raise e
8465
else:
8566
return handler.unary_unary(request, context)
8667

0 commit comments

Comments
 (0)