-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(datadog): add 'team' tag to logs, metrics, and cost management #21449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8d7f9a5
954e8d2
78e6080
02e4530
5755483
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import os | ||
| import sys | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| sys.path.insert(0, os.path.abspath("../../../")) | ||
|
|
||
| from litellm.integrations.datadog.datadog_handler import get_datadog_tags | ||
| from litellm.integrations.datadog.datadog_cost_management import ( | ||
| DatadogCostManagementLogger, | ||
| ) | ||
| from litellm.types.utils import StandardLoggingPayload, StandardLoggingMetadata | ||
|
|
||
|
|
||
| class TestDatadogTagsRegression: | ||
| @pytest.fixture | ||
| def mock_env_vars(self): | ||
| """Mock environment variables to isolate environment.""" | ||
| with patch.dict( | ||
| os.environ, | ||
| { | ||
| "DD_ENV": "test-env", | ||
| "DD_SERVICE": "test-service", | ||
| "DD_VERSION": "1.0.0", | ||
| "HOSTNAME": "test-host", | ||
| "POD_NAME": "test-pod", | ||
| "DD_API_KEY": "mock-api-key", | ||
| "DD_APP_KEY": "mock-app-key", | ||
| }, | ||
| ): | ||
| yield | ||
|
|
||
| def test_get_datadog_tags_regression(self, mock_env_vars): | ||
| """ | ||
| Regression Test: Ensure that get_datadog_tags still produces basic tags correctly | ||
| AND now includes the new team tag when provided. | ||
| """ | ||
| # Case 1: Legacy behavior (no team info) | ||
| payload_legacy = StandardLoggingPayload(metadata={}) | ||
Harshit28j marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tags_legacy = get_datadog_tags(payload_legacy) | ||
|
|
||
| # Verify base tags exist (legacy requirement) | ||
| assert "env:test-env" in tags_legacy | ||
| assert "service:test-service" in tags_legacy | ||
| # Verify NO team tag (should not invent one) | ||
| assert "team:" not in tags_legacy | ||
|
Comment on lines
+39
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test metadata construction doesn't match production behavior In production, When the key is present with a |
||
|
|
||
| # Case 2: New feature (team info provided) | ||
| payload_with_team = StandardLoggingPayload( | ||
| metadata=StandardLoggingMetadata(user_api_key_team_alias="regression-team") | ||
| ) | ||
| tags_with_team = get_datadog_tags(payload_with_team) | ||
|
|
||
| # Verify base tags STILL exist | ||
| assert "env:test-env" in tags_with_team | ||
| assert "service:test-service" in tags_with_team | ||
| # Verify NEW team tag is added | ||
| assert "team:regression-team" in tags_with_team | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_datadog_cost_management_tags_regression(self, mock_env_vars): | ||
| """ | ||
| Regression Test: Ensure DatadogCostManagementLogger extracts tags correctly, | ||
| preserving existing behavior while adding the team tag capability. | ||
| """ | ||
| logger = DatadogCostManagementLogger() | ||
Harshit28j marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Case 1: Legacy metadata (user alias only) | ||
| payload_legacy = StandardLoggingPayload( | ||
| metadata=StandardLoggingMetadata(user_api_key_alias="legacy-user") | ||
| ) | ||
|
|
||
| tags_legacy = logger._extract_tags(payload_legacy) | ||
|
|
||
| assert tags_legacy["env"] == "test-env" | ||
| assert tags_legacy["user"] == "legacy-user" | ||
| assert "team" not in tags_legacy # Should not exist | ||
|
|
||
| # Case 2: New metadata (team alias) | ||
| payload_new = StandardLoggingPayload( | ||
| metadata=StandardLoggingMetadata( | ||
| user_api_key_alias="new-user", user_api_key_team_alias="new-team-alias" | ||
| ) | ||
| ) | ||
|
|
||
| tags_new = logger._extract_tags(payload_new) | ||
|
|
||
| assert tags_new["env"] == "test-env" | ||
| assert tags_new["user"] == "new-user" | ||
| assert tags_new["team"] == "new-team-alias" # New feature verified | ||
Uh oh!
There was an error while loading. Please reload this page.