Skip to content

fix: telemetry decorator overwrites original function metadata #11568

Description

@ritikraj2425

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

  1. Add import functools to the imports of _telemetry.py.
  2. Apply the @functools.wraps(func) decorator to send_telemetry_wrapper.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High priority, add to the next sprint

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions