A recursive function that creates the events of a trace
(slow, start_timestamp, timestamp, user, trace_id, parent_span_id, data)
| 502 | |
| 503 | |
| 504 | def create_trace(slow, start_timestamp, timestamp, user, trace_id, parent_span_id, data): |
| 505 | """A recursive function that creates the events of a trace""" |
| 506 | frontend = data.get("frontend") |
| 507 | mobile = data.get("mobile") |
| 508 | |
| 509 | current_span_id = uuid4().hex[:16] |
| 510 | spans = [] |
| 511 | new_start = start_timestamp + timedelta(milliseconds=random_normal(50, 25, 10)) |
| 512 | new_end = timestamp - timedelta(milliseconds=random_normal(50, 25, 10)) |
| 513 | |
| 514 | for child in data["children"]: |
| 515 | span_id = uuid4().hex[:16] |
| 516 | description = f"GET {child['transaction']}" |
| 517 | duration = random_normal((new_end - new_start).total_seconds(), 0.25, 0.01) |
| 518 | spans.append( |
| 519 | { |
| 520 | "same_process_as_parent": True, |
| 521 | "op": "http", |
| 522 | "description": description, |
| 523 | "data": { |
| 524 | "duration": duration, |
| 525 | "offset": 0.02, |
| 526 | }, |
| 527 | "span_id": span_id, |
| 528 | "trace_id": trace_id, |
| 529 | "hash": hash_values([description]), |
| 530 | # not the best but just set the exclusive time |
| 531 | # equal to the duration to get some span data |
| 532 | "exclusive_time": duration, |
| 533 | } |
| 534 | ) |
| 535 | create_trace( |
| 536 | slow, |
| 537 | start_timestamp + timedelta(milliseconds=random_normal(50, 25, 10)), |
| 538 | timestamp - timedelta(milliseconds=random_normal(50, 25, 10)), |
| 539 | user, |
| 540 | trace_id, |
| 541 | span_id, |
| 542 | child, |
| 543 | ) |
| 544 | |
| 545 | if frontend: |
| 546 | platform = "javascript" |
| 547 | elif mobile: |
| 548 | platform = "android" |
| 549 | else: |
| 550 | platform = "python" |
| 551 | |
| 552 | for _ in range(data.get("errors", 0)): |
| 553 | create_sample_event( |
| 554 | project=data["project"], |
| 555 | platform=platform, |
| 556 | user=user, |
| 557 | transaction=data["transaction"], |
| 558 | contexts={ |
| 559 | "trace": { |
| 560 | "type": "trace", |
| 561 | "trace_id": trace_id, |
no test coverage detected