forked from phoenix/litellm-mirror
move _get_parent_otel_span_from_kwargs to otel.py
This commit is contained in:
parent
61c10e60a4
commit
2a89486948
2 changed files with 22 additions and 10 deletions
|
@ -703,3 +703,24 @@ class OpenTelemetry(CustomLogger):
|
|||
management_endpoint_span.set_attribute(f"exception", str(_exception))
|
||||
management_endpoint_span.set_status(Status(StatusCode.ERROR))
|
||||
management_endpoint_span.end(end_time=_end_time_ns)
|
||||
|
||||
|
||||
# Helper functions used for OTEL logging
|
||||
def _get_parent_otel_span_from_kwargs(kwargs: Optional[dict] = None):
|
||||
try:
|
||||
if kwargs is None:
|
||||
return None
|
||||
litellm_params = kwargs.get("litellm_params")
|
||||
_metadata = kwargs.get("metadata") or {}
|
||||
if "litellm_parent_otel_span" in _metadata:
|
||||
return _metadata["litellm_parent_otel_span"]
|
||||
elif (
|
||||
litellm_params is not None
|
||||
and litellm_params.get("metadata") is not None
|
||||
and "litellm_parent_otel_span" in litellm_params.get("metadata", {})
|
||||
):
|
||||
return litellm_params["metadata"]["litellm_parent_otel_span"]
|
||||
elif "litellm_parent_otel_span" in kwargs:
|
||||
return kwargs["litellm_parent_otel_span"]
|
||||
except:
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue