@@ -218,33 +218,11 @@ def _should_be_included(
218218 )
219219
220220
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 ):
222+ # type: (sentry_sdk.tracing.Span, Optional[str], Optional[list[str]], Optional[list[str]] ) -> None
223223 """
224224 Adds OTel compatible source code information to the span
225225 """
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-
248226 # Find the correct frame
249227 frame = sys ._getframe () # type: Union[FrameType, None]
250228 while frame is not None :
@@ -309,6 +287,68 @@ def add_query_source(span):
309287 span .set_data (SPANDATA .CODE_FUNCTION , frame .f_code .co_name )
310288
311289
290+ def add_query_source (span ):
291+ # type: (sentry_sdk.tracing.Span) -> None
292+ """
293+ Adds OTel compatible source code information to a database query span
294+ """
295+ client = sentry_sdk .get_client ()
296+ if not client .is_active ():
297+ return
298+
299+ if span .timestamp is None or span .start_timestamp is None :
300+ return
301+
302+ should_add_query_source = client .options .get ("enable_db_query_source" , True )
303+ if not should_add_query_source :
304+ return
305+
306+ duration = span .timestamp - span .start_timestamp
307+ threshold = client .options .get ("db_query_source_threshold_ms" , 0 )
308+ slow_query = duration / timedelta (milliseconds = 1 ) > threshold
309+
310+ if not slow_query :
311+ return
312+
313+ add_source (
314+ span = span ,
315+ project_root = client .options ["project_root" ],
316+ in_app_include = client .options .get ("in_app_include" ),
317+ in_app_exclude = client .options .get ("in_app_exclude" ),
318+ )
319+
320+
321+ def add_http_request_source (span ):
322+ # type: (sentry_sdk.tracing.Span) -> None
323+ """
324+ Adds OTel compatible source code information to a span for an outgoing HTTP request
325+ """
326+ client = sentry_sdk .get_client ()
327+ if not client .is_active ():
328+ return
329+
330+ if span .timestamp is None or span .start_timestamp is None :
331+ return
332+
333+ should_add_request_source = client .options .get ("enable_http_request_source" , False )
334+ if not should_add_request_source :
335+ return
336+
337+ duration = span .timestamp - span .start_timestamp
338+ threshold = client .options .get ("http_request_source_threshold_ms" , 0 )
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+
312352def extract_sentrytrace_data (header ):
313353 # type: (Optional[str]) -> Optional[Dict[str, Union[str, bool, None]]]
314354 """
0 commit comments