You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(llmobs): fix parsing for NotGiven in beta oai clients (DataDog#13315)
ddtrace is throwing when users use
`client.beta.chat.completions.stream`. This is because the beta client
passes `NOT_GIVEN` explicitly as a keyword argument to an endpoint that
we do support tracing for, and when we extract it out we attempt to call
`get` on it.
We don't usually bump into this issue since `NOT_GIVEN` is never passed
in as an explicit keyword argument by an actual library user
The fix accounts for the `NOT_GIVEN` cause and treats it the same as if
`stream_options` was `None`.
We also add a regression test to make sure
`client.beta.chat.completions.stream` does not throw
Previous error
```
packages/ddtrace/contrib/internal/openai/_endpoint_hooks.py, line 78, in handle_request
self._record_request(pin, integration, instance, span, args, kwargs)
File /deps/pysetup/.venv/lib/python3.12/site-packages/ddtrace/contrib/internal/openai/_endpoint_hooks.py, line 252, in _record_request
if kwargs.get("stream_options", {}).get("include_usage", None) is not None:
AttributeError: 'NotGiven' object has no attribute 'get'
```
## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
Co-authored-by: lievan <[email protected]>
LLM Observability: This fix resolves an issue where using `client.beta.chat.completions.stream` with LLM Observability enabled caused an attribute error.
5
+
- |
6
+
openai: This fix resolves an issue where using `client.beta.chat.completions.stream` with openai patching caused an attribute error.
0 commit comments