mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
[Feat] Improve OTEL Tracking - Require all Redis Cache reads to be logged on OTEL (#5881)
* fix use previous internal usage caching logic * fix test_dual_cache_uses_redis * redis track event_metadata in service logging * show otel error on _get_parent_otel_span_from_kwargs * track parent otel span on internal usage cache * update_request_status * fix internal usage cache * fix linting * fix test internal usage cache * fix linting error * show event metadata in redis set * fix test_get_team_redis * fix test_get_team_redis * test_proxy_logging_setup
This commit is contained in:
parent
2f67026f35
commit
4d253e473a
9 changed files with 243 additions and 79 deletions
|
@ -1,10 +1,17 @@
|
|||
# What is this?
|
||||
## Helper utilities
|
||||
import os
|
||||
from typing import List, Literal, Optional, Tuple
|
||||
from typing import TYPE_CHECKING, Any, List, Literal, Optional, Tuple, Union
|
||||
|
||||
from litellm._logging import verbose_logger
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from opentelemetry.trace import Span as _Span
|
||||
|
||||
Span = _Span
|
||||
else:
|
||||
Span = Any
|
||||
|
||||
|
||||
def map_finish_reason(
|
||||
finish_reason: str,
|
||||
|
@ -68,10 +75,12 @@ def get_litellm_metadata_from_kwargs(kwargs: dict):
|
|||
|
||||
|
||||
# Helper functions used for OTEL logging
|
||||
def _get_parent_otel_span_from_kwargs(kwargs: Optional[dict] = None):
|
||||
def _get_parent_otel_span_from_kwargs(
|
||||
kwargs: Optional[dict] = None,
|
||||
) -> Union[Span, None]:
|
||||
try:
|
||||
if kwargs is None:
|
||||
return None
|
||||
raise ValueError("kwargs is None")
|
||||
litellm_params = kwargs.get("litellm_params")
|
||||
_metadata = kwargs.get("metadata") or {}
|
||||
if "litellm_parent_otel_span" in _metadata:
|
||||
|
@ -84,5 +93,9 @@ def _get_parent_otel_span_from_kwargs(kwargs: Optional[dict] = None):
|
|||
return litellm_params["metadata"]["litellm_parent_otel_span"]
|
||||
elif "litellm_parent_otel_span" in kwargs:
|
||||
return kwargs["litellm_parent_otel_span"]
|
||||
except:
|
||||
return None
|
||||
except Exception as e:
|
||||
verbose_logger.exception(
|
||||
"Error in _get_parent_otel_span_from_kwargs: " + str(e)
|
||||
)
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue