Repository navigation
test(e2e): datadog log delivery for successful chat, messages, and responses (LIT-4447) #33415
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
Merged
yucheng-berri
merged 6 commits into
litellm_internal_staging
from
litellm_e2e_datadog_log_delivery
Jul 16, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
040b715
test(e2e): datadog log delivery for successful chat, messages, and re…
yucheng-berri fe815bb
test(e2e): address review findings on the datadog delivery suite
yucheng-berri bdd9c02
test(e2e): tolerate same-logical-event duplicates by call id, not byt…
yucheng-berri e7a59ad
test(e2e): assert the scenario strictly; the messages test is the LIT…
yucheng-berri 8d7be2e
Simplify docstrings for DataDog log tests
yucheng-berri 8cf6a00
Update test_datadog_log_e2e.py
yucheng-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| """Read-back for the DataDog logging tests: typed models over the compose | ||
| stack's dd-sink service, which records every logs-intake POST the datadog | ||
| callback sends (gunzipped) and replays them as JSON. | ||
|
|
||
| Delivery is judged on what the sink actually received, mirroring how the OTEL | ||
| tests read Jaeger; a failed sink query is a hard failure, never an empty | ||
| result. External reads go through ``e2e_http``. | ||
|
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. we could hit the actual datadog endpoint, using datadog application key to read logs back. for future references please make sure we use the actual provider as we cannot deploy these on our actual cluster |
||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import time | ||
| from dataclasses import dataclass | ||
|
|
||
| import pytest | ||
| from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError | ||
|
|
||
| from e2e_config import DD_SINK_URL, POLL_INTERVAL, POLL_TIMEOUT | ||
| from e2e_http import URL, NoBody, Success, get | ||
|
|
||
|
|
||
| class DdSinkRequest(BaseModel): | ||
| model_config = ConfigDict(extra="ignore") | ||
|
|
||
| path: str | ||
| body: str | ||
|
|
||
|
|
||
| class DdSinkRequests(BaseModel): | ||
| model_config = ConfigDict(extra="ignore") | ||
|
|
||
| requests: list[DdSinkRequest] = [] | ||
|
|
||
|
|
||
| class DdLogEvent(BaseModel): | ||
| model_config = ConfigDict(extra="ignore") | ||
|
|
||
| message: str | ||
| ddsource: str | None = None | ||
| service: str | None = None | ||
| status: str | None = None | ||
|
|
||
|
|
||
| _EVENT_BATCH: TypeAdapter[list[DdLogEvent]] = TypeAdapter(list[DdLogEvent]) | ||
|
|
||
|
|
||
| def _parse_batch(request: DdSinkRequest) -> list[DdLogEvent]: | ||
| """The intake accepts an array of events or a single event object.""" | ||
| try: | ||
| return _EVENT_BATCH.validate_json(request.body) | ||
| except ValidationError: | ||
| try: | ||
| return [DdLogEvent.model_validate_json(request.body)] | ||
| except ValidationError: | ||
| pytest.fail(f"dd-sink recorded a non-log body on {request.path}: {request.body[:200]}") | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True) | ||
| class DdSinkReader: | ||
| sink_url: str | ||
|
|
||
| def _recorded_requests(self) -> list[DdSinkRequest]: | ||
| result = get( | ||
| URL(f"{self.sink_url}/requests"), | ||
| headers=NoBody(), | ||
| params=NoBody(), | ||
| response_type=DdSinkRequests, | ||
| timeout=30.0, | ||
| ) | ||
| match result: | ||
| case Success(data=page): | ||
| return page.requests | ||
| case failure: | ||
| pytest.fail(f"dd-sink query at {self.sink_url} failed: {failure}") | ||
|
|
||
| def events_for_marker(self, marker: str) -> list[DdLogEvent]: | ||
| """Every log event across every recorded intake batch whose message | ||
| carries the marker. More than one hit for one call IS the | ||
| duplicate-delivery bug, so this never collapses to a single event.""" | ||
| events: list[DdLogEvent] = [] | ||
| for request in self._recorded_requests(): | ||
| if "/api/v2/logs" not in request.path: | ||
| continue | ||
| events.extend(event for event in _parse_batch(request) if marker in event.message) | ||
| return events | ||
|
|
||
| def poll_events_for_marker(self, marker: str) -> list[DdLogEvent]: | ||
| """Poll until at least one matching event lands (the callback flushes | ||
| in periodic batches), then re-read after one more interval so a late | ||
| duplicate cannot hide from the exactly-one assertion. At the deadline | ||
| the last result is returned as-is.""" | ||
| deadline = time.monotonic() + POLL_TIMEOUT | ||
| while time.monotonic() < deadline: | ||
| events = self.events_for_marker(marker) | ||
| if events: | ||
| time.sleep(POLL_INTERVAL) | ||
| return self.events_for_marker(marker) | ||
| time.sleep(POLL_INTERVAL) | ||
| return self.events_for_marker(marker) | ||
|
|
||
|
|
||
| def build_dd_sink_reader() -> DdSinkReader: | ||
| return DdSinkReader(sink_url=DD_SINK_URL) | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.