@@ -95,7 +95,7 @@ def convert_from_otel_timestamp(time):
95
95
96
96
97
97
def convert_to_otel_timestamp (time ):
98
- # type: (Union[datetime.datetime , float]) -> int
98
+ # type: (Union[datetime, float]) -> int
99
99
"""Convert a datetime to an OTel timestamp (with nanosecond precision)."""
100
100
if isinstance (time , datetime ):
101
101
return int (time .timestamp () * 1e9 )
@@ -121,9 +121,12 @@ def extract_span_data(span):
121
121
if span .attributes is None :
122
122
return (op , description , status , http_status , origin )
123
123
124
- op = span .attributes .get (SentrySpanAttribute .OP ) or op
125
- description = span .attributes .get (SentrySpanAttribute .DESCRIPTION ) or description
126
- origin = span .attributes .get (SentrySpanAttribute .ORIGIN )
124
+ attribute_op = cast ("Optional[str]" , span .attributes .get (SentrySpanAttribute .OP ))
125
+ op = attribute_op or op
126
+ description = cast (
127
+ "str" , span .attributes .get (SentrySpanAttribute .DESCRIPTION ) or description
128
+ )
129
+ origin = cast ("Optional[str]" , span .attributes .get (SentrySpanAttribute .ORIGIN ))
127
130
128
131
http_method = span .attributes .get (SpanAttributes .HTTP_METHOD )
83CB
129
132
http_method = cast ("Optional[str]" , http_method )
@@ -137,7 +140,7 @@ def extract_span_data(span):
137
140
rpc_service = span .attributes .get (SpanAttributes .RPC_SERVICE )
138
141
if rpc_service :
139
142
return (
140
- span . attributes . get ( SentrySpanAttribute . OP ) or "rpc" ,
143
+ attribute_op or "rpc" ,
141
144
description ,
142
145
status ,
143
146
http_status ,
@@ -147,7 +150,7 @@ def extract_span_data(span):
147
150
messaging_system = span .attributes .get (SpanAttributes .MESSAGING_SYSTEM )
148
151
if messaging_system :
149
152
return (
150
- span . attributes . get ( SentrySpanAttribute . OP ) or "message" ,
153
+ attribute_op or "message" ,
151
154
description ,
152
155
status ,
153
156
http_status ,
@@ -165,7 +168,7 @@ def span_data_for_http_method(span):
165
168
# type: (ReadableSpan) -> OtelExtractedSpanData
166
169
span_attributes = span .attributes or {}
167
170
168
- op = span_attributes .get (SentrySpanAttribute .OP )
171
+ op = cast ( "Optional[str]" , span_attributes .get (SentrySpanAttribute .OP ) )
169
172
if op is None :
170
173
op = "http"
171
174
@@ -183,6 +186,7 @@ def span_data_for_http_method(span):
183
186
description = span_attributes .get (
184
187
SentrySpanAttribute .DESCRIPTION
185
188
) or span_attributes .get (SentrySpanAttribute .NAME )
189
+ description = cast ("Optional[str]" , description )
186
190
if description is None :
187
191
description = f"{ http_method } "
188
192
@@ -205,7 +209,7 @@ def span_data_for_http_method(span):
205
209
206
210
status , http_status = extract_span_status (span )
207
211
208
- origin = span_attributes .get (SentrySpanAttribute .ORIGIN )
212
+ origin = cast ( "Optional[str]" , span_attributes .get (SentrySpanAttribute .ORIGIN ) )
209
213
210
214
return (op , description , status , http_status , origin )
211
215
@@ -214,13 +218,13 @@ def span_data_for_db_query(span):
214
218
# type: (ReadableSpan) -> OtelExtractedSpanData
215
219
span_attributes = span .attributes or {}
216
220
217
- op = span_attributes .get (SentrySpanAttribute .OP , OP .DB )
221
+ op = cast ( "str" , span_attributes .get (SentrySpanAttribute .OP , OP .DB ) )
218
222
219
223
statement = span_attributes .get (SpanAttributes .DB_STATEMENT , None )
220
224
statement = cast ("Optional[str]" , statement )
221
225
222
226
description = statement or span .name
223
- origin = span_attributes .get (SentrySpanAttribute .ORIGIN )
227
+ origin = cast ( "Optional[str]" , span_attributes .get (SentrySpanAttribute .ORIGIN ) )
224
228
225
229
return (op , description , None , None , origin )
226
230
@@ -293,19 +297,20 @@ def extract_span_attributes(span, namespace):
293
297
"""
294
298
Extract Sentry-specific span attributes and make them look the way Sentry expects.
295
299
"""
296
- extracted_attrs = {}
300
+ extracted_attrs = {} # type: dict[str, Any]
297
301
298
302
for attr , value in (span .attributes or {}).items ():
299
303
if attr .startswith (namespace ):
300
304
key = attr [len (namespace ) + 1 :]
301
305
302
306
if namespace == SentrySpanAttribute .MEASUREMENT :
303
- value = {
307
+ value = cast ("tuple[str, str]" , value )
308
+ extracted_attrs [key ] = {
304
309
"value" : float (value [0 ]),
305
310
"unit" : value [1 ],
306
311
}
307
-
308
- extracted_attrs [key ] = value
312
+ else :
313
+ extracted_attrs [key ] = value
309
314
310
315
return extracted_attrs
311
316
@@ -457,7 +462,7 @@ def set_sentry_meta(span, key, value):
457
462
# type: (Union[AbstractSpan, ReadableSpan], str, Any) -> None
458
463
sentry_meta = getattr (span , "_sentry_meta" , {})
459
464
sentry_meta [key ] = value
460
- span ._sentry_meta = sentry_meta
465
+ span ._sentry_meta = sentry_meta # type: ignore[union-attr]
461
466
462
467
463
468
def get_profile_context (span ):
0 commit comments