mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-10 08:28:25 +00:00
fix(otel): name the provider on raw request spans for image generation
image_generation leaves custom_llm_provider as None in litellm_params and sets it only on the call details, so every raw_gen_ai_request attribute was exported as llm.None.<field>. Fall back to the call details before using Unknown
This commit is contained in:
parent
02f61c9c42
commit
480ef0186b
2 changed files with 23 additions and 1 deletions
|
|
@ -2893,7 +2893,9 @@ class OpenTelemetry(OTELGenAISemconvMixin, CustomLogger):
|
|||
# gen_ai.* / metadata.* attributes — duplicating them here doubles
|
||||
# storage and adds noise (Issue #3).
|
||||
litellm_params: Final = kwargs.get("litellm_params", {}) or {}
|
||||
custom_llm_provider: Final = litellm_params.get("custom_llm_provider", "Unknown")
|
||||
custom_llm_provider: Final = (
|
||||
litellm_params.get("custom_llm_provider") or kwargs.get("custom_llm_provider") or "Unknown"
|
||||
)
|
||||
|
||||
_raw_response = kwargs.get("original_response")
|
||||
_additional_args: Final = kwargs.get("additional_args", {}) or {}
|
||||
|
|
|
|||
|
|
@ -3616,6 +3616,26 @@ class TestRawSpanAttributeIsolation(unittest.TestCase):
|
|||
)
|
||||
|
||||
|
||||
@patch("litellm.turn_off_message_logging", False)
|
||||
def test_raw_span_names_the_provider_when_only_the_call_details_carry_it(self):
|
||||
span_exporter: Final = InMemorySpanExporter()
|
||||
tracer_provider: Final = TracerProvider()
|
||||
tracer_provider.add_span_processor(SimpleSpanProcessor(span_exporter))
|
||||
otel: Final = OpenTelemetry(tracer_provider=tracer_provider)
|
||||
raw_span: Final = tracer_provider.get_tracer(__name__).start_span("raw_gen_ai_request")
|
||||
kwargs: Final = {
|
||||
"custom_llm_provider": "bedrock",
|
||||
"litellm_params": {"custom_llm_provider": None},
|
||||
"original_response": '{"images": ["aGVsbG8="]}',
|
||||
"additional_args": {"complete_input_dict": {"text_prompts": [{"text": "a red fox"}]}},
|
||||
}
|
||||
|
||||
otel.set_raw_request_attributes(raw_span, kwargs, None)
|
||||
raw_span.end()
|
||||
|
||||
(raw,) = span_exporter.get_finished_spans()
|
||||
self.assertEqual(set(raw.attributes or {}), {"llm.bedrock.text_prompts", "llm.bedrock.images"})
|
||||
|
||||
class TestNoParentSpanDuplication(unittest.TestCase):
|
||||
"""Issue #4: When litellm_request child span exists, the parent
|
||||
litellm_proxy_request span should NOT get set_attributes() called."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue