mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
(Feat) datadog_llm_observability
callback - emit request_tags
on logs (#7883)
All checks were successful
Read Version from pyproject.toml / read-version (push) Successful in 13s
All checks were successful
Read Version from pyproject.toml / read-version (push) Successful in 13s
* dd - emit tags on llm obs payload * dd - show requester tags on traces * test_get_datadog_tags * _get_datadog_tags * fix dd POD_NAME * test_get_datadog_tags
This commit is contained in:
parent
4b88635372
commit
806df5d31c
5 changed files with 82 additions and 3 deletions
|
@ -532,3 +532,48 @@ async def test_datadog_non_serializable_messages():
|
|||
# Check that the non-serializable objects were converted to strings
|
||||
assert isinstance(dict_payload["messages"][0]["content"], str)
|
||||
assert isinstance(dict_payload["response"]["choices"][0]["message"]["content"], str)
|
||||
|
||||
|
||||
def test_get_datadog_tags():
|
||||
"""Test the _get_datadog_tags static method with various inputs"""
|
||||
# Test with no standard_logging_object and default env vars
|
||||
base_tags = DataDogLogger._get_datadog_tags()
|
||||
assert "env:" in base_tags
|
||||
assert "service:" in base_tags
|
||||
assert "version:" in base_tags
|
||||
assert "POD_NAME:" in base_tags
|
||||
assert "HOSTNAME:" in base_tags
|
||||
|
||||
# Test with custom env vars
|
||||
test_env = {
|
||||
"DD_ENV": "production",
|
||||
"DD_SERVICE": "custom-service",
|
||||
"DD_VERSION": "1.0.0",
|
||||
"HOSTNAME": "test-host",
|
||||
"POD_NAME": "pod-123",
|
||||
}
|
||||
with patch.dict(os.environ, test_env):
|
||||
custom_tags = DataDogLogger._get_datadog_tags()
|
||||
assert "env:production" in custom_tags
|
||||
assert "service:custom-service" in custom_tags
|
||||
assert "version:1.0.0" in custom_tags
|
||||
assert "HOSTNAME:test-host" in custom_tags
|
||||
assert "POD_NAME:pod-123" in custom_tags
|
||||
|
||||
# Test with standard_logging_object containing request_tags
|
||||
standard_logging_obj = create_standard_logging_payload()
|
||||
standard_logging_obj["request_tags"] = ["tag1", "tag2"]
|
||||
|
||||
tags_with_request = DataDogLogger._get_datadog_tags(standard_logging_obj)
|
||||
assert "request_tag:tag1" in tags_with_request
|
||||
assert "request_tag:tag2" in tags_with_request
|
||||
|
||||
# Test with empty request_tags
|
||||
standard_logging_obj["request_tags"] = []
|
||||
tags_empty_request = DataDogLogger._get_datadog_tags(standard_logging_obj)
|
||||
assert "request_tag:" not in tags_empty_request
|
||||
|
||||
# Test with None request_tags
|
||||
standard_logging_obj["request_tags"] = None
|
||||
tags_none_request = DataDogLogger._get_datadog_tags(standard_logging_obj)
|
||||
assert "request_tag:" not in tags_none_request
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue