@@ -981,21 +981,16 @@ class TestGetProfileFromTraceTree(APITestCase, SnubaTestCase):
981
981
def test_get_profile_from_trace_tree (self , mock_get_from_profiling_service ) -> None :
982
982
"""
983
983
Test the _get_profile_from_trace_tree method which finds a transaction
984
- that contains the event's span_id or has a matching span_id .
984
+ that matches the event's transaction name and has a profile .
985
985
"""
986
- # Setup mock event with span_id
986
+ # Setup mock event with transaction name
987
987
event = Mock ()
988
988
event .event_id = "error-event-id"
989
989
event .trace_id = "1234567890abcdef1234567890abcdef"
990
- event .data = {
991
- "contexts" : {
992
- "trace" : {
993
- "span_id" : "event-span-id" ,
994
- }
995
- }
996
- }
990
+ event .transaction = "/api/users"
991
+ event .data = {"transaction" : "/api/users" }
997
992
998
- # Create a mock trace tree with a transaction that includes the event span_id in its span_ids
993
+ # Create a mock trace tree with a transaction that matches the event's transaction name
999
994
profile_id = "profile123456789"
1000
995
trace_tree = {
1001
996
"trace_id" : "1234567890abcdef1234567890abcdef" ,
@@ -1005,8 +1000,8 @@ def test_get_profile_from_trace_tree(self, mock_get_from_profiling_service) -> N
1005
1000
"span_id" : "root-span-id" ,
1006
1001
"is_transaction" : True ,
1007
1002
"is_error" : False ,
1003
+ "transaction" : "/api/users" ,
1008
1004
"profile_id" : profile_id ,
1009
- "span_ids" : ["some-span" , "event-span-id" , "another-span" ],
1010
1005
"children" : [
1011
1006
{
1012
1007
"event_id" : "error-event-id" ,
@@ -1060,35 +1055,31 @@ def test_get_profile_from_trace_tree(self, mock_get_from_profiling_service) -> N
1060
1055
)
1061
1056
1062
1057
@patch ("sentry.seer.explorer.utils.get_from_profiling_service" )
1063
- def test_get_profile_from_trace_tree_matching_span_id (
1058
+ def test_get_profile_from_trace_tree_matching_transaction_name (
1064
1059
self , mock_get_from_profiling_service
1065
1060
) -> None :
1066
1061
"""
1067
- Test _get_profile_from_trace_tree with a transaction whose own span_id
1068
- matches the event's span_id .
1062
+ Test _get_profile_from_trace_tree with a transaction whose name
1063
+ matches the event's transaction name .
1069
1064
"""
1070
- # Setup mock event with span_id
1065
+ # Setup mock event with transaction name
1071
1066
event = Mock ()
1072
1067
event .event_id = "error-event-id"
1073
1068
event .trace_id = "1234567890abcdef1234567890abcdef"
1074
- event .data = {
1075
- "contexts" : {
1076
- "trace" : {
1077
- "span_id" : "tx-span-id" ,
1078
- }
1079
- }
1080
- }
1069
+ event .transaction = "/api/orders"
1070
+ event .data = {"transaction" : "/api/orders" }
1081
1071
1082
- # Create a mock trace tree with a transaction whose span_id matches event span_id
1072
+ # Create a mock trace tree with a transaction whose name matches event transaction name
1083
1073
profile_id = "profile123456789"
1084
1074
trace_tree = {
1085
1075
"trace_id" : "1234567890abcdef1234567890abcdef" ,
1086
1076
"events" : [
1087
1077
{
1088
1078
"event_id" : "tx-id" ,
1089
- "span_id" : "tx-span-id" , # This matches the event's span_id
1079
+ "span_id" : "tx-span-id" ,
1090
1080
"is_transaction" : True ,
1091
1081
"is_error" : False ,
1082
+ "transaction" : "/api/orders" , # This matches the event's transaction name
1092
1083
"profile_id" : profile_id ,
1093
1084
"children" : [
1094
1085
{
@@ -1149,11 +1140,13 @@ def test_get_profile_from_trace_tree_continuous_e2e(
1149
1140
End-to-end: build a trace tree from span query results where the transaction has only
1150
1141
profiler.id (continuous profile). Then verify we fetch a continuous profile and return an execution tree.
1151
1142
"""
1152
- # Base error event whose span_id should be found within the transaction's spans
1143
+ # Base error event whose transaction name should match the transaction in the trace
1153
1144
trace_id = "1234567890abcdef1234567890abcdef"
1154
1145
error_span_id = "bbbbbbbbbbbbbbbb" # 16-hex span id
1155
1146
tx_span_id = "aaaaaaaaaaaaaaaa" # 16-hex transaction span id
1156
1147
data = load_data ("python" )
1148
+ # Set transaction to match what we'll have in the trace tree
1149
+ data ["transaction" ] = "/api/test"
1157
1150
data .update ({"contexts" : {"trace" : {"trace_id" : trace_id , "span_id" : error_span_id }}})
1158
1151
event = self .store_event (data = data , project_id = self .project .id )
1159
1152
@@ -1172,7 +1165,7 @@ def test_get_profile_from_trace_tree_continuous_e2e(
1172
1165
"precise.start_ts" : tx_start ,
1173
1166
"precise.finish_ts" : tx_end ,
1174
1167
"is_transaction" : True ,
1175
- "transaction" : "Root " ,
1168
+ "transaction" : "/api/test " ,
1176
1169
"project.id" : self .project .id ,
1177
1170
"platform" : "python" ,
1178
1171
"profile.id" : None ,
@@ -1267,19 +1260,14 @@ def test_get_profile_from_trace_tree_api_error(self, mock_get_from_profiling_ser
1267
1260
"""
1268
1261
Test the behavior when the profiling service API returns an error.
1269
1262
"""
1270
- # Setup mock event with span_id
1263
+ # Setup mock event with transaction name
1271
1264
event = Mock ()
1272
1265
event .event_id = "error-event-id"
1273
1266
event .trace_id = "1234567890abcdef1234567890abcdef"
1274
- event .data = {
1275
- "contexts" : {
1276
- "trace" : {
1277
- "span_id" : "event-span-id" ,
1278
- }
1279
- }
1280
- }
1267
+ event .transaction = "/api/test"
1268
+ event .data = {"transaction" : "/api/test" }
1281
1269
1282
- # Create a mock trace tree with a transaction that includes the event span_id
1270
+ # Create a mock trace tree with a transaction that matches the event transaction name
1283
1271
profile_id = "profile123456789"
1284
1272
trace_tree = {
1285
1273
"trace_id" : "1234567890abcdef1234567890abcdef" ,
@@ -1289,8 +1277,8 @@ def test_get_profile_from_trace_tree_api_error(self, mock_get_from_profiling_ser
1289
1277
"span_id" : "root-span-id" ,
1290
1278
"is_transaction" : True ,
1291
1279
"is_error" : False ,
1280
+ "transaction" : "/api/test" ,
1292
1281
"profile_id" : profile_id ,
1293
- "span_ids" : ["event-span-id" ],
1294
1282
"children" : [
1295
1283
{
1296
1284
"event_id" : "error-event-id" ,
@@ -1327,19 +1315,14 @@ def test_get_profile_from_trace_tree_no_matching_transaction(
1327
1315
"""
1328
1316
Test that the function returns None when no matching transaction is found.
1329
1317
"""
1330
- # Setup mock event with span_id
1318
+ # Setup mock event with transaction name
1331
1319
event = Mock ()
1332
1320
event .event_id = "error-event-id"
1333
1321
event .trace_id = "1234567890abcdef1234567890abcdef"
1334
- event .data = {
1335
- "contexts" : {
1336
- "trace" : {
1337
- "span_id" : "event-span-id" ,
1338
- }
1339
- }
1340
- }
1322
+ event .transaction = "/api/different"
1323
+ event .data = {"transaction" : "/api/different" }
1341
1324
1342
- # Create a mock trace tree with a transaction that DOESN'T include the event span_id
1325
+ # Create a mock trace tree with a transaction that DOESN'T match the event transaction name
1343
1326
trace_tree = {
1344
1327
"trace_id" : "1234567890abcdef1234567890abcdef" ,
1345
1328
"events" : [
@@ -1348,8 +1331,8 @@ def test_get_profile_from_trace_tree_no_matching_transaction(
1348
1331
"span_id" : "root-span-id" ,
1349
1332
"is_transaction" : True ,
1350
1333
"is_error" : False ,
1334
+ "transaction" : "/api/other" , # Doesn't match event's transaction name
1351
1335
"profile_id" : "profile123456789" ,
1352
- "span_ids" : ["different-span-id" ], # Doesn't include event's span_id
1353
1336
"children" : [
1354
1337
{
1355
1338
"event_id" : "error-event-id" ,
@@ -1371,15 +1354,18 @@ def test_get_profile_from_trace_tree_no_matching_transaction(
1371
1354
mock_get_from_profiling_service .assert_not_called ()
1372
1355
1373
1356
@patch ("sentry.seer.explorer.utils.get_from_profiling_service" )
1374
- def test_get_profile_from_trace_tree_no_span_id (self , mock_get_from_profiling_service ) -> None :
1357
+ def test_get_profile_from_trace_tree_no_transaction_name (
1358
+ self , mock_get_from_profiling_service
1359
+ ) -> None :
1375
1360
"""
1376
- Test the behavior when the event doesn't have a span_id .
1361
+ Test the behavior when the event doesn't have a transaction name .
1377
1362
"""
1378
- # Setup mock event WITHOUT span_id
1363
+ # Setup mock event WITHOUT transaction name
1379
1364
event = Mock ()
1380
1365
event .event_id = "error-event-id"
1381
1366
event .trace_id = "1234567890abcdef1234567890abcdef"
1382
- event .data = {"contexts" : {"trace" : {}}} # No span_id
1367
+ event .transaction = None
1368
+ event .data = {} # No transaction
1383
1369
1384
1370
# Create a mock trace tree
1385
1371
trace_tree = {
@@ -1390,6 +1376,7 @@ def test_get_profile_from_trace_tree_no_span_id(self, mock_get_from_profiling_se
1390
1376
"span_id" : "tx-span-id" ,
1391
1377
"is_transaction" : True ,
1392
1378
"is_error" : False ,
1379
+ "transaction" : "/api/test" ,
1393
1380
"profile_id" : "profile123456789" ,
1394
1381
"children" : [],
1395
1382
}
@@ -1400,7 +1387,7 @@ def test_get_profile_from_trace_tree_no_span_id(self, mock_get_from_profiling_se
1400
1387
profile_result = _get_profile_from_trace_tree (trace_tree , event , self .project )
1401
1388
1402
1389
assert profile_result is None
1403
- # API should not be called if event has no span_id
1390
+ # API should not be called if event has no transaction name
1404
1391
mock_get_from_profiling_service .assert_not_called ()
1405
1392
1406
1393
0 commit comments