Skip to content

Commit 04667ce

Browse files
committed
.
1 parent 67c3cb1 commit 04667ce

2 files changed

Lines changed: 19 additions & 36 deletions

File tree

sentry_sdk/traces.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -649,17 +649,20 @@ def _set_segment_attributes(self) -> None:
649649

650650

651651
class NoOpStreamedSpan(StreamedSpan):
652-
def __init__(self, name: "Optional[str]" = None, scope: "Optional[sentry_sdk.Scope]" = None, **kwargs: "Any") -> None:
653-
self.name = name
654-
self.parent_span_id = None
655-
self.segment = None
656-
self._scope = scope
657-
self._context_manager_state = None
652+
__slots__ = (
653+
"name",
654+
"segment",
655+
"_scope",
656+
"_context_manager_state",
657+
)
658+
659+
def __init__(self, scope: "Optional[sentry_sdk.Scope]" = None, **kwargs: "Any") -> None:
660+
self.segment = None # type: ignore[assignment]
661+
self._scope = scope # type: ignore[assignment]
658662

659663
def __repr__(self) -> str:
660664
return (
661665
f"<{self.__class__.__name__}("
662-
f"name={self.name}, "
663666
f"sampled={self.sampled})>"
664667
)
665668

@@ -689,21 +692,21 @@ def __exit__(
689692
quantity=1,
690693
)
691694

692-
if self._context_manager_state is None:
695+
if self._scope is None:
693696
return
694697

695698
with capture_internal_exceptions():
696699
scope, old_span = self._context_manager_state
697700
del self._context_manager_state
698701
scope.span = old_span
699702

700-
def start(self) -> None:
703+
def start(self) -> "NoOpStreamedSpan":
701704
return self.__enter__()
702705

703-
def end(self) -> None:
706+
def end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None:
704707
self.__exit__(None, None, None)
705708

706-
def finish(self) -> None:
709+
def finish(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None:
707710
pass
708711

709712
def get_attributes(self) -> "Attributes":
@@ -712,7 +715,7 @@ def get_attributes(self) -> "Attributes":
712715
def set_attribute(self, key: str, value: "AttributeValue") -> None:
713716
pass
714717

715-
def set_attributes(self) -> None:
718+
def set_attributes(self, attributes: "Attributes") -> None:
716719
pass
717720

718721
def remove_attribute(self, key: str) -> None:
@@ -724,7 +727,7 @@ def set_name(self, name: str) -> None:
724727
def get_name(self) -> str:
725728
return ""
726729

727-
def set_flag(self) -> None:
730+
def set_flag(self, flag: str, result: bool) -> None:
728731
pass
729732

730733
def set_op(self, op: str) -> None:
@@ -751,21 +754,6 @@ def trace_id(self) -> str:
751754
def sampled(self) -> "Optional[bool]":
752755
return False
753756

754-
def dynamic_sampling_context(self) -> dict[str, str]:
755-
return {}
756-
757-
def get_baggage(self) -> "Baggage":
758-
return Baggage()
759-
760-
def to_baggage(self) -> "Optional[Baggage]":
761-
return None
762-
763-
def to_traceparent(self) -> str:
764-
return "0000-0000-0"
765-
766-
def iter_headers(self) -> "Iterator[tuple[str, str]]":
767-
return
768-
769757
def _set_segment_attributes(self) -> None:
770758
pass
771759

tests/tracing/test_span_streaming.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def test_start_span_no_context_manager(sentry_init, capture_envelopes):
9090
child = sentry_sdk.traces.start_span(name="child")
9191
child.start()
9292
assert child.segment == segment
93-
child.finish()
94-
segment.finish()
93+
child.end()
94+
segment.end()
9595

9696
sentry_sdk.get_client().flush()
9797
spans = envelopes_to_spans(events)
@@ -137,7 +137,7 @@ def traces_sampler(sampling_context):
137137
segment = sentry_sdk.traces.start_span(name="segment")
138138
segment.set_attribute("delayed_attribute", 12)
139139
segment.start()
140-
segment.finish()
140+
segment.end()
141141

142142
sentry_sdk.get_client().flush()
143143
spans = envelopes_to_spans(events)
@@ -1092,15 +1092,12 @@ def test_ignore_spans_set_ignored_child_span_as_parent(sentry_init, capture_enve
10921092

10931093
with sentry_sdk.traces.start_span(name="segment") as segment:
10941094
assert segment.sampled is True
1095-
assert segment.parent_span_id is None
10961095

10971096
with sentry_sdk.traces.start_span(name="ignored") as ignored_span1:
10981097
assert ignored_span1.sampled is False
1099-
assert ignored_span1.parent_span_id is None
11001098

11011099
with sentry_sdk.traces.start_span(name="ignored") as ignored_span2:
11021100
assert ignored_span2.sampled is False
1103-
assert ignored_span2.parent_span_id is None
11041101

11051102
with sentry_sdk.traces.start_span(name="child") as span:
11061103
assert span.sampled is True
@@ -1145,15 +1142,13 @@ def test_ignore_spans_set_ignored_child_span_as_parent_explicit_parent_span(
11451142
ignored_span1.start()
11461143
assert isinstance(ignored_span1, NoOpStreamedSpan)
11471144
assert ignored_span1.sampled is False
1148-
assert ignored_span1.parent_span_id is None
11491145

11501146
ignored_span2 = sentry_sdk.traces.start_span(
11511147
name="ignored", parent_span=ignored_span1
11521148
)
11531149
ignored_span2.start()
11541150
assert isinstance(ignored_span2, NoOpStreamedSpan)
11551151
assert ignored_span2.sampled is False
1156-
assert ignored_span2.parent_span_id is None
11571152

11581153
span = sentry_sdk.traces.start_span(name="child", parent_span=ignored_span2)
11591154
span.start()

0 commit comments

Comments
 (0)