Skip to content

Commit 0f5b059

Browse files
committed
merge
1 parent 6c7cf70 commit 0f5b059

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

sentry_sdk/_span_batcher.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
from typing import TYPE_CHECKING
55

66
from sentry_sdk._batcher import Batcher
7-
from sentry_sdk.consts import SPANSTATUS
87
from sentry_sdk.envelope import Envelope, Item, PayloadRef
9-
from sentry_sdk.utils import format_timestamp, serialize_attribute, safe_repr
8+
from sentry_sdk.utils import format_timestamp, serialize_attribute
109

1110
if TYPE_CHECKING:
1211
from typing import Any, Callable, Optional
13-
from sentry_sdk.traces import SpanStatus, StreamedSpan
14-
from sentry_sdk._types import SerializedAttributeValue
12+
from sentry_sdk.traces import StreamedSpan
1513

1614

1715
class SpanBatcher(Batcher["StreamedSpan"]):
@@ -88,9 +86,9 @@ def _to_transport_format(item: "StreamedSpan") -> "Any":
8886
elif item.parent_span_id:
8987
res["parent_span_id"] = item.parent_span_id
9088

91-
if item.attributes:
89+
if item._attributes:
9290
res["attributes"] = {
93-
k: serialize_attribute(v) for (k, v) in item.attributes.items()
91+
k: serialize_attribute(v) for (k, v) in item._attributes.items()
9492
}
9593

9694
return res
@@ -101,7 +99,7 @@ def _flush(self) -> None:
10199
return None
102100

103101
envelopes = []
104-
for trace_id, spans in self._span_buffer.items():
102+
for spans in self._span_buffer.values():
105103
if spans:
106104
dsc = spans[0].dynamic_sampling_context()
107105

sentry_sdk/scope.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
has_tracing_enabled,
3232
has_span_streaming_enabled,
3333
is_ignored_span,
34-
normalize_incoming_data,
3534
PropagationContext,
3635
)
3736
from sentry_sdk.traces import StreamedSpan
@@ -1683,7 +1682,7 @@ def _apply_scope_attributes_to_telemetry(
16831682
if isinstance(telemetry, dict):
16841683
attributes = telemetry["attributes"]
16851684
else:
1686-
attributes = telemetry.attributes
1685+
attributes = telemetry._attributes
16871686

16881687
for attribute, value in self._attributes.items():
16891688
if attribute not in attributes:
@@ -1695,7 +1694,7 @@ def _apply_user_attributes_to_telemetry(
16951694
if isinstance(telemetry, dict):
16961695
attributes = telemetry["attributes"]
16971696
else:
1698-
attributes = telemetry.attributes
1697+
attributes = telemetry._attributes
16991698

17001699
if not should_send_default_pii() or self._user is None:
17011700
return

sentry_sdk/traces.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class StreamedSpan:
204204

205205
__slots__ = (
206206
"name",
207-
"attributes",
207+
"_attributes",
208208
"_span_id",
209209
"_trace_id",
210210
"parent_span_id",
@@ -250,7 +250,7 @@ def __init__(
250250
self._scope = scope
251251

252252
self.name: str = name
253-
self.attributes: "Attributes" = attributes or {}
253+
self._attributes: "Attributes" = attributes or {}
254254

255255
self._trace_id = trace_id
256256
self.parent_span_id = parent_span_id
@@ -318,7 +318,7 @@ def __enter__(self) -> "StreamedSpan":
318318
"span_id": self.span_id,
319319
"parent_span_id": self.parent_span_id,
320320
"parent_sampled": self.parent_sampled,
321-
"attributes": self.attributes,
321+
"attributes": self._attributes,
322322
}
323323
custom_sampling_context = (
324324
scope.get_active_propagation_context()._custom_sampling_context
@@ -432,21 +432,21 @@ def _end(
432432
self._finished = True
433433

434434
def get_attributes(self) -> "Attributes":
435-
return self.attributes
435+
return self._attributes
436436

437437
def set_attribute(self, key: str, value: "AttributeValue") -> None:
438-
self.attributes[key] = format_attribute(value)
438+
self._attributes[key] = format_attribute(value)
439+
440+
def set_attributes(self, attributes: "Attributes") -> None:
441+
for key, value in attributes.items():
442+
self.set_attribute(key, value)
439443

440444
def remove_attribute(self, key: str) -> None:
441445
try:
442-
del self.attributes[key]
446+
del self._attributes[key]
443447
except KeyError:
444448
pass
445449

446-
def set_attributes(self, attributes: "Attributes") -> None:
447-
for key, value in attributes.items():
448-
self.set_attribute(key, value)
449-
450450
def set_status(self, status: "Union[SpanStatus, str]") -> None:
451451
if isinstance(status, Enum):
452452
status = status.value

0 commit comments

Comments
 (0)