feat: add Python Azure OpenAI instrumentation package - #156
Conversation
Add traceai-azure-openai package for tracing Azure OpenAI API calls. This brings Python parity with the existing Java Azure OpenAI integration. - AzureOpenAIInstrumentor for auto-instrumenting AzureOpenAI/AsyncAzureOpenAI clients - Azure-specific attributes: deployment name, API version, endpoint - Chat completions, embeddings, and completions tracing - Streaming and async support - Unit tests (7 tests) and usage examples
|
Nice work on this the streaming and async coverage is solid. One thing I noticed in init.py: _instrument patches openai.OpenAI.request rather than openai.AzureOpenAI.request directly. Since AzureOpenAI inherits from OpenAI this works in isolation, but if someone has both OpenAIInstrumentor and AzureOpenAIInstrumentor active in the same process they'd both be patching the same method on the same base class which could cause double instrumentation or one silently overwriting the other's wrapper. Would wrapping AzureOpenAI.request directly be cleaner so each instrumentor owns its own target? Also logger = logging.getLogger(name) appears twice in init.py (before and after the try/except block) second one's redundant. |
|
Hey thanks for putting this together, but I want to stop this one before it goes further, because I think the premise doesn't hold. traceai-openai already traces Azure OpenAI today. In the Python SDK, AzureOpenAI subclasses OpenAI and doesn't override request(): AzureOpenAI.request is OpenAI.request → True AzureOpenAIInstrumentor._instrument() wraps openai.OpenAI.request and openai.AsyncOpenAI.request — the exact same two targets OpenAIInstrumentor already wraps, and it never references AzureOpenAI anywhere. I ran Two things in your PR are genuinely better than what's on dev and I'd like to keep them:
That's ~20 lines into _get_attributes_from_instance in traceai_openai. Could you redo it as that instead? The reasons I don't want to ship the separate package: Duplicate spans. Any app using both OpenAI and Azure installs both instrumentors, both wrap the same function, and every Azure call produces two spans. That's double ingest cost for customers and broken trace Uninstrument leak. The Azure instrumentor captures _original_request after the OpenAI one has already wrapped it, so uninstrumenting in the wrong order leaves OpenAI.request permanently wrapped. On the Java parity point: that doesn't transfer. Java needs two packages because it wraps two genuinely different SDKs com.openai:openai-java vs com.azure:azure-ai-openai. Python has one SDK and one class |
Add traceai-azure-openai package for tracing Azure OpenAI API calls. This brings Python parity with the existing Java Azure OpenAI integration.
Pull Request
Description
tracing Azure OpenAI API calls