mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
feat(opentelemetry.py): support logging call metadata to otel
This commit is contained in:
parent
b74095deca
commit
fd743aaefd
4 changed files with 13 additions and 5 deletions
|
@ -288,6 +288,11 @@ class OpenTelemetry(CustomLogger):
|
|||
)
|
||||
pass
|
||||
|
||||
def is_primitive(self, value):
|
||||
if value is None:
|
||||
return False
|
||||
return isinstance(value, (str, bool, int, float))
|
||||
|
||||
def set_attributes(self, span: Span, kwargs, response_obj):
|
||||
from litellm.proxy._types import SpanAttributes
|
||||
|
||||
|
@ -296,6 +301,14 @@ class OpenTelemetry(CustomLogger):
|
|||
|
||||
# https://github.com/open-telemetry/semantic-conventions/blob/main/model/registry/gen-ai.yaml
|
||||
# Following Conventions here: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/llm-spans.md
|
||||
#############################################
|
||||
############ LLM CALL METADATA ##############
|
||||
#############################################
|
||||
metadata = litellm_params.get("metadata", {}) or {}
|
||||
|
||||
for key, value in metadata.items():
|
||||
if self.is_primitive(value):
|
||||
span.set_attribute("metadata.{}".format(key), value)
|
||||
|
||||
#############################################
|
||||
########## LLM Request Attributes ###########
|
||||
|
@ -474,8 +487,6 @@ class OpenTelemetry(CustomLogger):
|
|||
_raw_response,
|
||||
)
|
||||
|
||||
pass
|
||||
|
||||
def _to_ns(self, dt):
|
||||
return int(dt.timestamp() * 1e9)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue