Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a5d0f01

Browse filesBrowse files
authored
Introduce underscore span attributes (#4331)
Introduce the convention of underscore-prefixed span attributes. These won't be sent to Sentry and are meant for internal SDK usage. Changed `flag.count` to internal. Looked through the rest of the attrs we're setting and that stuff requires a big comprehensive cleanup altogether to make stuff align with OTel. Didn't touch anything else for now. Closes #4329
1 parent 5b6d37c commit a5d0f01
Copy full SHA for a5d0f01

File tree

Expand file treeCollapse file tree

5 files changed

+44
-9
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+44
-9
lines changed

‎sentry_sdk/opentelemetry/span_processor.py

Copy file name to clipboardExpand all lines: sentry_sdk/opentelemetry/span_processor.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,12 @@ def _span_to_json(self, span):
289289
if parent_span_id:
290290
span_json["parent_span_id"] = parent_span_id
291291

292-
if span.attributes:
293-
span_json["data"] = dict(span.attributes)
292+
attributes = getattr(span, "attributes", {}) or {}
293+
if attributes:
294+
span_json["data"] = {}
295+
for key, value in attributes.items():
296+
if not key.startswith("_"):
297+
span_json["data"][key] = value
294298

295299
return span_json
296300

‎sentry_sdk/tracing.py

Copy file name to clipboardExpand all lines: sentry_sdk/tracing.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,10 @@ def set_context(self, key, value):
588588

589589
def set_flag(self, flag, value):
590590
# type: (str, bool) -> None
591-
flag_count = self.get_attribute("flag.count") or 0
591+
flag_count = self.get_attribute("_flag.count") or 0
592592
if flag_count < _FLAGS_CAPACITY:
593593
self.set_attribute(f"flag.evaluation.{flag}", value)
594-
self.set_attribute("flag.count", flag_count + 1)
594+
self.set_attribute("_flag.count", flag_count + 1)
595595

596596

597597
# TODO-neel-potel add deprecation

‎tests/integrations/threading/test_threading.py

Copy file name to clipboardExpand all lines: tests/integrations/threading/test_threading.py
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import sentry_sdk
1010
from sentry_sdk import capture_message
1111
from sentry_sdk.integrations.threading import ThreadingIntegration
12-
from sentry_sdk.tracing import _OTEL_VERSION
1312

1413
original_start = Thread.start
1514
original_run = Thread.run
@@ -106,10 +105,7 @@ def double(number):
106105
assert len(event["spans"]) == 0
107106

108107

109-
@pytest.mark.skipif(
110-
sys.version[:3] == "3.8" and (1, 12) <= _OTEL_VERSION < (1, 16),
111-
reason="Fails in CI on 3.8 and specific OTel versions",
112-
)
108+
@pytest.mark.skipif(sys.version[:3] == "3.8", reason="Fails in CI on 3.8")
113109
def test_circular_references(sentry_init, request):
114110
sentry_init(default_integrations=False, integrations=[ThreadingIntegration()])
115111

+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sentry_sdk
2+
3+
4+
def test_span_processor_omits_underscore_attributes(sentry_init, capture_events):
5+
sentry_init(traces_sample_rate=1.0)
6+
7+
events = capture_events()
8+
9+
with sentry_sdk.start_span():
10+
with sentry_sdk.start_span() as span:
11+
span.set_attribute("_internal", 47)
12+
span.set_attribute("noninternal", 23)
13+
14+
assert span._otel_span.attributes["_internal"] == 47
15+
assert span._otel_span.attributes["noninternal"] == 23
16+
17+
outgoing_span = events[0]["spans"][0]
18+
assert "_internal" not in outgoing_span["data"]
19+
assert "noninternal" in outgoing_span["data"]

‎tests/test_feature_flags.py

Copy file name to clipboardExpand all lines: tests/test_feature_flags.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,19 @@ def test_flag_limit(sentry_init, capture_events):
259259
}
260260
)
261261
assert "flag.evaluation.10" not in event["spans"][0]["data"]
262+
263+
264+
def test_flag_counter_not_sent(sentry_init, capture_events):
265+
sentry_init(traces_sample_rate=1.0)
266+
267+
events = capture_events()
268+
269+
with start_transaction(name="hi"):
270+
with start_span(op="foo", name="bar"):
271+
add_feature_flag("0", True)
272+
add_feature_flag("1", True)
273+
add_feature_flag("2", True)
274+
add_feature_flag("3", True)
275+
276+
(event,) = events
277+
assert "_flag.count" not in event["spans"][0]["data"]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.