[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:
Ishaan Jaff 2024-09-25 10:57:08 -07:00 committed by GitHub
parent 2f67026f35
commit 4d253e473a
9 changed files with 243 additions and 79 deletions

View file

@ -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