Skip to main content
Version: devel

dlt.common.runtime.telemetry

with_telemetry

def with_telemetry(category: TEventCategory, command: str, track_before: bool,
*args: str, **kwargs: Any) -> Callable[[TFun], TFun]

View source on GitHub

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'.

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.