Skip to content

Commit 048acc9

Browse files
committed
working span processor
1 parent 5d04d3d commit 048acc9

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

sentry_sdk/integrations/opentelemetry/potel_span_processor.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ def _flush_root_span(self, span):
6464
if not transaction_event:
6565
return
6666

67-
children = self._collect_children(span)
68-
# TODO add converted spans
67+
spans = []
68+
for child in self._collect_children(span):
69+
span_json = self._span_to_json(child)
70+
if span_json:
71+
spans.append(span_json)
72+
transaction_event.setdefault("spans", []).extend(spans)
73+
# TODO-neel-potel sort and cutoff max spans
74+
6975
capture_event(transaction_event)
7076

7177

@@ -126,7 +132,37 @@ def _root_span_to_transaction_event(self, span):
126132
"contexts": contexts,
127133
"start_timestamp": convert_otel_timestamp(span.start_time),
128134
"timestamp": convert_otel_timestamp(span.end_time),
129-
"spans": [],
130135
} # type: Event
131136

132137
return event
138+
139+
def _span_to_json(self, span):
140+
# type: (ReadableSpan) -> Optional[dict[str, Any]]
141+
if not span.context:
142+
return None
143+
if not span.start_time:
144+
return None
145+
if not span.end_time:
146+
return None
147+
148+
trace_id = format_trace_id(span.context.trace_id)
149+
span_id = format_span_id(span.context.span_id)
150+
parent_span_id = format_span_id(span.parent.span_id) if span.parent else None
151+
152+
span_json = {
153+
"trace_id": trace_id,
154+
"span_id": span_id,
155+
"origin": SPAN_ORIGIN,
156+
"op": span.name, # TODO
157+
"description": span.name, # TODO
158+
"status": "ok", # TODO
159+
"start_timestamp": convert_otel_timestamp(span.start_time),
160+
"timestamp": convert_otel_timestamp(span.end_time),
161+
} # type: dict[str, Any]
162+
163+
if parent_span_id:
164+
span_json["parent_span_id"] = parent_span_id
165+
if span.attributes:
166+
span_json["data"] = dict(span.attributes)
167+
168+
return span_json

0 commit comments

Comments
 (0)