Skip to content

Commit 497d4a7

Browse files
committed
build(deps): bump codecov/codecov-action from 5.1.2 to 5.3.1 (#3995)
<!-- Describe your PR here --> --- Thank you for contributing to `sentry-python`! Please add tests to validate your changes, and lint your code using `tox -e linters`. Running the test suite on your PR might require maintainer approval. The AWS Lambda tests additionally require a maintainer to add a special label, and they will fail until this label is added.
1 parent 5a27502 commit 497d4a7

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

sentry_sdk/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,11 @@ def _prepare_event(
488488

489489
if scope is not None:
490490
is_transaction = event.get("type") == "transaction"
491-
spans_before = len(event.get("spans", []))
491+
spans = event.get("spans", [])
492+
from sentry_sdk.utils import AnnotatedValue
493+
if isinstance(spans, AnnotatedValue):
494+
spans = spans.value
495+
spans_before = len(spans)
492496
event_ = scope.apply_to_event(event, hint, self.options)
493497

494498
# one of the event/error processors returned None
@@ -508,7 +512,10 @@ def _prepare_event(
508512

509513
event = event_
510514

511-
spans_delta = spans_before - len(event.get("spans", []))
515+
spans = event.get("spans", [])
516+
if isinstance(spans, AnnotatedValue):
517+
spans = spans.value
518+
spans_delta = spans_before - len(spans)
512519
if is_transaction and spans_delta > 0 and self.transport is not None:
513520
self.transport.record_lost_event(
514521
"event_processor", data_category="span", quantity=spans_delta

sentry_sdk/serializer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ def _serialize_node_impl(
382382
serialized_event = _serialize_node(event, **kwargs)
383383
if not is_vars and meta_stack and isinstance(serialized_event, dict):
384384
serialized_event["_meta"] = meta_stack[0]
385+
print(serialized_event["_meta"])
385386

386387
return serialized_event
387388
finally:

sentry_sdk/tracing.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
is_valid_sample_rate,
1212
logger,
1313
nanosecond_time,
14+
AnnotatedValue
1415
)
1516

1617
from typing import TYPE_CHECKING
@@ -193,7 +194,7 @@ def get_span_status_from_http_code(http_status_code):
193194
class _SpanRecorder:
194195
"""Limits the number of spans recorded in a transaction."""
195196

196-
__slots__ = ("maxlen", "spans")
197+
__slots__ = ("maxlen", "spans", "dropped_spans")
197198

198199
def __init__(self, maxlen):
199200
# type: (int) -> None
@@ -203,15 +204,53 @@ def __init__(self, maxlen):
203204
# should be changed to match a consistent interpretation of what maxlen
204205
# limits: either transaction+spans or only child spans.
205206
self.maxlen = maxlen - 1
206-
self.spans = [] # type: List[Span]
207+
self.spans = [] # type: Union[List[Span], AnnotatedValue]
208+
self.dropped_spans = 0 # type: int
207209

208210
def add(self, span):
209211
# type: (Span) -> None
210212
if len(self.spans) > self.maxlen:
211213
span._span_recorder = None
214+
self.dropped_spans += 1
212215
else:
213216
self.spans.append(span)
214217

218+
219+
220+
221+
222+
223+
224+
# __slots__ = ("maxlen", "_spans")
225+
226+
# def __init__(self, maxlen):
227+
# # type: (int) -> None
228+
# # FIXME: this is `maxlen - 1` only to preserve historical behavior
229+
# # enforced by tests.
230+
# # Either this should be changed to `maxlen` or the JS SDK implementation
231+
# # should be changed to match a consistent interpretation of what maxlen
232+
# # limits: either transaction+spans or only child spans.
233+
# self.maxlen = maxlen - 1
234+
# self._spans = [] # type: Union[List[Span], AnnotatedValue]
235+
236+
# def add(self, span):
237+
# # type: (Span) -> None
238+
# if isinstance(self._spans, AnnotatedValue):
239+
# self._spans.metadata["len"] += 1
240+
# else:
241+
# if len(self._spans) > self.maxlen:
242+
# span._span_recorder = None
243+
# self._spans = AnnotatedValue(self._spans, {"len": self.maxlen}) # TODO!
244+
# else:
245+
# self._spans.append(span)
246+
247+
# @property
248+
# def spans(self):
249+
# # type: () -> List[Span]
250+
# if isinstance(self._spans, AnnotatedValue):
251+
# return self._spans.value
252+
# return self._spans
253+
215254

216255
class Span:
217256
"""A span holds timing information of a block of code.
@@ -972,6 +1011,10 @@ def finish(
9721011
if span.timestamp is not None
9731012
]
9741013

1014+
len_diff = len(self._span_recorder.spans) - len(finished_spans)
1015+
if len_diff or self._span_recorder.dropped_spans:
1016+
finished_spans = AnnotatedValue(finished_spans, {"len": len_diff + self._span_recorder.dropped_spans})
1017+
9751018
# we do this to break the circular reference of transaction -> span
9761019
# recorder -> span -> containing transaction (which is where we started)
9771020
# before either the spans or the transaction goes out of scope and has

0 commit comments

Comments
 (0)