@@ -95,7 +95,7 @@ def convert_from_otel_timestamp(time):
9595
9696
9797def convert_to_otel_timestamp (time ):
98- # type: (Union[datetime.datetime , float]) -> int
98+ # type: (Union[datetime, float]) -> int
9999 """Convert a datetime to an OTel timestamp (with nanosecond precision)."""
100100 if isinstance (time , datetime ):
101101 return int (time .timestamp () * 1e9 )
@@ -121,9 +121,11 @@ def extract_span_data(span):
121121 if span .attributes is None :
122122 return (op , description , status , http_status , origin )
123123
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+ op = cast ("str" , span .attributes .get (SentrySpanAttribute .OP ) or op )
125+ description = cast (
126+ "str" , span .attributes .get (SentrySpanAttribute .DESCRIPTION ) or description
127+ )
128+ origin = cast ("Optional[str]" , span .attributes .get (SentrySpanAttribute .ORIGIN ))
127129
128130 http_method = span .attributes .get (SpanAttributes .HTTP_METHOD )
129131 http_method = cast ("Optional[str]" , http_method )
@@ -137,7 +139,7 @@ def extract_span_data(span):
137139 rpc_service = span .attributes .get (SpanAttributes .RPC_SERVICE )
138140 if rpc_service :
139141 return (
140- span . attributes . get ( SentrySpanAttribute . OP ) or "rpc" ,
142+ op or "rpc" ,
141143 description ,
142144 status ,
143145 http_status ,
@@ -147,7 +149,7 @@ def extract_span_data(span):
147149 messaging_system = span .attributes .get (SpanAttributes .MESSAGING_SYSTEM )
148150 if messaging_system :
149151 return (
150- span . attributes . get ( SentrySpanAttribute . OP ) or "message" ,
152+ op or "message" ,
151153 description ,
152154 status ,
153155 http_status ,
@@ -165,7 +167,7 @@ def span_data_for_http_method(span):
165167 # type: (ReadableSpan) -> OtelExtractedSpanData
166168 span_attributes = span .attributes or {}
167169
168- op = span_attributes .get (SentrySpanAttribute .OP )
170+ op = cast ( "Optional[str]" , span_attributes .get (SentrySpanAttribute .OP ) )
169171 if op is None :
170172 op = "http"
171173
@@ -183,6 +185,7 @@ def span_data_for_http_method(span):
183185 description = span_attributes .get (
184186 SentrySpanAttribute .DESCRIPTION
185187 ) or span_attributes .get (SentrySpanAttribute .NAME )
188+ description = cast ("Optional[str]" , description )
186189 if description is None :
187190 description = f"{ http_method } "
188191
@@ -205,7 +208,7 @@ def span_data_for_http_method(span):
205208
206209 status , http_status = extract_span_status (span )
207210
208- origin = span_attributes .get (SentrySpanAttribute .ORIGIN )
211+ origin = cast ( "Optional[str]" , span_attributes .get (SentrySpanAttribute .ORIGIN ) )
209212
210213 return (op , description , status , http_status , origin )
211214
@@ -214,13 +217,13 @@ def span_data_for_db_query(span):
214217 # type: (ReadableSpan) -> OtelExtractedSpanData
215218 span_attributes = span .attributes or {}
216219
217- op = span_attributes .get (SentrySpanAttribute .OP , OP .DB )
220+ op = cast ( "str" , span_attributes .get (SentrySpanAttribute .OP , OP .DB ) )
218221
219222 statement = span_attributes .get (SpanAttributes .DB_STATEMENT , None )
220223 statement = cast ("Optional[str]" , statement )
221224
222225 description = statement or span .name
223- origin = span_attributes .get (SentrySpanAttribute .ORIGIN )
226+ origin = cast ( "Optional[str]" , span_attributes .get (SentrySpanAttribute .ORIGIN ) )
224227
225228 return (op , description , None , None , origin )
226229
@@ -293,19 +296,20 @@ def extract_span_attributes(span, namespace):
293296 """
294297 Extract Sentry-specific span attributes and make them look the way Sentry expects.
295298 """
296- extracted_attrs = {}
299+ extracted_attrs = {} # type: dict[str, Any]
297300
298301 for attr , value in (span .attributes or {}).items ():
299302 if attr .startswith (namespace ):
300303 key = attr [len (namespace ) + 1 :]
301304
302305 if namespace == SentrySpanAttribute .MEASUREMENT :
303- value = {
306+ value = cast ("tuple[str, str]" , value )
307+ extracted_attrs [key ] = {
304308 "value" : float (value [0 ]),
305309 "unit" : value [1 ],
306310 }
307-
308- extracted_attrs [key ] = value
311+ else :
312+ extracted_attrs [key ] = value
309313
310314 return extracted_attrs
311315
@@ -457,7 +461,7 @@ def set_sentry_meta(span, key, value):
457461 # type: (Union[AbstractSpan, ReadableSpan], str, Any) -> None
458462 sentry_meta = getattr (span , "_sentry_meta" , {})
459463 sentry_meta [key ] = value
460- span ._sentry_meta = sentry_meta
464+ span ._sentry_meta = sentry_meta # type: ignore[union-attr]
461465
462466
463467def get_profile_context (span ):
0 commit comments