Skip to content

Fix: Null email issue in the logs.#151

Open
SirajuddinShaik wants to merge 3 commits into
release/v1.83.3from
fix/null_email
Open

Fix: Null email issue in the logs.#151
SirajuddinShaik wants to merge 3 commits into
release/v1.83.3from
fix/null_email

Conversation

@SirajuddinShaik

Copy link
Copy Markdown
Member

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 metadata and litellm_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 cost as a constant 0).

💡 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 prakhar-prakash-juspay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please resolve copilot comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants