Skip to content

Commit 2aa27d7

Browse files
authored
Merge pull request #5839 from snwoods/private/stevenwo/CP-49875
CP-49875: observer.py: Group the auto_instrumentation spans by module
2 parents b8b5fd0 + bd69fbe commit 2aa27d7

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

python3/packages/observer.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,15 @@ def autoinstrument_class(aclass):
306306
"""Auto-instrument a class."""
307307

308308
t = tracers[0]
309-
module_name = f"{aclass.__module__}:{aclass.__qualname__}"
309+
class_name = f"{aclass.__module__}:{aclass.__qualname__}"
310310

311-
with t.start_as_current_span(f"auto_instrumentation.add: {module_name}"):
311+
with t.start_as_current_span(f"auto_instrumentation.add_class: {class_name}"):
312312
for method_name, method in aclass.__dict__.items():
313313
if not callable(getattr(aclass, method_name)):
314314
continue
315315

316316
with t.start_as_current_span(
317-
f"class.instrument:{module_name}.{method_name}"
317+
f"class.instrument:{class_name}.{method_name}"
318318
):
319319
# Avoid RecursionError:
320320
# 'maximum recursion depth exceeded in comparison'
@@ -333,16 +333,17 @@ def autoinstrument_class(aclass):
333333
def autoinstrument_module(amodule):
334334
"""Autoinstrument the classes and functions in a module."""
335335

336-
# Instrument the methods of the classes in the module
337-
for _, aclass in inspect.getmembers(amodule, inspect.isclass):
338-
try:
339-
autoinstrument_class(aclass)
340-
except Exception:
341-
debug("instrument_function: Exception %s", traceback.format_exc())
342-
343-
# Instrument the module-level functions of the module
344-
for fname, afunction in inspect.getmembers(amodule, inspect.isfunction):
345-
setattr(amodule, fname, instrument_function(afunction))
336+
with tracers[0].start_as_current_span(f"auto_instrumentation.add_module: {amodule}"):
337+
# Instrument the methods of the classes in the module
338+
for _, aclass in inspect.getmembers(amodule, inspect.isclass):
339+
try:
340+
autoinstrument_class(aclass)
341+
except Exception:
342+
debug("instrument_function: Exception %s", traceback.format_exc())
343+
344+
# Instrument the module-level functions of the module
345+
for fname, afunction in inspect.getmembers(amodule, inspect.isfunction):
346+
setattr(amodule, fname, instrument_function(afunction))
346347

347348
if inspect.ismodule(wrapped):
348349
autoinstrument_module(wrapped)

0 commit comments

Comments
 (0)