@@ -218,33 +218,10 @@ def _should_be_included(
218
218
)
219
219
220
220
221
- def add_query_source (span ):
222
- # type: (sentry_sdk.tracing.Span) -> None
221
+ def add_source (span , project_root , in_app_include , in_app_exclude ):
223
222
"""
224
223
Adds OTel compatible source code information to the span
225
224
"""
226
- client = sentry_sdk .get_client ()
227
- if not client .is_active ():
228
- return
229
-
230
- if span .timestamp is None or span .start_timestamp is None :
231
- return
232
-
233
- should_add_query_source = client .options .get ("enable_db_query_source" , True )
234
- if not should_add_query_source :
235
- return
236
-
237
- duration = span .timestamp - span .start_timestamp
238
- threshold = client .options .get ("db_query_source_threshold_ms" , 0 )
239
- slow_query = duration / timedelta (milliseconds = 1 ) > threshold
240
-
241
- if not slow_query :
242
- return
243
-
244
- project_root = client .options ["project_root" ]
245
- in_app_include = client .options .get ("in_app_include" )
246
- in_app_exclude = client .options .get ("in_app_exclude" )
247
-
248
225
# Find the correct frame
249
226
frame = sys ._getframe () # type: Union[FrameType, None]
250
227
while frame is not None :
@@ -309,6 +286,69 @@ def add_query_source(span):
309
286
span .set_data (SPANDATA .CODE_FUNCTION , frame .f_code .co_name )
310
287
311
288
289
+ def add_query_source (span ):
290
+ # type: (sentry_sdk.tracing.Span) -> None
291
+ """
292
+ Adds OTel compatible source code information to a database query span
293
+ """
294
+ client = sentry_sdk .get_client ()
295
+ if not client .is_active ():
296
+ return
297
+
298
+ if span .timestamp is None or span .start_timestamp is None :
299
+ return
300
+
301
+ should_add_query_source = client .options .get ("enable_db_query_source" , True )
302
+ if not should_add_query_source :
303
+ return
304
+
305
+ duration = span .timestamp - span .start_timestamp
306
+ threshold = client .options .get ("db_query_source_threshold_ms" , 0 )
307
+ slow_query = duration / timedelta (milliseconds = 1 ) > threshold
308
+
309
+ if not slow_query :
310
+ return
311
+
312
+ add_source (
313
+ span = span ,
314
+ project_root = client .options ["project_root" ],
315
+ in_app_include = client .options .get ("in_app_include" ),
316
+ in_app_exclude = client .options .get ("in_app_exclude" ),
317
+ )
318
+
319
+
320
+ def add_http_request_source (span ):
321
+ # type: (sentry_sdk.tracing.Span) -> None
322
+ """
323
+ Adds OTel compatible source code information to a span for an outgoing HTTP request
324
+ """
325
+ client = sentry_sdk .get_client ()
326
+ if not client .is_active ():
327
+ return
328
+
329
+ if span .timestamp is None or span .start_timestamp is None :
330
+ return
331
+
332
+ should_add_request_source = client .options .get ("enable_http_request_source" , True )
333
+ if not should_add_request_source :
334
+ return
335
+
336
+ duration = span .timestamp - span .start_timestamp
337
+ threshold = client .options .get ("http_request_source_threshold_ms" , 0 )
338
+ print ("division: " , duration / timedelta (milliseconds = 1 ), threshold )
339
+ slow_query = duration / timedelta (milliseconds = 1 ) > threshold
340
+
341
+ if not slow_query :
342
+ return
343
+
344
+ add_source (
345
+ span = span ,
346
+ project_root = client .options ["project_root" ],
347
+ in_app_include = client .options .get ("in_app_include" ),
348
+ in_app_exclude = client .options .get ("in_app_exclude" ),
349
+ )
350
+
351
+
312
352
def extract_sentrytrace_data (header ):
313
353
# type: (Optional[str]) -> Optional[Dict[str, Union[str, bool, None]]]
314
354
"""
0 commit comments