observability_instrumentation module
Manual instrumentation helpers built on OpenTelemetry (safe no-op fallback).
traced decorator for sync/async functions that creates a span and records duration and errors via OpenTelemetry metrics when available.
All imports are done lazily to avoid hard dependency in environments where OpenTelemetry is not installed (e.g., docs/CI minimal).
- observability_instrumentation.traced(span_name=None, attributes=None)[מקור]
Decorator to add OpenTelemetry tracing around a function.
Works for both sync and async functions.
If OpenTelemetry is not available, acts as a no-op decorator.
- observability_instrumentation.start_span(span_name, attributes=None)[מקור]
Start a span manually (best-effort).
Returns a context manager whose __enter__ yields the span (or None when OTEL missing). Safe to use as:
span_cm = start_span("my.span", {"key": "value"}) span = span_cm.__enter__() try: ... finally: span_cm.__exit__(None, None, None)