Skip to content

Commit c6a4fa5

Browse files
feat(closes OPEN-10097): create Azure Content Understanding tracer
1 parent 60c4841 commit c6a4fa5

File tree

3 files changed

+499
-0
lines changed

3 files changed

+499
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "2722b419",
6+
"metadata": {},
7+
"source": [
8+
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/azure-content-understanding/azure_content_understanding_tracing.ipynb)\n",
9+
"\n",
10+
"\n",
11+
"# <a id=\"top\">Azure Content Understanding tracing quickstart</a>\n",
12+
"\n",
13+
"This notebook illustrates how to get started monitoring Azure Content Understanding with Openlayer."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"id": "020c8f6a",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"!pip install openlayer azure-ai-contentunderstanding azure-identity"
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"id": "75c2a473",
29+
"metadata": {},
30+
"source": [
31+
"## 1. Set the environment variables"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"id": "f3f4fa13",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"import os\n",
42+
"\n",
43+
"# Azure Content Understanding env variables\n",
44+
"os.environ[\"AZURE_CONTENT_UNDERSTANDING_ENDPOINT\"] = \"YOUR_AZURE_CONTENT_UNDERSTANDING_ENDPOINT_HERE\"\n",
45+
"os.environ[\"AZURE_CONTENT_UNDERSTANDING_KEY\"] = \"YOUR_AZURE_CONTENT_UNDERSTANDING_KEY_HERE\"\n",
46+
"\n",
47+
"# Openlayer env variables\n",
48+
"os.environ[\"OPENLAYER_API_KEY\"] = \"YOUR_OPENLAYER_API_KEY_HERE\"\n",
49+
"os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE\""
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"id": "9758533f",
55+
"metadata": {},
56+
"source": [
57+
"## 2. Import the `trace_azure_content_understanding` function and create the client"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"id": "e60584fa",
64+
"metadata": {},
65+
"outputs": [],
66+
"source": "from azure.ai.contentunderstanding import ContentUnderstandingClient\nfrom azure.ai.contentunderstanding.models import AnalysisInput\nfrom azure.core.credentials import AzureKeyCredential\n\nfrom openlayer.lib import configure, trace_azure_content_understanding\n\n# Configure if you want to upload documents to Openlayer storage\nconfigure(\n attachment_upload_enabled=True, # upload binary/file attachments\n url_upload_enabled=True, # also download & re-upload external URLs\n)\n\nclient = trace_azure_content_understanding(\n ContentUnderstandingClient(\n endpoint=os.environ.get(\"AZURE_CONTENT_UNDERSTANDING_ENDPOINT\"),\n credential=AzureKeyCredential(os.environ.get(\"AZURE_CONTENT_UNDERSTANDING_KEY\")),\n api_version=\"2025-11-01\",\n )\n)"
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"id": "72a6b954",
71+
"metadata": {},
72+
"source": [
73+
"## 3. Use your traced client normally"
74+
]
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"id": "76a350b4",
79+
"metadata": {},
80+
"source": [
81+
"That's it! Now you can continue using your Azure Content Understanding client normally. The data is automatically published to Openlayer and you can start creating tests around it!"
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"id": "e00c1c79",
88+
"metadata": {},
89+
"outputs": [],
90+
"source": "analyzer_id = \"prebuilt-read\"\nurl = \"https://contentunderstanding.ai.azure.com/assets/prebuilt/read_healthcare.png\"\n\npoller = client.begin_analyze(\n analyzer_id=analyzer_id,\n inputs=[AnalysisInput(url=url)],\n)\nresult = poller.result()"
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"id": "abaf6987-c257-4f0d-96e7-3739b24c7206",
96+
"metadata": {},
97+
"outputs": [],
98+
"source": []
99+
}
100+
],
101+
"metadata": {
102+
"kernelspec": {
103+
"display_name": "hr-benefits",
104+
"language": "python",
105+
"name": "python3"
106+
},
107+
"language_info": {
108+
"codemirror_mode": {
109+
"name": "ipython",
110+
"version": 3
111+
},
112+
"file_extension": ".py",
113+
"mimetype": "text/x-python",
114+
"name": "python",
115+
"nbconvert_exporter": "python",
116+
"pygments_lexer": "ipython3",
117+
"version": "3.12.13"
118+
}
119+
},
120+
"nbformat": 4,
121+
"nbformat_minor": 5
122+
}

src/openlayer/lib/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"trace_async_openai",
1212
"trace_async",
1313
"trace_bedrock",
14+
"trace_azure_content_understanding",
1415
"trace_oci_genai",
1516
"trace_oci", # Alias for backward compatibility
1617
"trace_litellm",
@@ -138,6 +139,26 @@ def trace_bedrock(client):
138139
return bedrock_tracer.trace_bedrock(client)
139140

140141

142+
def trace_azure_content_understanding(client):
143+
"""Trace Azure Content Understanding analyses."""
144+
# pylint: disable=import-outside-toplevel
145+
try:
146+
from azure.ai.contentunderstanding import ContentUnderstandingClient
147+
except ImportError:
148+
raise ImportError(
149+
"azure-ai-contentunderstanding is required for Azure Content Understanding tracing. "
150+
"Install with: pip install azure-ai-contentunderstanding"
151+
)
152+
153+
from .integrations import azure_content_understanding_tracer
154+
155+
if not isinstance(client, ContentUnderstandingClient):
156+
raise ValueError(
157+
"Invalid client. Please provide a ContentUnderstandingClient."
158+
)
159+
return azure_content_understanding_tracer.trace_azure_content_understanding(client)
160+
161+
141162
def trace_oci_genai(client, estimate_tokens: bool = True):
142163
"""Trace OCI GenAI chat completions.
143164

0 commit comments

Comments
 (0)