7
7
from typing import List , Optional
8
8
from unittest .mock import Mock
9
9
10
- from sentry_sdk import start_span , start_transaction
10
+ from sentry_sdk import start_span
11
11
from sentry_sdk .consts import OP
12
12
from sentry_sdk .integrations .grpc import GRPCIntegration
13
13
from tests .conftest import ApproxDict
@@ -41,7 +41,7 @@ def _tear_down(server: grpc.Server):
41
41
42
42
43
43
@pytest .mark .forked
44
- def test_grpc_server_starts_transaction (sentry_init , capture_events_forksafe ):
44
+ def test_grpc_server_starts_root_span (sentry_init , capture_events_forksafe ):
45
45
sentry_init (traces_sample_rate = 1.0 , integrations = [GRPCIntegration ()])
46
46
events = capture_events_forksafe ()
47
47
@@ -99,7 +99,7 @@ def test_grpc_server_other_interceptors(sentry_init, capture_events_forksafe):
99
99
100
100
101
101
@pytest .mark .forked
102
- def test_grpc_server_continues_transaction (sentry_init , capture_events_forksafe ):
102
+ def test_grpc_server_continues_trace (sentry_init , capture_events_forksafe ):
103
103
sentry_init (traces_sample_rate = 1.0 , integrations = [GRPCIntegration ()])
104
104
events = capture_events_forksafe ()
105
105
@@ -108,20 +108,20 @@ def test_grpc_server_continues_transaction(sentry_init, capture_events_forksafe)
108
108
with grpc .insecure_channel ("localhost:{}" .format (PORT )) as channel :
109
109
stub = gRPCTestServiceStub (channel )
110
110
111
- with start_transaction () as transaction :
111
+ with start_span () as root_span :
112
112
metadata = (
113
113
(
114
114
"baggage" ,
115
115
"sentry-trace_id={trace_id},sentry-environment=test,"
116
116
"sentry-transaction=test-transaction,sentry-sample_rate=1.0" .format (
117
- trace_id = transaction .trace_id
117
+ trace_id = root_span .trace_id
118
118
),
119
119
),
120
120
(
121
121
"sentry-trace" ,
122
122
"{trace_id}-{parent_span_id}-{sampled}" .format (
123
- trace_id = transaction .trace_id ,
124
- parent_span_id = transaction .span_id ,
123
+ trace_id = root_span .trace_id ,
124
+ parent_span_id = root_span .span_id ,
125
125
sampled = 1 ,
126
126
),
127
127
),
@@ -139,7 +139,7 @@ def test_grpc_server_continues_transaction(sentry_init, capture_events_forksafe)
139
139
"source" : "custom" ,
140
140
}
141
141
assert event ["contexts" ]["trace" ]["op" ] == OP .GRPC_SERVER
142
- assert event ["contexts" ]["trace" ]["trace_id" ] == transaction .trace_id
142
+ assert event ["contexts" ]["trace" ]["trace_id" ] == root_span .trace_id
143
143
assert span ["op" ] == "test"
144
144
145
145
@@ -153,17 +153,17 @@ def test_grpc_client_starts_span(sentry_init, capture_events_forksafe):
153
153
with grpc .insecure_channel ("localhost:{}" .format (PORT )) as channel :
154
154
stub = gRPCTestServiceStub (channel )
155
155
156
- with start_transaction ():
156
+ with start_span ():
157
157
stub .TestServe (gRPCTestMessage (text = "test" ))
158
158
159
159
_tear_down (server = server )
160
160
161
161
events .write_file .close ()
162
162
events .read_event ()
163
- local_transaction = events .read_event ()
164
- span = local_transaction ["spans" ][0 ]
163
+ local_root_span = events .read_event ()
164
+ span = local_root_span ["spans" ][0 ]
165
165
166
- assert len (local_transaction ["spans" ]) == 1
166
+ assert len (local_root_span ["spans" ]) == 1
167
167
assert span ["op" ] == OP .GRPC_CLIENT
168
168
assert (
169
169
span ["description" ]
@@ -188,16 +188,16 @@ def test_grpc_client_unary_stream_starts_span(sentry_init, capture_events_forksa
188
188
with grpc .insecure_channel ("localhost:{}" .format (PORT )) as channel :
189
189
stub = gRPCTestServiceStub (channel )
190
190
191
- with start_transaction ():
191
+ with start_span ():
192
192
[el for el in stub .TestUnaryStream (gRPCTestMessage (text = "test" ))]
193
193
194
194
_tear_down (server = server )
195
195
196
196
events .write_file .close ()
197
- local_transaction = events .read_event ()
198
- span = local_transaction ["spans" ][0 ]
197
+ local_root_span = events .read_event ()
198
+ span = local_root_span ["spans" ][0 ]
199
199
200
- assert len (local_transaction ["spans" ]) == 1
200
+ assert len (local_root_span ["spans" ]) == 1
201
201
assert span ["op" ] == OP .GRPC_CLIENT
202
202
assert (
203
203
span ["description" ]
@@ -233,7 +233,7 @@ def test_grpc_client_other_interceptor(sentry_init, capture_events_forksafe):
233
233
channel = grpc .intercept_channel (channel , MockClientInterceptor ())
234
234
stub = gRPCTestServiceStub (channel )
235
235
236
- with start_transaction ():
236
+ with start_span ():
237
237
stub .TestServe (gRPCTestMessage (text = "test" ))
238
238
239
239
_tear_down (server = server )
@@ -242,10 +242,10 @@ def test_grpc_client_other_interceptor(sentry_init, capture_events_forksafe):
242
242
243
243
events .write_file .close ()
244
244
events .read_event ()
245
- local_transaction = events .read_event ()
246
- span = local_transaction ["spans" ][0 ]
245
+ local_root_span = events .read_event ()
246
+ span = local_root_span ["spans" ][0 ]
247
247
248
- assert len (local_transaction ["spans" ]) == 1
248
+ assert len (local_root_span ["spans" ]) == 1
249
249
assert span ["op" ] == OP .GRPC_CLIENT
250
250
assert (
251
251
span ["description" ]
@@ -272,18 +272,18 @@ def test_grpc_client_and_servers_interceptors_integration(
272
272
with grpc .insecure_channel ("localhost:{}" .format (PORT )) as channel :
273
273
stub = gRPCTestServiceStub (channel )
274
274
275
- with start_transaction ():
275
+ with start_span ():
276
276
stub .TestServe (gRPCTestMessage (text = "test" ))
277
277
278
278
_tear_down (server = server )
279
279
280
280
events .write_file .close ()
281
- server_transaction = events .read_event ()
282
- local_transaction = events .read_event ()
281
+ server_root_span = events .read_event ()
282
+ local_root_span = events .read_event ()
283
283
284
284
assert (
285
- server_transaction ["contexts" ]["trace" ]["trace_id" ]
286
- == local_transaction ["contexts" ]["trace" ]["trace_id" ]
285
+ server_root_span ["contexts" ]["trace" ]["trace_id" ]
286
+ == local_root_span ["contexts" ]["trace" ]["trace_id" ]
287
287
)
288
288
289
289
@@ -328,26 +328,23 @@ def test_span_origin(sentry_init, capture_events_forksafe):
328
328
with grpc .insecure_channel ("localhost:{}" .format (PORT )) as channel :
329
329
stub = gRPCTestServiceStub (channel )
330
330
331
- with start_transaction (name = "custom_transaction " ):
331
+ with start_span (name = "custom_root " ):
332
332
stub .TestServe (gRPCTestMessage (text = "test" ))
333
333
334
334
_tear_down (server = server )
335
335
336
336
events .write_file .close ()
337
337
338
- transaction_from_integration = events .read_event ()
339
- custom_transaction = events .read_event ()
338
+ root_span_from_integration = events .read_event ()
339
+ custom_root_span = events .read_event ()
340
340
341
+ assert root_span_from_integration ["contexts" ]["trace" ]["origin" ] == "auto.grpc.grpc"
341
342
assert (
342
- transaction_from_integration ["contexts" ]["trace" ]["origin" ] == "auto.grpc.grpc"
343
- )
344
- assert (
345
- transaction_from_integration ["spans" ][0 ]["origin" ]
346
- == "auto.grpc.grpc.TestService"
343
+ root_span_from_integration ["spans" ][0 ]["origin" ] == "auto.grpc.grpc.TestService"
347
344
) # manually created in TestService, not the instrumentation
348
345
349
- assert custom_transaction ["contexts" ]["trace" ]["origin" ] == "manual"
350
- assert custom_transaction ["spans" ][0 ]["origin" ] == "auto.grpc.grpc"
346
+ assert custom_root_span ["contexts" ]["trace" ]["origin" ] == "manual"
347
+ assert custom_root_span ["spans" ][0 ]["origin" ] == "auto.grpc.grpc"
351
348
352
349
353
350
class TestService (gRPCTestServiceServicer ):
0 commit comments