mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-29 06:33:28 +00:00
fix(otel): filter redacted metadata keys without widening span metadata types
Drop user_api_key_* keys while iterating the typed StandardLoggingMetadata instead of round-tripping through the untyped redact helper, so the type gates see no new unknown types.
This commit is contained in:
parent
0c55922364
commit
47cf62db9e
1 changed files with 12 additions and 3 deletions
|
|
@ -49,6 +49,7 @@ from litellm.types.utils import (
|
|||
Function,
|
||||
LLMResponseTypes,
|
||||
StandardCallbackDynamicParams,
|
||||
StandardLoggingMetadata,
|
||||
StandardLoggingPayload,
|
||||
)
|
||||
|
||||
|
|
@ -103,6 +104,13 @@ class _ResponseWithUsageView(TypedDict, total=False):
|
|||
|
||||
_JSON_OBJECT: Final = TypeAdapter(Mapping[str, object], config=ConfigDict(hide_input_in_errors=True))
|
||||
|
||||
# Metadata keys dropped from spans when `litellm.redact_user_api_key_info` is set.
|
||||
_USER_API_KEY_METADATA_KEYS: Final = frozenset(
|
||||
key
|
||||
for key in StandardLoggingMetadata.__required_keys__ | StandardLoggingMetadata.__optional_keys__
|
||||
if key.startswith("user_api_key")
|
||||
)
|
||||
|
||||
# Cap on credential-scoped providers held at once; each one owns an exporter thread.
|
||||
_MAX_DYNAMIC_TRACER_PROVIDERS: Final = 256
|
||||
|
||||
|
|
@ -2413,10 +2421,11 @@ class OpenTelemetry(OTELGenAISemconvMixin, CustomLogger):
|
|||
#############################################
|
||||
############ LLM CALL METADATA ##############
|
||||
#############################################
|
||||
from litellm.litellm_core_utils.redact_messages import redact_user_api_key_info
|
||||
|
||||
metadata: Final = redact_user_api_key_info(metadata=dict(standard_logging_payload["metadata"]))
|
||||
metadata: Final = standard_logging_payload["metadata"]
|
||||
redact_user_api_key_info: Final = litellm.redact_user_api_key_info is True
|
||||
for key, value in metadata.items():
|
||||
if redact_user_api_key_info and key in _USER_API_KEY_METADATA_KEYS:
|
||||
continue
|
||||
self.safe_set_attribute(span=span, key=f"metadata.{key}", value=value)
|
||||
decision: Final = metadata.get("routing_decision")
|
||||
span.set_attributes(routing_decision_attributes(decision))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue