forked from phoenix/litellm-mirror
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
|
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):
|
def set_attributes(self, span: Span, kwargs, response_obj):
|
||||||
from litellm.proxy._types import SpanAttributes
|
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
|
# 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
|
# 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 ###########
|
########## LLM Request Attributes ###########
|
||||||
|
@ -474,8 +487,6 @@ class OpenTelemetry(CustomLogger):
|
||||||
_raw_response,
|
_raw_response,
|
||||||
)
|
)
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _to_ns(self, dt):
|
def _to_ns(self, dt):
|
||||||
return int(dt.timestamp() * 1e9)
|
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…
Add table
Add a link
Reference in a new issue