Skip to content

Commit 144d976

Browse files
sl0thentr0pyszokeasaurusrex
authored andcommitted
Proxy POTelSpan.set_data to underlying otel span attributes (#3297)
1 parent 78cd8e1 commit 144d976

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

sentry_sdk/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ def set_tag(self, key, value):
13481348

13491349
def set_data(self, key, value):
13501350
# type: (str, Any) -> None
1351-
pass
1351+
self._otel_span.set_attribute(key, value)
13521352

13531353
def set_status(self, status):
13541354
# type: (str) -> None

tests/integrations/opentelemetry/test_potel.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,45 @@ def test_children_span_nesting_mixed(capture_envelopes):
208208
assert db_span["parent_span_id"] == payload["contexts"]["trace"]["span_id"]
209209
assert http_span["parent_span_id"] == payload["contexts"]["trace"]["span_id"]
210210
assert redis_span["parent_span_id"] == db_span["span_id"]
211+
212+
213+
def test_span_attributes_in_data_started_with_otel(capture_envelopes):
214+
envelopes = capture_envelopes()
215+
216+
with tracer.start_as_current_span("request") as request_span:
217+
request_span.set_attributes({"foo": "bar", "baz": 42})
218+
with tracer.start_as_current_span("db") as db_span:
219+
db_span.set_attributes({"abc": 99, "def": "moo"})
220+
221+
(envelope,) = envelopes
222+
(item,) = envelope.items
223+
payload = item.payload.json
224+
225+
assert payload["contexts"]["trace"]["data"] == {"foo": "bar", "baz": 42}
226+
assert payload["spans"][0]["data"] == {"abc": 99, "def": "moo"}
227+
228+
229+
def test_span_data_started_with_sentry(capture_envelopes):
230+
envelopes = capture_envelopes()
231+
232+
with sentry_sdk.start_span(op="http", description="request") as request_span:
233+
request_span.set_data("foo", "bar")
234+
with sentry_sdk.start_span(op="db", description="statement") as db_span:
235+
db_span.set_data("baz", 42)
236+
237+
(envelope,) = envelopes
238+
(item,) = envelope.items
239+
payload = item.payload.json
240+
241+
assert payload["contexts"]["trace"]["data"] == {
242+
"foo": "bar",
243+
"sentry.origin": "manual",
244+
"sentry.description": "request",
245+
"sentry.op": "http",
246+
}
247+
assert payload["spans"][0]["data"] == {
248+
"baz": 42,
249+
"sentry.origin": "manual",
250+
"sentry.description": "statement",
251+
"sentry.op": "db",
252+
}

0 commit comments

Comments
 (0)