Skip to content

feat(datadog): add 'team' tag to logs, metrics, and cost management#21449

Merged
Harshit28j merged 5 commits intoBerriAI:mainfrom
Harshit28j:litellm_feat_dataDog_tags
Feb 18, 2026
Merged

feat(datadog): add 'team' tag to logs, metrics, and cost management#21449
Harshit28j merged 5 commits intoBerriAI:mainfrom
Harshit28j:litellm_feat_dataDog_tags

Conversation

@Harshit28j
Copy link
Contributor

@Harshit28j Harshit28j commented Feb 18, 2026

Relevant issues

Closes the need for team-based observability in Datadog integration.

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
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

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

Changes

image
  • Datadog Handler (datadog_handler.py): Updated get_datadog_tags to automatically extract and append the team tag from request metadata. Logic prioritizes user_api_key_team_alias -> team_alias -> user_api_key_team_id -> team_id.
  • Cost Management (datadog_cost_management.py): Implemented consistent team tag extraction in _extract_tags to ensure cost metrics are properly attributed to teams.
  • Documentation (datadog.md): Added a new "Automatic Tags" section to documentation, detailing the new team tag sources.

@vercel
Copy link

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 18, 2026 1:25pm

Request Review

greptile-apps[bot]

This comment was marked as outdated.

greptile-apps[bot]

This comment was marked as outdated.

@BerriAI BerriAI deleted a comment from greptile-apps bot Feb 18, 2026
@Harshit28j
Copy link
Contributor Author

@greptile can you please review this PR ?

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 18, 2026

Greptile Summary

This PR adds a team tag to Datadog logs, metrics, and cost management by extracting team information from request metadata. The core logic uses an or-chaining pattern across four metadata fields: user_api_key_team_alias, team_alias, user_api_key_team_id, and team_id.

  • The primary extraction path (user_api_key_team_alias and user_api_key_team_id) works correctly and matches how the proxy auth system populates metadata.
  • Two new fields (team_alias, team_id) were added to StandardLoggingMetadata and initialized in litellm_logging.py, but no code path in the codebase actually populates these fields with values. The fallback lookups for team_alias and team_id in both Datadog handlers are currently dead code.
  • The fix to use .get() instead of in for the user_api_key_alias check in datadog_cost_management.py is a correctness improvement — the previous in check would match even when the value was None, producing "None" as a string tag.
  • Tests use partial TypedDict construction that doesn't fully match production metadata shape, which may give false confidence in edge-case correctness.
  • Minor: duplicate # Add user info comment in datadog_cost_management.py.

Confidence Score: 3/5

  • The primary team tag feature works for the common case, but includes dead-code fallback paths and unpopulated type fields that suggest incomplete implementation.
  • The core feature (extracting team tag from user_api_key_team_alias) works correctly. However, two new fields added to StandardLoggingMetadata (team_alias, team_id) are never populated anywhere in the codebase, making the fallback paths dead code. The tests pass but use partial TypedDict construction that doesn't match production shape. No risk of runtime errors, but the incomplete implementation and dead code lower confidence.
  • Pay close attention to litellm/types/utils.py (unpopulated new fields) and tests/test_litellm/integrations/datadog/test_datadog_tags_regression.py (test reliability concerns).

Important Files Changed

Filename Overview
litellm/integrations/datadog/datadog_handler.py Adds team tag extraction via or-chaining on metadata fields. The team_alias and team_id fallbacks are currently dead code since those fields are never populated, but the primary user_api_key_team_alias path works correctly.
litellm/integrations/datadog/datadog_cost_management.py Team tag extraction added with consistent or-chaining pattern. Has a duplicate # Add user info comment on line 172. Same dead-code fallbacks as datadog_handler.py. Improved user alias check from in to .get() which is a correctness fix.
litellm/types/utils.py Adds team_alias and team_id fields to StandardLoggingMetadata, but no code path populates these fields with actual values. They are initialized to None in litellm_logging.py but never set from the proxy auth flow.
litellm/litellm_core_utils/litellm_logging.py Adds team_alias=None and team_id=None initialization to StandardLoggingMetadata construction. Also includes whitespace-only formatting changes (line breaks for long conditionals). No functional issues with the formatting changes.
tests/test_litellm/integrations/datadog/test_datadog_tags_regression.py New regression tests for team tag extraction. Tests use partial TypedDict construction that doesn't match production metadata shape. The async test may have fragility due to DatadogCostManagementLogger calling asyncio.create_task during init.
docs/my-website/docs/observability/datadog.md Adds documentation for the automatic team and request_tag tags. Documents the team_alias and team_id sources which are not yet populated in production.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[LLM Request] --> B[Proxy Auth]
    B --> C[UserAPIKeyAuth populates metadata]
    C --> D{user_api_key_team_alias set?}
    D -->|Yes| E[team tag = user_api_key_team_alias]
    D -->|No| F{team_alias set?}
    F -->|Yes - currently never| G[team tag = team_alias]
    F -->|No| H{user_api_key_team_id set?}
    H -->|Yes| I[team tag = user_api_key_team_id]
    H -->|No| J{team_id set?}
    J -->|Yes - currently never| K[team tag = team_id]
    J -->|No| L[No team tag added]
    E --> M[Datadog Handler / Cost Management]
    G --> M
    I --> M
    K --> M
    L --> M
    M --> N[Tags sent to Datadog]
Loading

Last reviewed commit: 5755483

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@Harshit28j Harshit28j merged commit c760318 into BerriAI:main Feb 18, 2026
13 of 21 checks passed
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.

1 participant