feat(opentelemetry.py): support logging call metadata to otel
This commit is contained in:
parent
b74095deca
commit
fd743aaefd
@ -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)
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user