From f247682fa349e551d5052337855801927ef72a26 Mon Sep 17 00:00:00 2001 From: Hemang Date: Wed, 26 Mar 2025 15:20:26 +0100 Subject: [PATCH] Add debug logs for metadata push. --- gateway/integrations/explorer.py | 3 +++ gateway/routes/anthropic.py | 3 +++ gateway/routes/gemini.py | 3 +++ 3 files changed, 9 insertions(+) diff --git a/gateway/integrations/explorer.py b/gateway/integrations/explorer.py index ed4098d..7ea264a 100644 --- a/gateway/integrations/explorer.py +++ b/gateway/integrations/explorer.py @@ -59,6 +59,9 @@ async def push_trace( dataset=dataset_name, metadata=metadata, ) + print( + "[DEBUG] Pushing trace to Invariant Explorer: ", request.to_json(), flush=True + ) client = AsyncClient( api_url=os.getenv("INVARIANT_API_URL", DEFAULT_API_URL).rstrip("/"), api_key=invariant_authorization.split("Bearer ")[1], diff --git a/gateway/routes/anthropic.py b/gateway/routes/anthropic.py index 01004c6..672285a 100644 --- a/gateway/routes/anthropic.py +++ b/gateway/routes/anthropic.py @@ -93,10 +93,13 @@ def create_metadata( context: RequestContextData, response_json: dict[str, Any] ) -> dict[str, Any]: """Creates metadata for the trace""" + print("[DEBUG] Anthropic Request JSON: ", context.request_json, flush=True) + print("[DEBUG] Anthropic Response JSON: ", response_json, flush=True) metadata = {k: v for k, v in context.request_json.items() if k != "messages"} metadata["via_gateway"] = True if response_json.get("usage"): metadata["usage"] = response_json.get("usage") + print("[DEBUG] Anthropic Metadata: ", metadata, flush=True) return metadata diff --git a/gateway/routes/gemini.py b/gateway/routes/gemini.py index 905f14f..97d37be 100644 --- a/gateway/routes/gemini.py +++ b/gateway/routes/gemini.py @@ -193,6 +193,8 @@ def create_metadata( context: RequestContextData, response_json: dict[str, Any] ) -> dict[str, Any]: """Creates metadata for the trace""" + print("[DEBUG] Gemimini Request JSON: ", context.request_json, flush=True) + print("[DEBUG] Gemini Response JSON: ", response_json, flush=True) metadata = { k: v for k, v in context.request_json.items() @@ -206,6 +208,7 @@ def create_metadata( if key in ("usageMetadata", "modelVersion") } ) + print("[DEBUG] Gemini Metadata: ", metadata, flush=True) return metadata