The send_telemetry decorator in haystack/telemetry/_telemetry.py wraps telemetry functions like pipeline_running and tutorial_running but does not use @functools.wraps.
As a result, decorated functions lose their original metadata—including their name (__name__), docstring (__doc__), and annotations (__annotations__). This can cause confusion in stack traces, make debugging harder, and affect API documentation generation.
A comment in the code currently states:
# FIXME? Somehow, functools.wraps makes `telemetry` out of scope. Let's take care of it later.
Reasoning / Analysis
The original concern that functools.wraps makes the global telemetry object "out of scope" is incorrect. Global variables inside the wrapped function are resolved at execution time (runtime), not decoration time. The error the original author encountered was most likely a simple NameError due to functools not being imported in _telemetry.py.
Proposed Solution
- Add
import functools to the imports of _telemetry.py.
- Apply the
@functools.wraps(func) decorator to send_telemetry_wrapper.
- Remove the obsolete
# FIXME comment.
Additional Context
I've verified that applying @functools.wraps doesn't cause any scope errors, and the existing unit tests in test/test_telemetry.py pass successfully with this change.
The
send_telemetrydecorator in haystack/telemetry/_telemetry.py wraps telemetry functions likepipeline_runningandtutorial_runningbut does not use@functools.wraps.As a result, decorated functions lose their original metadata—including their name (
__name__), docstring (__doc__), and annotations (__annotations__). This can cause confusion in stack traces, make debugging harder, and affect API documentation generation.A comment in the code currently states:
# FIXME? Somehow, functools.wraps makes `telemetry` out of scope. Let's take care of it later.Reasoning / Analysis
The original concern that
functools.wrapsmakes the globaltelemetryobject "out of scope" is incorrect. Global variables inside the wrapped function are resolved at execution time (runtime), not decoration time. The error the original author encountered was most likely a simpleNameErrordue tofunctoolsnot being imported in_telemetry.py.Proposed Solution
import functoolsto the imports of_telemetry.py.@functools.wraps(func)decorator tosend_telemetry_wrapper.# FIXMEcomment.Additional Context
I've verified that applying
@functools.wrapsdoesn't cause any scope errors, and the existing unit tests intest/test_telemetry.pypass successfully with this change.