|
28 | 28 | from ddtrace.internal import core |
29 | 29 | from ddtrace.internal.packages import is_user_code |
30 | 30 | from ddtrace.internal.safety import _isinstance |
31 | | -from ddtrace.internal.utils.inspection import functions_for_code |
32 | 31 | from ddtrace.internal.wrapping.context import WrappingContext |
33 | 32 | from ddtrace.settings.code_origin import config as co_config |
34 | 33 | from ddtrace.trace import Span |
@@ -217,12 +216,17 @@ def on_span_start(self, span: Span) -> None: |
217 | 216 |
|
218 | 217 | span.set_tag_str(f"_dd.code_origin.frames.{n}.file", filename) |
219 | 218 | span.set_tag_str(f"_dd.code_origin.frames.{n}.line", str(code.co_firstlineno)) |
| 219 | + |
| 220 | + # Get the module and function name from the frame and code object. In Python3.11+ qualname |
| 221 | + # is available, otherwise we'll fallback to the unqualified name. |
220 | 222 | try: |
221 | | - (f,) = functions_for_code(code) |
222 | | - span.set_tag_str(f"_dd.code_origin.frames.{n}.type", f.__module__) |
223 | | - span.set_tag_str(f"_dd.code_origin.frames.{n}.method", f.__qualname__) |
224 | | - except ValueError: |
225 | | - continue |
| 223 | + name = code.co_qualname # type: ignore[attr-defined] |
| 224 | + except AttributeError: |
| 225 | + name = code.co_name |
| 226 | + |
| 227 | + mod = frame.f_globals.get("__name__") |
| 228 | + span.set_tag_str(f"_dd.code_origin.frames.{n}.type", mod) if mod else None |
| 229 | + span.set_tag_str(f"_dd.code_origin.frames.{n}.method", name) if name else None |
226 | 230 |
|
227 | 231 | # TODO[gab]: This will be enabled as part of the live debugger/distributed debugging |
228 | 232 | # if ld_config.enabled: |
|
0 commit comments