21
21
to_string ,
22
22
is_sentry_url ,
23
23
_is_external_source ,
24
+ _is_in_project_root ,
24
25
_module_in_list ,
25
26
)
26
27
from sentry_sdk ._types import TYPE_CHECKING
@@ -170,6 +171,14 @@ def maybe_create_breadcrumbs_from_span(scope, span):
170
171
)
171
172
172
173
174
+ def _get_frame_module_abs_path (frame ):
175
+ # type: (FrameType) -> Optional[str]
176
+ try :
177
+ return frame .f_code .co_filename
178
+ except Exception :
179
+ return None
180
+
181
+
173
182
def add_query_source (span ):
174
183
# type: (sentry_sdk.tracing.Span) -> None
175
184
"""
@@ -200,10 +209,7 @@ def add_query_source(span):
200
209
# Find the correct frame
201
210
frame = sys ._getframe () # type: Union[FrameType, None]
202
211
while frame is not None :
203
- try :
204
- abs_path = frame .f_code .co_filename
205
- except Exception :
206
- abs_path = ""
212
+ abs_path = _get_frame_module_abs_path (frame )
207
213
208
214
try :
209
215
namespace = frame .f_globals .get ("__name__" ) # type: Optional[str]
@@ -215,16 +221,15 @@ def add_query_source(span):
215
221
)
216
222
217
223
should_be_included = not _is_external_source (abs_path )
218
- if namespace is not None :
219
- if in_app_exclude and _module_in_list (namespace , in_app_exclude ):
220
- should_be_included = False
221
- if in_app_include and _module_in_list (namespace , in_app_include ):
222
- # in_app_include takes precedence over in_app_exclude, so doing it
223
- # at the end
224
- should_be_included = True
224
+ if _module_in_list (namespace , in_app_exclude ):
225
+ should_be_included = False
226
+ if _module_in_list (namespace , in_app_include ):
227
+ # in_app_include takes precedence over in_app_exclude, so doing it
228
+ # at the end
229
+ should_be_included = True
225
230
226
231
if (
227
- abs_path . startswith ( project_root )
232
+ _is_in_project_root ( abs_path , project_root )
228
233
and should_be_included
229
234
and not is_sentry_sdk_frame
230
235
):
@@ -250,10 +255,7 @@ def add_query_source(span):
250
255
if namespace is not None :
251
256
span .set_data (SPANDATA .CODE_NAMESPACE , namespace )
252
257
253
- try :
254
- filepath = frame .f_code .co_filename
255
- except Exception :
256
- filepath = None
258
+ filepath = _get_frame_module_abs_path (frame )
257
259
if filepath is not None :
258
260
if namespace is not None :
259
261
in_app_path = filename_for_module (namespace , filepath )
0 commit comments