|
1 |
| -from sentry.spans.consumers.process_segments.enrichment import set_exclusive_time |
| 1 | +from sentry.spans.consumers.process_segments.enrichment import ( |
| 2 | + compute_breakdowns, |
| 3 | + set_exclusive_time, |
| 4 | +) |
| 5 | +from sentry.testutils.pytest.fixtures import django_db_all |
2 | 6 | from tests.sentry.spans.consumers.process import build_mock_span
|
3 | 7 |
|
4 | 8 | # Tests ported from Relay
|
@@ -303,3 +307,78 @@ def test_only_immediate_child_spans_affect_calculation():
|
303 | 307 | "cccccccccccccccc": 400.0,
|
304 | 308 | "dddddddddddddddd": 400.0,
|
305 | 309 | }
|
| 310 | + |
| 311 | + |
| 312 | +@django_db_all |
| 313 | +def test_emit_ops_breakdown(default_project): |
| 314 | + segment_span = build_mock_span( |
| 315 | + project_id=1, |
| 316 | + is_segment=True, |
| 317 | + start_timestamp_precise=1577836800.0, |
| 318 | + end_timestamp_precise=1577858400.01, |
| 319 | + span_id="ffffffffffffffff", |
| 320 | + ) |
| 321 | + |
| 322 | + spans = [ |
| 323 | + build_mock_span( |
| 324 | + project_id=1, |
| 325 | + start_timestamp_precise=1577836800.0, # 2020-01-01 00:00:00 |
| 326 | + end_timestamp_precise=1577840400.0, # 2020-01-01 01:00:00 |
| 327 | + span_id="fa90fdead5f74052", |
| 328 | + parent_span_id=segment_span["span_id"], |
| 329 | + span_op="http", |
| 330 | + ), |
| 331 | + build_mock_span( |
| 332 | + project_id=1, |
| 333 | + start_timestamp_precise=1577844000.0, # 2020-01-01 02:00:00 |
| 334 | + end_timestamp_precise=1577847600.0, # 2020-01-01 03:00:00 |
| 335 | + span_id="bbbbbbbbbbbbbbbb", |
| 336 | + parent_span_id=segment_span["span_id"], |
| 337 | + span_op="db", |
| 338 | + ), |
| 339 | + build_mock_span( |
| 340 | + project_id=1, |
| 341 | + start_timestamp_precise=1577845800.0, # 2020-01-01 02:30:00 |
| 342 | + end_timestamp_precise=1577849400.0, # 2020-01-01 03:30:00 |
| 343 | + span_id="cccccccccccccccc", |
| 344 | + parent_span_id=segment_span["span_id"], |
| 345 | + span_op="db.postgres", |
| 346 | + ), |
| 347 | + build_mock_span( |
| 348 | + project_id=1, |
| 349 | + start_timestamp_precise=1577851200.0, # 2020-01-01 04:00:00 |
| 350 | + end_timestamp_precise=1577853000.0, # 2020-01-01 04:30:00 |
| 351 | + span_id="dddddddddddddddd", |
| 352 | + parent_span_id=segment_span["span_id"], |
| 353 | + span_op="db.mongo", |
| 354 | + ), |
| 355 | + build_mock_span( |
| 356 | + project_id=1, |
| 357 | + start_timestamp_precise=1577854800.0, # 2020-01-01 05:00:00 |
| 358 | + end_timestamp_precise=1577858400.01, # 2020-01-01 06:00:00.01 |
| 359 | + span_id="eeeeeeeeeeeeeeee", |
| 360 | + parent_span_id=segment_span["span_id"], |
| 361 | + span_op="browser", |
| 362 | + ), |
| 363 | + segment_span, |
| 364 | + ] |
| 365 | + |
| 366 | + breakdowns_config = { |
| 367 | + "span_ops": {"type": "spanOperations", "matches": ["http", "db"]}, |
| 368 | + "span_ops_2": {"type": "spanOperations", "matches": ["http", "db"]}, |
| 369 | + } |
| 370 | + default_project.update_option("sentry:breakdowns", breakdowns_config) |
| 371 | + |
| 372 | + # Compute breakdowns for the segment span |
| 373 | + compute_breakdowns(segment_span, spans, default_project) |
| 374 | + measurements = segment_span["measurements"] |
| 375 | + |
| 376 | + assert measurements["span_ops.ops.http"]["value"] == 3600000.0 |
| 377 | + assert measurements["span_ops.ops.db"]["value"] == 7200000.0 |
| 378 | + assert measurements["span_ops_2.ops.http"]["value"] == 3600000.0 |
| 379 | + assert measurements["span_ops_2.ops.db"]["value"] == 7200000.0 |
| 380 | + |
| 381 | + # NOTE: Relay used to extract a total.time breakdown, which is no longer |
| 382 | + # included in span breakdowns. |
| 383 | + # assert measurements["span_ops.total.time"]["value"] == 14400000.01 |
| 384 | + # assert measurements["span_ops_2.total.time"]["value"] == 14400000.01 |
0 commit comments