Skip to content

Commit 5b1f462

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
chore: add OpenLLMetry tracing example
1 parent 6fe873c commit 5b1f462

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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/openllmetry/openllmetry_tracing.ipynb)\n",
9+
"\n",
10+
"\n",
11+
"# <a id=\"top\">OpenLLMetry quickstart</a>\n",
12+
"\n",
13+
"This notebook shows how to export traces captured by [OpenLLMetry](https://github.com/traceloop/openllmetry) (by Traceloop) to Openlayer. The integration is done via the Openlayer's [OpenTelemetry endpoint](https://www.openlayer.com/docs/integrations/opentelemetry)."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"id": "020c8f6a",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"!pip install openai traceloop-sdk"
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": 1,
37+
"id": "f3f4fa13",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"import os\n",
42+
"\n",
43+
"import openai\n",
44+
"\n",
45+
"os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY_HERE\"\n",
46+
"\n",
47+
"# Env variables pointing to Openlayer's OpenTelemetry endpoint (make sure to keep the `%20` to enconde the space between the `Bearer` and the `YOUR_OPENLAYER_API_KEY_HERE` string)\n",
48+
"os.environ[\"TRACELOOP_BASE_URL\"] = \"https://api.openlayer.com/v1/otel\"\n",
49+
"os.environ[\"TRACELOOP_HEADERS\"] = \"Authorization=Bearer%20YOUR_OPENLAYER_API_KEY_HERE, x-bt-parent=pipeline_id:YOUR_PIPELINE_ID_HERE\""
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"id": "9758533f",
55+
"metadata": {},
56+
"source": [
57+
"## 2. Initialize OpenLLMetry instrumentation"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"id": "c35d9860-dc41-4f7c-8d69-cc2ac7e5e485",
64+
"metadata": {},
65+
"outputs": [
66+
{
67+
"name": "stderr",
68+
"output_type": "stream",
69+
"text": [
70+
"Failed to export batch code: 404, reason: {\"error\": \"The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.\", \"code\": 404}\n"
71+
]
72+
}
73+
],
74+
"source": [
75+
"from traceloop.sdk import Traceloop\n",
76+
"\n",
77+
"Traceloop.init(disable_batch=True)"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"id": "72a6b954",
83+
"metadata": {},
84+
"source": [
85+
"## 3. Use LLMs and workflows as usual\n",
86+
"\n",
87+
"That's it! Now you can continue using LLMs and workflows as usual.The trace data is automatically exported to Openlayer and you can start creating tests around it."
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": 3,
93+
"id": "e00c1c79",
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"client = openai.OpenAI()"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": 4,
103+
"id": "abaf6987-c257-4f0d-96e7-3739b24c7206",
104+
"metadata": {},
105+
"outputs": [],
106+
"source": [
107+
"client.chat.completions.create(\n",
108+
" model=\"gpt-4o-mini\", messages=[{\"role\": \"user\", \"content\": \"How are you doing today?\"}]\n",
109+
")"
110+
]
111+
}
112+
],
113+
"metadata": {
114+
"kernelspec": {
115+
"display_name": "otel",
116+
"language": "python",
117+
"name": "python3"
118+
},
119+
"language_info": {
120+
"codemirror_mode": {
121+
"name": "ipython",
122+
"version": 3
123+
},
124+
"file_extension": ".py",
125+
"mimetype": "text/x-python",
126+
"name": "python",
127+
"nbconvert_exporter": "python",
128+
"pygments_lexer": "ipython3",
129+
"version": "3.9.19"
130+
}
131+
},
132+
"nbformat": 4,
133+
"nbformat_minor": 5
134+
}

0 commit comments

Comments
 (0)