Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /BerriAI_litellm /litellm /integrations /otel /runtime.py
| """SDK-free entrypoints for proxy-core call sites (auth, …). | |
| Proxy code may run without the OpenTelemetry SDK installed, so it must not import | |
| ``litellm.integrations.otel.logger`` (which imports the SDK at module scope) at | |
| module load. These wrappers import it lazily and no-op when the SDK is absent or | |
| V2 is not the active logger — so a call site can wrap a request phase or seed | |
| identity unconditionally. | |
| """ | |
| from collections.abc import Callable, Iterator | |
| from contextlib import contextmanager | |
| from functools import cache | |
| from typing import Any, Final | |
| def _otel_runtime() -> "tuple[Callable[[str], Any], Callable[..., None]] | None": | |
| """Resolve the SDK-backed hooks once and cache the outcome, absence included. | |
| CPython never caches a failed import, so without this memoization every call | |
| site re-attempts the import on each request; when the OTel SDK is not installed | |
| that re-scans ``sys.path`` and contends on the import lock on the hot path. | |
| """ | |
| try: | |
| from litellm.integrations.otel import logger | |
| except Exception: | |
| return None | |
| return (logger.phase_span, logger.seed_request_identity) | |
| def phase_span(name: str) -> "Iterator[Any]": | |
| """Run a request phase inside a live active span so its DB/service calls nest. | |
| Yields ``None`` (a plain no-op) when the OTel SDK is unavailable or V2 is not | |
| the active logger. | |
| """ | |
| runtime: Final = _otel_runtime() | |
| if runtime is None: | |
| yield None | |
| return | |
| with runtime[0](name) as span: | |
| yield span | |
| def seed_request_identity(user_api_key_dict: Any, model: Any = None) -> None: | |
| """Seed request-identity Baggage at the auth boundary (no-op without V2).""" | |
| runtime: Final = _otel_runtime() | |
| if runtime is None: | |
| return | |
| runtime[1](user_api_key_dict, model=model) | |
Xet Storage Details
- Size:
- 1.85 kB
- Xet hash:
- 53f86b0b8d3a5fb3441b7a4891c81f4a7378d09677038d67b7b199aeb6ff8302
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.