Skip to content

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

Closed
@tonybaloney

Description

@tonybaloney

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions