Skip to content

Commit 8c15d39

Browse files
dd-octo-sts[bot]Yun-Kimsabrenner
authored
fix(openai): guard client/openai access [backport 3.11] (#14238)
Backport 030b83c from #14186 to 3.11. Closes #14168. Adds a safe access to `OpenAI/AsyncOpenAI._client` in the openai integration. Previously if the client was never initialized, it would raise an error (according to issue). Waiting on a better reproduction case from #14168 to add a regression test. ## 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: Yun Kim <[email protected]> Co-authored-by: Sam Brenner <[email protected]>
1 parent 9bd57c8 commit 8c15d39

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ddtrace/llmobs/_integrations/openai.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def _is_provider(self, span, provider):
7575
"""Check if the traced operation is from the given provider."""
7676
base_url = None
7777
if parse_version(self._openai.version.VERSION) >= (1, 0, 0):
78-
base_url = self._client._base_url
78+
base_url = getattr(self._client, "_base_url", None)
7979
else:
80-
base_url = self._openai.api_base
80+
base_url = getattr(self._openai, "api_base", None)
8181
base_url = str(base_url) if base_url else None
8282
if not base_url or not isinstance(base_url, str):
8383
return False
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
openai: Resolves an issue where an uninitialized ``OpenAI/AsyncOpenAI`` client would result in an ``AttributeError``.

0 commit comments

Comments
 (0)