(Feat) - Allow viewing Request/Response Logs stored in GCS Bucket (#8449)

* BaseRequestResponseFetchFromCustomLogger

* get_active_base_request_response_fetch_from_custom_logger

* get_request_response_payload

* ui_view_request_response_for_request_id

* fix uiSpendLogDetailsCall

* fix get_request_response_payload

* ui fix RequestViewer

* use 1 class AdditionalLoggingUtils

* ui_view_request_response_for_request_id

* cache the prefetch logs details

* refactor prefetch

* test view request/resp logs

* fix code quality

* fix get_request_response_payload

* uninstall posthog
prevent it from being added in ci/cd

* fix posthog

* fix traceloop test

* fix linting error
This commit is contained in:
Ishaan Jaff 2025-02-10 20:38:55 -08:00 committed by GitHub
parent 64a4229606
commit 00c596a852
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 706 additions and 201 deletions

View file

@ -2,6 +2,7 @@
import collections
import os
from datetime import datetime, timedelta, timezone
from functools import lru_cache
from typing import TYPE_CHECKING, Any, List, Optional
import fastapi
@ -1759,6 +1760,56 @@ async def ui_view_spend_logs( # noqa: PLR0915
raise handle_exception_on_proxy(e)
@lru_cache(maxsize=128)
@router.get(
"/spend/logs/ui/{request_id}",
tags=["Budget & Spend Tracking"],
dependencies=[Depends(user_api_key_auth)],
include_in_schema=False,
)
async def ui_view_request_response_for_request_id(
request_id: str,
start_date: Optional[str] = fastapi.Query(
default=None,
description="Time from which to start viewing key spend",
),
end_date: Optional[str] = fastapi.Query(
default=None,
description="Time till which to view key spend",
),
):
"""
View request / response for a specific request_id
- goes through all callbacks, checks if any of them have a @property -> has_request_response_payload
- if so, it will return the request and response payload
"""
custom_loggers = (
litellm.logging_callback_manager.get_active_additional_logging_utils_from_custom_logger()
)
start_date_obj: Optional[datetime] = None
end_date_obj: Optional[datetime] = None
if start_date is not None:
start_date_obj = datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S").replace(
tzinfo=timezone.utc
)
if end_date is not None:
end_date_obj = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S").replace(
tzinfo=timezone.utc
)
for custom_logger in custom_loggers:
payload = await custom_logger.get_request_response_payload(
request_id=request_id,
start_time_utc=start_date_obj,
end_time_utc=end_date_obj,
)
if payload is not None:
return payload
return None
@router.get(
"/spend/logs",
tags=["Budget & Spend Tracking"],