Skip to content

Commit edaf05d

Browse files
committed
dsc
1 parent 2fa3338 commit edaf05d

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

sentry_sdk/_span_batcher.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,35 @@ def _flush(self):
162162
return None
163163

164164
for trace_id, spans in self._span_buffer.items():
165-
envelope = Envelope(
166-
headers={
167-
"sent_at": format_timestamp(datetime.now(timezone.utc)),
168-
}
169-
# TODO[span-first] more headers
170-
)
165+
if spans:
166+
trace_context = spans[0].get_trace_context()
167+
dsc = trace_context.get("dynamic_sampling_context")
168+
# XXX[span-first]: empty dsc?
171169

172-
envelope.add_item(
173-
Item(
174-
type="span",
175-
content_type="application/vnd.sentry.items.span.v2+json",
170+
envelope = Envelope(
176171
headers={
177-
"item_count": len(spans),
178-
},
179-
payload=PayloadRef(
180-
json={
181-
"items": [
182-
self._span_to_transport_format(span)
183-
for span in spans
184-
]
185-
}
186-
),
172+
"sent_at": format_timestamp(datetime.now(timezone.utc)),
173+
"trace": dsc,
174+
}
175+
)
176+
177+
envelope.add_item(
178+
Item(
179+
type="span",
180+
content_type="application/vnd.sentry.items.span.v2+json",
181+
headers={
182+
"item_count": len(spans),
183+
},
184+
payload=PayloadRef(
185+
json={
186+
"items": [
187+
self._span_to_transport_format(span)
188+
for span in spans
189+
]
190+
}
191+
),
192+
)
187193
)
188-
)
189194

190195
self._span_buffer.clear()
191196

sentry_sdk/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,10 +947,15 @@ def _capture_span(self, span):
947947
attributes = get_default_attributes()
948948
span._attributes = attributes | span._attributes
949949

950-
span._attributes["sentry.segment.id"] = span.containing_transaction.span_id
951-
span._attributes["sentry.segment.name"] = span.containing_transaction.name
950+
segment = span.containing_transaction
951+
span._attributes["sentry.segment.id"] = segment.span_id
952+
span._attributes["sentry.segment.name"] = segment.name
952953

953-
self._span_batcher.add(span)
954+
if self._span_batcher:
955+
logger.debug(
956+
f"[Tracing] Adding span {span.span_id} of segment {segment.span_id} to batcher"
957+
)
958+
self._span_batcher.add(span)
954959

955960
def _capture_log(self, log):
956961
# type: (Optional[Log]) -> None

sentry_sdk/tracing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,6 @@ def finish(self, scope=None, end_timestamp=None):
742742
has_span_streaming_enabled(client.options)
743743
and self.containing_transaction.sampled
744744
):
745-
logger.debug(f"[Tracing] Adding span {self.span_id} to buffer")
746745
client._capture_span(self)
747746

748747
return None
@@ -1113,7 +1112,6 @@ def finish(
11131112

11141113
if self._mode == "stream":
11151114
if self.containing_transaction.sampled:
1116-
logger.debug(f"[Tracing] Adding span {self.span_id} to batcher")
11171115
client._capture_span(self)
11181116
return
11191117

sentry_sdk/transport.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,10 @@ def _send_envelope(self, envelope):
478478
print("Headers")
479479
print(item.headers)
480480
print("Attributes")
481-
for i in item.payload.json["items"]:
482-
for attribute, value in i["attributes"].items():
483-
print(attribute, value)
481+
if item.payload.json.get("items"):
482+
for i in item.payload.json["items"]:
483+
for attribute, value in i["attributes"].items():
484+
print(attribute, value)
484485
print("Payload")
485486
print(item.payload.json)
486487
print()

0 commit comments

Comments
 (0)