Skip to content
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

fix(openai): don't eagerly import types from openai as they may not be available #2601

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from opentelemetry.instrumentation.openai.shared.config import Config
from opentelemetry.instrumentation.openai.utils import is_openai_v1
from opentelemetry.instrumentation.openai.v0 import OpenAIV0Instrumentor
from opentelemetry.instrumentation.openai.v1 import OpenAIV1Instrumentor

_instruments = ("openai >= 0.27.0",)

Expand Down Expand Up @@ -38,12 +36,20 @@ def instrumentation_dependencies(self) -> Collection[str]:

def _instrument(self, **kwargs):
if is_openai_v1():
from opentelemetry.instrumentation.openai.v1 import OpenAIV1Instrumentor

OpenAIV1Instrumentor().instrument(**kwargs)
else:
from opentelemetry.instrumentation.openai.v0 import OpenAIV0Instrumentor

OpenAIV0Instrumentor().instrument(**kwargs)

def _uninstrument(self, **kwargs):
if is_openai_v1():
from opentelemetry.instrumentation.openai.v1 import OpenAIV1Instrumentor

OpenAIV1Instrumentor().uninstrument(**kwargs)
else:
from opentelemetry.instrumentation.openai.v0 import OpenAIV0Instrumentor

OpenAIV0Instrumentor().uninstrument(**kwargs)