Fix: Null email issue in the logs.#151
Open
SirajuddinShaik wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Production GCS logger payload construction to reduce “null email” occurrences by sourcing user fields from both metadata and litellm_metadata, while also changing how session_id/header fields are derived in the emitted success/error JSON logs.
Changes:
- Pull user identity fields from both
metadataandlitellm_metadata, and merge them for session/model fields. - Change header logging to a filtered dict-comprehension (dropping only
x-api-key). - Remove the previous success-cost calculation block (leaving
costas a constant0).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+150
to
+156
| # Try metadata first, then litellm_metadata for email and user_id | ||
| email = ( | ||
| metadata.get("user_api_key_user_email") | ||
| or litellm_metadata.get("user_api_key_user_email") | ||
| or metadata.get("user_api_key_user_id") | ||
| or litellm_metadata.get("user_api_key_user_id") | ||
| ) |
Comment on lines
+211
to
+217
| if email is None: | ||
| try: | ||
| # Filter out keys containing 'api' or 'key' to avoid logging sensitive data | ||
| filtered_kwargs = { | ||
| k: v for k, v in kwargs.items() if "api" not in k.lower() and "key" not in k.lower() | ||
| } | ||
| success_log["litellm_kwargs"] = filtered_kwargs # For debugging when user info is missing |
Comment on lines
+206
to
208
| "headers": { | ||
| key: data for key, data in combined_metadata.get("headers", {}).items() if key not in ["x-api-key"] | ||
| }, |
Comment on lines
197
to
+205
| "response": {}, | ||
| "usage": {}, | ||
| "cost": 0, | ||
| "timing": { | ||
| "start_time": str(start_time), | ||
| "end_time": str(end_time), | ||
| "duration_seconds": ( | ||
| (end_time - start_time).total_seconds() | ||
| if start_time and end_time | ||
| else None | ||
| ), | ||
| "llm_api_duration_ms": metadata.get("llm_api_duration_ms"), | ||
| "duration_seconds": ((end_time - start_time).total_seconds() if start_time and end_time else None), | ||
| "llm_api_duration_ms": combined_metadata.get("llm_api_duration_ms"), | ||
| }, |
Comment on lines
+324
to
+325
| for key, data in metadata.get("headers", {}).items() | ||
| if key not in ["x-api-key"] |
Comment on lines
+148
to
+166
| metadata = litellm_params.get("metadata", {}) | ||
| litellm_metadata = litellm_params.get("litellm_metadata", {}) | ||
| # Try metadata first, then litellm_metadata for email and user_id | ||
| email = ( | ||
| metadata.get("user_api_key_user_email") | ||
| or litellm_metadata.get("user_api_key_user_email") | ||
| or metadata.get("user_api_key_user_id") | ||
| or litellm_metadata.get("user_api_key_user_id") | ||
| ) | ||
| user_id = metadata.get("user_api_key_user_id") or litellm_metadata.get("user_api_key_user_id") | ||
| team_alias = metadata.get("user_api_key_team_alias") or litellm_metadata.get("user_api_key_team_alias") | ||
| department = ( | ||
| metadata.get("user_api_key_metadata") or litellm_metadata.get("user_api_key_metadata") or {} | ||
| ).get("department", "unknown") | ||
| # Extract date and session_id for queryability | ||
| log_date = datetime.utcnow().strftime("%Y-%m-%d") | ||
| session_id = self._get_session_id(kwargs, litellm_params, metadata) | ||
| # Combine metadata for _get_session_id | ||
| combined_metadata = {**(litellm_metadata or {}), **(metadata or {})} | ||
| session_id = self._get_session_id(kwargs, litellm_params, combined_metadata) |
prakhar-prakash-juspay
requested changes
May 7, 2026
prakhar-prakash-juspay
left a comment
Collaborator
There was a problem hiding this comment.
please resolve copilot comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes