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

🐛 Bug Report: Calling openai methods in v1 SDK with with_raw_response redirect causes crash #535

Closed
1 task done
tonybaloney opened this issue Feb 27, 2024 · 0 comments · Fixed by #536
Closed
1 task done

Comments

@tonybaloney
Copy link
Contributor

Which component is this bug for?

OpenAI Instrumentation

📜 Description

OpenAI's v1 SDK has a with_raw_responses redirect that returns a different type, LegacyAPIResponse.

The code assumes it's a pydantic model and crashes in this mode.

👟 Reproduction steps

from opentelemetry import trace
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.richconsole import RichConsoleSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from openai import AsyncAzureOpenAI, AsyncOpenAI
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(RichConsoleSpanExporter()))

OpenAIInstrumentor().instrument()

azure_credential = DefaultAzureCredential(exclude_shared_token_cache_credential=True)
token_provider = get_bearer_token_provider(azure_credential, "https://cognitiveservices.azure.com/.default")

openai_client = AsyncAzureOpenAI(
    api_version="2023-07-01-preview",
    azure_endpoint="https://<redacted>.openai.azure.com",
    azure_ad_token_provider=token_provider,
)

async def test():
    # THIS next line
    response = await openai_client.embeddings.with_raw_response.create(
        model="embedding",
        input="Ground control to Major Tom",
    )

    response.close()

import asyncio

asyncio.run(test())

👍 Expected behavior

It should either not trace, but definitely not crash.

👎 Actual Behavior with Screenshots

Will submit test to reproduce

🤖 Python Version

3.11

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

Yes I am willing to submit a PR!

@tonybaloney tonybaloney changed the title 🐛 Bug Report: Calling openai methods in v1 SDK with with_raw_responses redirect causes crash 🐛 Bug Report: Calling openai methods in v1 SDK with with_raw_response redirect causes crash Feb 27, 2024
tonybaloney added a commit to tonybaloney/openllmetry that referenced this issue Feb 27, 2024
…hich has the .parse() method and then recursively calling the result so that span attributes are still captured
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant