Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1806191

Browse files
author
Andrew Xue
committed
deep copy empty attributes
1 parent 64b3cf2 commit 1806191

File tree

1 file changed

+2
-6
lines changed
  • opentelemetry-sdk/src/opentelemetry/sdk/trace

1 file changed

+2
-6
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ class Span(trace_api.Span):
253253
"""
254254

255255
# Initialize these lazily assuming most spans won't have them.
256-
_empty_attributes = BoundedDict(MAX_NUM_ATTRIBUTES)
257256
_empty_events = BoundedList(MAX_NUM_EVENTS)
258257
_empty_links = BoundedList(MAX_NUM_LINKS)
259258

@@ -289,7 +288,7 @@ def __init__(
289288

290289
self._filter_attribute_values(attributes)
291290
if not attributes:
292-
self.attributes = Span._empty_attributes
291+
self.attributes = BoundedDict(MAX_NUM_ATTRIBUTES)
293292
else:
294293
self.attributes = BoundedDict.from_map(
295294
MAX_NUM_ATTRIBUTES, attributes
@@ -407,9 +406,6 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None:
407406
if not self.is_recording_events():
408407
return
409408
has_ended = self.end_time is not None
410-
if not has_ended:
411-
if self.attributes is Span._empty_attributes:
412-
self.attributes = BoundedDict(MAX_NUM_ATTRIBUTES)
413409
if has_ended:
414410
logger.warning("Setting attribute on ended span.")
415411
return
@@ -458,7 +454,7 @@ def add_event(
458454
) -> None:
459455
self._filter_attribute_values(attributes)
460456
if not attributes:
461-
attributes = Span._empty_attributes
457+
attributes = BoundedDict(MAX_NUM_ATTRIBUTES)
462458
self._add_event(
463459
Event(
464460
name=name,

0 commit comments

Comments
 (0)