|
3 | 3 | import copy
|
4 | 4 | import logging
|
5 | 5 | import sys
|
| 6 | +import typing |
6 | 7 | from collections.abc import Generator, Mapping, Sequence, Sized
|
7 | 8 | from types import FrameType
|
8 | 9 | from typing import TYPE_CHECKING, Any, NamedTuple
|
@@ -237,12 +238,15 @@ def before_send_transaction(event: Event, _: Hint) -> Event | None:
|
237 | 238 | num_of_spans = len(event["spans"])
|
238 | 239 |
|
239 | 240 | event["tags"]["spans_over_limit"] = str(num_of_spans >= 1000)
|
240 |
| - if not event["measurements"]: |
241 |
| - event["measurements"] = {} |
242 |
| - event["measurements"]["num_of_spans"] = { |
243 |
| - "value": num_of_spans, |
244 |
| - "unit": None, |
245 |
| - } |
| 241 | + |
| 242 | + # Type safety: `event["contexts"]["trace"]["data"]` is a dictionary if it is set. |
| 243 | + # See https://develop.sentry.dev/sdk/data-model/event-payloads/contexts/#trace-context. |
| 244 | + data = typing.cast( |
| 245 | + dict[str, object], |
| 246 | + event.setdefault("contexts", {}).setdefault("trace", {}).setdefault("data", {}), |
| 247 | + ) |
| 248 | + data["num_of_spans"] = num_of_spans |
| 249 | + |
246 | 250 | return event
|
247 | 251 |
|
248 | 252 |
|
@@ -695,15 +699,6 @@ def parse_org_slug(x: Organization | RpcOrganization | str) -> str:
|
695 | 699 | )
|
696 | 700 |
|
697 | 701 |
|
698 |
| -def set_measurement(measurement_name, value, unit=None): |
699 |
| - try: |
700 |
| - transaction = sentry_sdk.Scope.get_current_scope().transaction |
701 |
| - if transaction is not None: |
702 |
| - transaction.set_measurement(measurement_name, value, unit) |
703 |
| - except Exception: |
704 |
| - pass |
705 |
| - |
706 |
| - |
707 | 702 | def set_span_attribute(data_name, value):
|
708 | 703 | span = sentry_sdk.get_current_span()
|
709 | 704 | if span is not None:
|
@@ -746,6 +741,5 @@ def merge_context_into_scope(
|
746 | 741 | "patch_transport_for_instrumentation",
|
747 | 742 | "isolation_scope",
|
748 | 743 | "set_current_event_project",
|
749 |
| - "set_measurement", |
750 | 744 | "traces_sampler",
|
751 | 745 | )
|
0 commit comments