Skip to content

Commit c2d1ec9

Browse files
authored
Merge pull request #242 from microsoft/aochengwang/tracing
feat: add all remaining sdk instructions
2 parents 23cb0af + 173dba0 commit c2d1ec9

1 file changed

Lines changed: 153 additions & 4 deletions

File tree

doc/tracing.md

Lines changed: 153 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ All frameworks or SDKs that support OTLP and follow [semantic conventions for ge
66

77
| | Azure AI Inference | Azure AI Foundry Agents Service | Anthropic | Gemini | LangChain | OpenAI SDK | OpenAI Agents SDK |
88
|---|---|---|---|---|---|---|---|
9-
| **Python** ||| ✅ ([traceloop](https://github.com/traceloop/openllmetry))<sub>1,2</sub> || ✅ ([LangSmith](https://github.com/langchain-ai/langsmith-sdk)) <sub>1,2</sub> | ✅ ([opentelemetry-python-contrib](https://github.com/open-telemetry/opentelemetry-python-contrib)) <sub>1</sub> | ✅ ([Logfire](https://github.com/pydantic/logfire)) <sub>1,2</sub> |
10-
| **TS/JS** ||| ✅ ([traceloop](https://github.com/traceloop/openllmetry))<sub>1,2</sub>||✅ ([traceloop](https://github.com/traceloop/openllmetry)) <sub>1,2</sub> |✅ ([traceloop](https://github.com/traceloop/openllmetry)) <sub>1,2</sub>||
9+
| **Python** ||| ✅ ([traceloop](https://github.com/traceloop/openllmetry))<sub>1,2</sub> || ✅ ([LangSmith](https://github.com/langchain-ai/langsmith-sdk))<sub>1,2</sub> | ✅ ([opentelemetry-python-contrib](https://github.com/open-telemetry/opentelemetry-python-contrib))<sub>1</sub> | ✅ ([Logfire](https://github.com/pydantic/logfire))<sub>1,2</sub> |
10+
| **TS/JS** ||| ✅ ([traceloop](https://github.com/traceloop/openllmetry))<sub>1,2</sub>||✅ ([traceloop](https://github.com/traceloop/openllmetry))<sub>1,2</sub> |✅ ([traceloop](https://github.com/traceloop/openllmetry))<sub>1,2</sub>||
1111

1212
> 1. The SDKs in brackets are third-party SDKs to support OTLP instrumentation. They are used because the official SDKs don't support OTLP.
1313
> 2. These instrumentation SDKs don't strictly adhere to the OpenTelemetry semantic conventions for generative AI systems.
@@ -29,6 +29,11 @@ All frameworks or SDKs that support OTLP and follow [semantic conventions for ge
2929

3030
## Set up Instrumentation
3131

32+
Overall, the code changes focus on:
33+
34+
- Instrumenting the LLM/agent application.
35+
- Configuring the OTLP trace exporter to use the AITK local collector.
36+
3237
<details>
3338
<summary>Azure AI Inference SDK - Python</summary>
3439

@@ -66,7 +71,7 @@ AIInferenceInstrumentor().instrument(True)
6671

6772

6873
<details>
69-
<summary>Azure AI Inference SDK - TypeScript / JavaScript</summary>
74+
<summary>Azure AI Inference SDK - TypeScript/JavaScript</summary>
7075

7176
**Installation:**
7277
```bash
@@ -141,7 +146,7 @@ AIAgentsInstrumentor().instrument(True)
141146
</details>
142147

143148
<details>
144-
<summary>Azure AI Foundry Agent Service - TypeScript / JavaScript</summary>
149+
<summary>Azure AI Foundry Agent Service - TypeScript/JavaScript</summary>
145150

146151
**Installation:**
147152
```bash
@@ -180,6 +185,127 @@ registerInstrumentations({
180185
```
181186
</details>
182187

188+
<details>
189+
<summary>Anthropic - Python</summary>
190+
191+
**Installation:**
192+
```bash
193+
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http opentelemetry-instrumentation-anthropic
194+
```
195+
196+
**Setup:**
197+
```python
198+
from opentelemetry import trace
199+
from opentelemetry.sdk.resources import Resource
200+
from opentelemetry.sdk.trace import TracerProvider
201+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
202+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
203+
204+
resource = Resource(attributes={
205+
"service.name": "opentelemetry-instrumentation-anthropic-traceloop"
206+
})
207+
provider = TracerProvider(resource=resource)
208+
otlp_exporter = OTLPSpanExporter(
209+
endpoint="http://localhost:4318/v1/traces",
210+
)
211+
processor = BatchSpanProcessor(otlp_exporter)
212+
provider.add_span_processor(processor)
213+
trace.set_tracer_provider(provider)
214+
215+
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
216+
AnthropicInstrumentor().instrument()
217+
```
218+
</details>
219+
220+
<details>
221+
<summary>Anthropic - TypeScript/JavaScript</summary>
222+
223+
**Installation:**
224+
```bash
225+
npm install @traceloop/node-server-sdk
226+
```
227+
228+
**Setup:**
229+
```javascript
230+
const { initialize } = require("@traceloop/node-server-sdk");
231+
const { trace } = require("@opentelemetry/api");
232+
233+
initialize({
234+
appName: "opentelemetry-instrumentation-anthropic-traceloop",
235+
baseUrl: "http://localhost:4318",
236+
disableBatch: true,
237+
});
238+
```
239+
</details>
240+
241+
<details>
242+
<summary>Google Gemini - Python</summary>
243+
244+
**Installation:**
245+
```bash
246+
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http opentelemetry-instrumentation-google-genai
247+
```
248+
249+
**Setup:**
250+
```python
251+
from opentelemetry import trace
252+
from opentelemetry.sdk.resources import Resource
253+
from opentelemetry.sdk.trace import TracerProvider
254+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
255+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
256+
257+
resource = Resource(attributes={
258+
"service.name": "opentelemetry-instrumentation-google-genai"
259+
})
260+
provider = TracerProvider(resource=resource)
261+
otlp_exporter = OTLPSpanExporter(
262+
endpoint="http://localhost:4318/v1/traces",
263+
)
264+
processor = BatchSpanProcessor(otlp_exporter)
265+
provider.add_span_processor(processor)
266+
trace.set_tracer_provider(provider)
267+
268+
from opentelemetry.instrumentation.google_genai import GoogleGenAiSdkInstrumentor
269+
GoogleGenAiSdkInstrumentor().instrument(enable_content_recording=True)
270+
```
271+
</details>
272+
273+
<details>
274+
<summary>LangChain - Python</summary>
275+
276+
**Installation:**
277+
```bash
278+
pip install langsmith[otel]
279+
```
280+
281+
**Setup:**
282+
```python
283+
import os
284+
os.environ["LANGSMITH_OTEL_ENABLED"] = "true"
285+
os.environ["LANGSMITH_TRACING"] = "true"
286+
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "http://localhost:4318"
287+
```
288+
</details>
289+
290+
<details>
291+
<summary>LangChain - TypeScript/JavaScript</summary>
292+
293+
**Installation:**
294+
```bash
295+
npm install @traceloop/node-server-sdk
296+
```
297+
298+
**Setup:**
299+
```javascript
300+
const { initialize } = require("@traceloop/node-server-sdk");
301+
initialize({
302+
appName: "opentelemetry-instrumentation-langchain-traceloop",
303+
baseUrl: "http://localhost:4318",
304+
disableBatch: true,
305+
});
306+
```
307+
</details>
308+
183309
<details>
184310
<summary>OpenAI - Python</summary>
185311

@@ -233,6 +359,29 @@ initialize({
233359
```
234360
</details>
235361

362+
<details>
363+
<summary>OpenAI Agents SDK - Python</summary>
364+
365+
**Installation:**
366+
```bash
367+
pip install logfire
368+
```
369+
370+
**Setup:**
371+
```python
372+
import logfire
373+
import os
374+
375+
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = "http://localhost:4318/v1/traces"
376+
377+
logfire.configure(
378+
service_name="opentelemetry-instrumentation-openai-agents-logfire",
379+
send_to_logfire=False,
380+
)
381+
logfire.instrument_openai_agents()
382+
```
383+
</details>
384+
236385
## A Full Example
237386

238387
Here's a complete working example using Azure AI Inference SDK with Python that demonstrates how to set up both the tracing provider and instrumentation.

0 commit comments

Comments
 (0)