1
1
from collections import deque
2
- from datetime import datetime
3
2
4
- from opentelemetry .trace import INVALID_SPAN , get_current_span , format_trace_id , format_span_id
3
+ from opentelemetry .trace import format_trace_id , format_span_id
5
4
from opentelemetry .context import Context
6
5
from opentelemetry .sdk .trace import Span , ReadableSpan , SpanProcessor
7
6
8
7
from sentry_sdk import capture_event
9
- from sentry_sdk .integrations .opentelemetry .utils import is_sentry_span , convert_otel_timestamp
10
- from sentry_sdk .integrations .opentelemetry .consts import OTEL_SENTRY_CONTEXT , SPAN_ORIGIN
8
+ from sentry_sdk .integrations .opentelemetry .utils import (
9
+ is_sentry_span ,
10
+ convert_otel_timestamp ,
11
+ )
12
+ from sentry_sdk .integrations .opentelemetry .consts import (
13
+ OTEL_SENTRY_CONTEXT ,
14
+ SPAN_ORIGIN ,
15
+ )
11
16
from sentry_sdk ._types import TYPE_CHECKING
12
17
13
18
if TYPE_CHECKING :
14
- from typing import Optional , List , Any
19
+ from typing import Optional , List , Any , Deque
15
20
from sentry_sdk ._types import Event
16
21
17
22
18
- class PotelSentrySpanProcessor (SpanProcessor ): # type: ignore
23
+ class PotelSentrySpanProcessor (SpanProcessor ):
19
24
"""
20
25
Converts OTel spans into Sentry spans so they can be sent to the Sentry backend.
21
26
"""
@@ -74,21 +79,22 @@ def _flush_root_span(self, span):
74
79
75
80
capture_event (transaction_event )
76
81
77
-
78
82
def _collect_children (self , span ):
79
83
# type: (ReadableSpan) -> List[ReadableSpan]
80
84
if not span .context :
81
85
return []
82
86
83
87
children = []
84
- bfs_queue = deque ()
88
+ bfs_queue = deque () # type: Deque[int]
85
89
bfs_queue .append (span .context .span_id )
86
90
87
91
while bfs_queue :
88
92
parent_span_id = bfs_queue .popleft ()
89
93
node_children = self ._children_spans .pop (parent_span_id , [])
90
94
children .extend (node_children )
91
- bfs_queue .extend ([child .context .span_id for child in node_children if child .context ])
95
+ bfs_queue .extend (
96
+ [child .context .span_id for child in node_children if child .context ]
97
+ )
92
98
93
99
return children
94
100
@@ -112,8 +118,8 @@ def _root_span_to_transaction_event(self, span):
112
118
"trace_id" : trace_id ,
113
119
"span_id" : span_id ,
114
120
"origin" : SPAN_ORIGIN ,
115
- "op" : span .name , # TODO
116
- "status" : "ok" , # TODO
121
+ "op" : span .name , # TODO
122
+ "status" : "ok" , # TODO
117
123
} # type: dict[str, Any]
118
124
119
125
if parent_span_id :
@@ -127,8 +133,8 @@ def _root_span_to_transaction_event(self, span):
127
133
128
134
event = {
129
135
"type" : "transaction" ,
130
- "transaction" : span .name , # TODO
131
- "transaction_info" : {"source" : "custom" }, # TODO
136
+ "transaction" : span .name , # TODO
137
+ "transaction_info" : {"source" : "custom" }, # TODO
132
138
"contexts" : contexts ,
133
139
"start_timestamp" : convert_otel_timestamp (span .start_time ),
134
140
"timestamp" : convert_otel_timestamp (span .end_time ),
@@ -153,9 +159,9 @@ def _span_to_json(self, span):
153
159
"trace_id" : trace_id ,
154
160
"span_id" : span_id ,
155
161
"origin" : SPAN_ORIGIN ,
156
- "op" : span .name , # TODO
157
- "description" : span .name , # TODO
158
- "status" : "ok" , # TODO
162
+ "op" : span .name , # TODO
163
+ "description" : span .name , # TODO
164
+ "status" : "ok" , # TODO
159
165
"start_timestamp" : convert_otel_timestamp (span .start_time ),
160
166
"timestamp" : convert_otel_timestamp (span .end_time ),
161
167
} # type: dict[str, Any]
0 commit comments