dlt.common.runtime.telemetry
with_telemetry
def with_telemetry(category: TEventCategory, command: str, track_before: bool,
*args: str, **kwargs: Any) -> Callable[[TFun], TFun]
Decorator factory that attaches telemetry to a callable.
The returned decorator wraps a function so that an anonymous telemetry event is
emitted either before execution (if track_before is True) or after execution.
When tracked after execution, the event includes whether the call succeeded.
Telemetry is initialized lazily on first use if it is not already running.
Arguments:
category- telemetry event category used by the anon tracker.command- event/command name to report.track_before- if True, emit a single event before calling the function. if False, emit a single event after the call, including success state.*args- names of parameters from the decorated function whose values should be included in the event properties. names must match the function signature and can refer to positional or keyword parameters.**kwargs- additional key-value pairs to include in the event properties.
Returns:
a decorator that takes a function and returns a wrapped function with telemetry tracking applied. the wrapped function preserves the original signature and return value.
Notes:
- success is determined as follows when tracking after execution:
- if the wrapped function returns an int, 0 is treated as success; any other value is treated as failure.
- for non-int returns, success is True unless an exception is raised.
- on exception, a failure event is emitted and the exception is re-raised.
- event properties always include elapsed execution time in seconds under the 'elapsed' key and the success flag under 'success'.