litellm/tests/test_litellm/integrations
ryan-crabbe-berri 886e91b85e
fix(otel): stamp http.response.status_code on all error responses (#28405)
* fix(otel): stamp http.response.status_code on all error responses

httpx.HTTPStatusError exposes status under .response.status_code, not as a
top-level attr, so unified-endpoint 5xx failures left the SERVER span without
a status. The admin hooks only wrote a child span and never stamped or ended
the parent at all, so admin 4xx/5xx (and success) responses were invisible
to dashboards. Adds a fallback to .response.status_code in get_error_information,
and ends the parent SERVER span in async_management_endpoint_{success,failure}_hook
with the same _record_exception_on_span helper the unified path uses.

Resolves LIT-3193

* test(otel): exercise httpx.HTTPStatusError through admin path

Pins the contract that get_error_information's response.status_code fallback
is reachable from any entry point — without this, a future refactor that
bypasses _record_exception_on_span in the admin hooks could regress for
httpx-wrapped exceptions while the unified suite still passes.

* chore(otel): trim verbose comments in LIT-3193 changes

Tighten docstrings and remove redundant section dividers/inline narration.
Behavior is unchanged.

* fix(otel): set span.status on management hook parent SERVER span

Mirror the unified failure path: stamp StatusCode.ERROR on the parent
SERVER span before recording the exception, and StatusCode.OK before
ending it on success. Without this, OTEL backends filtering on span
status (the idiomatic primitive) miss admin-endpoint failures even
though the http.response.status_code attribute is correct.

Extend assert_server_span_attrs to assert span.status.status_code
matches the expected outcome so the gap can't regress.

* fix(otel): close SERVER span on body-validation and unhandled errors

Stash the SERVER span on request.state in auth so FastAPI exception
handlers can finish it for failures that occur after auth but before
the route handler (e.g. /model/new TypeError, /key/generate
RequestValidationError). Without this, those requests left dangling
spans missing http.response.status_code.

Resolves LIT-3193

* fix(otel): generic 500 body, log exception details server-side

Don't leak str(exc) and type(exc).__name__ to clients on uncaught
exceptions. The full traceback is logged via verbose_proxy_logger and
the SERVER span still gets http.response.status_code=500.

Resolves LIT-3193

* fix(otel): stamp http.response.status_code on every SERVER span path

Closes three remaining gaps where the proxy SERVER span ended without
the http.response.status_code attribute:

1. ProxyException raised from _read_request_body (e.g. invalid JSON
   body) bubbled out of user_api_key_auth before the SERVER span was
   created, so the FastAPI handler had nothing to close and the trace
   never reached the backend. Hoist the span creation to a new
   idempotent _ensure_parent_otel_span_on_request_state helper called
   at the top of user_api_key_auth; wire openai_exception_handler to
   close the dangling span. Covers /v1/chat/completions, /v1/messages,
   /v1/responses (shared handler).

2. /v1/responses success — _handle_success ends the proxy span before
   async_post_call_success_hook fires on this path, so the hook's
   set_response_status_code_attribute(200) silently no-op'd against an
   ended span. Stamp 200 + set OK status at the close site in
   _handle_success / _end_proxy_span_from_kwargs via a shared
   _close_proxy_span_ok helper, so the attribute lands regardless of
   which success hook runs first.

3. Failure path for exceptions without code/status_code (e.g. a bare
   TypeError surfacing through _handle_llm_api_exception) — empty
   error_information.error_code → _record_exception_on_span skips the
   stamp → the hook ends the span. Default to 500 in
   async_post_call_failure_hook so the attribute is always set.

Resolves LIT-3193
2026-05-23 19:21:32 +00:00
..
arize Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_oss_staging_04_25_2026 2026-05-02 06:04:39 +00:00
azure_storage
bitbucket fix: block path traversal SSRF in BitBucket, Arize Phoenix, and AssemblyAI clients (#26943) 2026-05-01 11:45:12 -07:00
cloudzero
compression_interception
datadog
dotprompt
focus
gcs_bucket fix cloud storage file guards 2026-05-01 15:34:11 -07:00
gcs_pubsub
gitlab
langfuse
levo
litellm_agent
open_telemetry fix(otel): stamp http.response.status_code on all error responses (#28405) 2026-05-23 19:21:32 +00:00
SlackAlerting
websearch_interception Emit native web_search_tool_result blocks for Anthropic clients (Claude Desktop / Cowork citations) (#27886) 2026-05-14 12:30:47 -07:00
rubrik_test_helpers.py Litellm oss staging 04 21 2026 2 (#26569) 2026-05-20 21:25:19 -07:00
test_agentops.py
test_anthropic_cache_control_hook.py fix(tests): replace deprecated Bedrock Claude 3.7 Sonnet model ID 2026-04-28 14:24:19 -07:00
test_athina.py
test_azure_sentinel.py Add Azure Sentinel audit log support (#27280) 2026-05-06 15:50:06 -07:00
test_braintrust_logging.py
test_braintrust_span_name.py
test_custom_guardrail_recursion.py
test_custom_guardrail.py Fix 3 OpenTelemetry tracing bugs in proxy integration (#27757) 2026-05-12 18:32:05 -07:00
test_custom_prompt_management.py
test_deepeval.py
test_langfuse_otel.py
test_langfuse.py
test_langsmith_init.py Remove unneeded metadata info from LangSmith 2026-05-01 15:42:12 -07:00
test_mlflow.py
test_openmeter.py
test_opentelemetry_dynamic_imports.py
test_opentelemetry.py fix: serialize guardrail_response to JSON in OTEL traces (#28362) 2026-05-20 17:34:36 -07:00
test_otel_guardrail_violation_spans.py feat: add guardrail violation span attributes and fix missing spans on pre-call blocks (#28364) 2026-05-21 15:49:42 -07:00
test_otel_team_attributes_matrix.py feat: propagate team_id and team_alias to all child OTEL spans (#28273) 2026-05-19 15:31:25 -07:00
test_prometheus_api_promql_escape.py fix(prometheus): quote api_key for PromQL string literal in spend lookup 2026-05-01 21:38:19 +00:00
test_prometheus_cache_metrics.py
test_prometheus_client_ip_user_agent.py
test_prometheus_custom_metadata_label_counts.py Fix Prometheus remaining metric zero values (#27348) 2026-05-06 17:22:20 -07:00
test_prometheus_end_user_cardinality.py perf: cap Prometheus end-user metric cardinality with TTL + LRU eviction (#27272) 2026-05-06 13:35:13 -07:00
test_prometheus_invalid_key_filtering.py
test_prometheus_labels.py
test_prometheus_metric_name_consistency.py
test_prometheus_missing_metrics.py
test_prometheus_none_metadata.py
test_prometheus_queue_guardrail_metrics.py
test_prometheus_remaining_tokens_router_fallback.py fix(prometheus): emit litellm_remaining_tokens_metric for Bedrock and Vertex (#27705) 2026-05-13 17:40:59 -07:00
test_prometheus_services.py
test_prometheus_spend_logs_metadata.py
test_prometheus_stream_label.py
test_prometheus_token_detail_metrics.py feat(prometheus): emit per-token-type detail metrics (LIT-3220) (#28372) (#28378) 2026-05-23 12:17:42 -07:00
test_prometheus_user_team_metrics.py feat(prometheus): add user_email and user_alias to user budget metrics (#28155) 2026-05-18 16:28:14 -07:00
test_prompt_manager_ssti.py fix(security): sandbox jinja2 in gitlab/arize/bitbucket prompt managers 2026-05-02 09:14:02 +00:00
test_responses_background_cost.py
test_rubrik.py Litellm oss staging 04 21 2026 2 (#26569) 2026-05-20 21:25:19 -07:00
test_s3_v2.py decouple S3 audit-log config via s3_audit_callback_params 2026-05-05 13:23:32 -07:00
test_weave_otel.py