Skip to content

Commit 3f5b74c

Browse files
committed
adding conversation trace tests and recordings
1 parent eb3e8f7 commit 3f5b74c

File tree

10 files changed

+2011
-4
lines changed

10 files changed

+2011
-4
lines changed

instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,11 +1144,15 @@ def _get_conversation_items_request_attributes(kwargs, client_instance):
11441144

11451145
def _set_conversation_items_attributes(span, result, args, kwargs):
11461146
"""Set span attributes for conversation items list response."""
1147-
# Add conversation_id from arguments
1147+
# Add conversation_id from arguments (check both positional and keyword args)
1148+
conversation_id = None
11481149
if len(args) > 0:
11491150
conversation_id = args[0]
1150-
if conversation_id:
1151-
set_span_attribute(span, "gen_ai.conversation.id", conversation_id)
1151+
elif "conversation_id" in kwargs:
1152+
conversation_id = kwargs["conversation_id"]
1153+
1154+
if conversation_id:
1155+
set_span_attribute(span, "gen_ai.conversation.id", conversation_id)
11521156

11531157
# Add pagination info if available
11541158
if hasattr(result, "object") and result.object == "list":
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,350 @@
1+
interactions:
2+
- request:
3+
body: |-
4+
{}
5+
headers:
6+
accept:
7+
- application/json
8+
accept-encoding:
9+
- gzip, deflate
10+
authorization:
11+
- Bearer test_openai_api_key
12+
connection:
13+
- keep-alive
14+
content-length:
15+
- '2'
16+
content-type:
17+
- application/json
18+
host:
19+
- api.openai.com
20+
user-agent:
21+
- AsyncOpenAI/Python 2.5.0
22+
x-stainless-arch:
23+
- other:amd64
24+
x-stainless-async:
25+
- async:asyncio
26+
x-stainless-lang:
27+
- python
28+
x-stainless-os:
29+
- Windows
30+
x-stainless-package-version:
31+
- 2.5.0
32+
x-stainless-read-timeout:
33+
- '600'
34+
x-stainless-retry-count:
35+
- '0'
36+
x-stainless-runtime:
37+
- CPython
38+
x-stainless-runtime-version:
39+
- 3.13.9
40+
method: POST
41+
uri: https://api.openai.com/v1/conversations
42+
response:
43+
body:
44+
string: |-
45+
{
46+
"id": "test_conversation_id",
47+
"object": "conversation",
48+
"created_at": 1234567890,
49+
"metadata": {}
50+
}
51+
headers:
52+
CF-RAY: test_cf_ray_id-ATL
53+
Connection:
54+
- keep-alive
55+
Content-Type:
56+
- application/json
57+
Date: Mon, 01 Jan 2024 00:00:00 GMT
58+
Server:
59+
- cloudflare
60+
Set-Cookie: test_set_cookie
61+
Strict-Transport-Security:
62+
- max-age=31536000; includeSubDomains; preload
63+
Transfer-Encoding:
64+
- chunked
65+
X-Content-Type-Options:
66+
- nosniff
67+
alt-svc:
68+
- h3=":443"; ma=86400
69+
cf-cache-status:
70+
- DYNAMIC
71+
content-length:
72+
- '141'
73+
openai-organization: test_openai_org_id
74+
openai-processing-ms: '100'
75+
openai-project: test_openai_project_id
76+
openai-version:
77+
- '2020-10-01'
78+
x-envoy-upstream-service-time: '100'
79+
x-openai-proxy-wasm:
80+
- v0.1
81+
x-request-id: test_request_id
82+
status:
83+
code: 200
84+
message: OK
85+
- request:
86+
body: |-
87+
{
88+
"conversation": "test_conversation_id",
89+
"input": "Say hello",
90+
"model": "gpt-4o-mini"
91+
}
92+
headers:
93+
accept:
94+
- application/json
95+
accept-encoding:
96+
- gzip, deflate
97+
authorization:
98+
- Bearer test_openai_api_key
99+
connection:
100+
- keep-alive
101+
content-length:
102+
- '114'
103+
content-type:
104+
- application/json
105+
cookie:
106+
- test_cookie
107+
host:
108+
- api.openai.com
109+
user-agent:
110+
- AsyncOpenAI/Python 2.5.0
111+
x-stainless-arch:
112+
- other:amd64
113+
x-stainless-async:
114+
- async:asyncio
115+
x-stainless-lang:
116+
- python
117+
x-stainless-os:
118+
- Windows
119+
x-stainless-package-version:
120+
- 2.5.0
121+
x-stainless-read-timeout:
122+
- '600'
123+
x-stainless-retry-count:
124+
- '0'
125+
x-stainless-runtime:
126+
- CPython
127+
x-stainless-runtime-version:
128+
- 3.13.9
129+
method: POST
130+
uri: https://api.openai.com/v1/responses
131+
response:
132+
body:
133+
string: |-
134+
{
135+
"id": "test_response_id",
136+
"object": "response",
137+
"created_at": 1234567890,
138+
"status": "completed",
139+
"background": false,
140+
"billing": {
141+
"payer": "test_payer"
142+
},
143+
"conversation": {
144+
"id": "test_conversation_id"
145+
},
146+
"error": null,
147+
"incomplete_details": null,
148+
"instructions": null,
149+
"max_output_tokens": null,
150+
"max_tool_calls": null,
151+
"model": "gpt-4o-mini-2024-07-18",
152+
"output": [
153+
{
154+
"id": "test_message_id",
155+
"type": "message",
156+
"status": "completed",
157+
"content": [
158+
{
159+
"type": "output_text",
160+
"annotations": [],
161+
"logprobs": [],
162+
"text": "Hello! How can I assist you today?"
163+
}
164+
],
165+
"role": "assistant"
166+
}
167+
],
168+
"parallel_tool_calls": true,
169+
"previous_response_id": null,
170+
"prompt_cache_key": null,
171+
"reasoning": {
172+
"effort": null,
173+
"summary": null
174+
},
175+
"safety_identifier": null,
176+
"service_tier": "default",
177+
"store": true,
178+
"temperature": 1.0,
179+
"text": {
180+
"format": {
181+
"type": "text"
182+
},
183+
"verbosity": "medium"
184+
},
185+
"tool_choice": "auto",
186+
"tools": [],
187+
"top_logprobs": 0,
188+
"top_p": 1.0,
189+
"truncation": "disabled",
190+
"usage": {
191+
"input_tokens": 9,
192+
"input_tokens_details": {
193+
"cached_tokens": 0
194+
},
195+
"output_tokens": 10,
196+
"output_tokens_details": {
197+
"reasoning_tokens": 0
198+
},
199+
"total_tokens": 19
200+
},
201+
"user": null,
202+
"metadata": {}
203+
}
204+
headers:
205+
CF-RAY: test_cf_ray_id-ATL
206+
Connection:
207+
- keep-alive
208+
Content-Type:
209+
- application/json
210+
Date: Mon, 01 Jan 2024 00:00:00 GMT
211+
Server:
212+
- cloudflare
213+
Set-Cookie: test_set_cookie
214+
Strict-Transport-Security:
215+
- max-age=31536000; includeSubDomains; preload
216+
Transfer-Encoding:
217+
- chunked
218+
X-Content-Type-Options:
219+
- nosniff
220+
alt-svc:
221+
- h3=":443"; ma=86400
222+
cf-cache-status:
223+
- DYNAMIC
224+
content-length:
225+
- '1533'
226+
openai-organization: test_openai_org_id
227+
openai-processing-ms: '100'
228+
openai-project: test_openai_project_id
229+
openai-version:
230+
- '2020-10-01'
231+
x-envoy-upstream-service-time: '100'
232+
x-ratelimit-limit-requests: '1000'
233+
x-ratelimit-limit-tokens: '1000'
234+
x-ratelimit-remaining-requests: '1000'
235+
x-ratelimit-remaining-tokens: '1000'
236+
x-ratelimit-reset-requests: '1000'
237+
x-ratelimit-reset-tokens: '1000'
238+
x-request-id: test_request_id
239+
status:
240+
code: 200
241+
message: OK
242+
- request:
243+
body: ''
244+
headers:
245+
accept:
246+
- application/json
247+
accept-encoding:
248+
- gzip, deflate
249+
authorization:
250+
- Bearer test_openai_api_key
251+
connection:
252+
- keep-alive
253+
cookie:
254+
- test_cookie
255+
host:
256+
- api.openai.com
257+
user-agent:
258+
- AsyncOpenAI/Python 2.5.0
259+
x-stainless-arch:
260+
- other:amd64
261+
x-stainless-async:
262+
- async:asyncio
263+
x-stainless-lang:
264+
- python
265+
x-stainless-os:
266+
- Windows
267+
x-stainless-package-version:
268+
- 2.5.0
269+
x-stainless-read-timeout:
270+
- '600'
271+
x-stainless-retry-count:
272+
- '0'
273+
x-stainless-runtime:
274+
- CPython
275+
x-stainless-runtime-version:
276+
- 3.13.9
277+
method: GET
278+
uri: https://api.openai.com/v1/conversations/test_conversation_id/items
279+
response:
280+
body:
281+
string: |-
282+
{
283+
"object": "list",
284+
"data": [
285+
{
286+
"id": "test_message_id",
287+
"type": "message",
288+
"status": "completed",
289+
"content": [
290+
{
291+
"type": "output_text",
292+
"annotations": [],
293+
"logprobs": [],
294+
"text": "Hello! How can I assist you today?"
295+
}
296+
],
297+
"role": "assistant"
298+
},
299+
{
300+
"id": "test_message_id",
301+
"type": "message",
302+
"status": "completed",
303+
"content": [
304+
{
305+
"type": "input_text",
306+
"text": "Say hello"
307+
}
308+
],
309+
"role": "user"
310+
}
311+
],
312+
"first_id": "test_message_id",
313+
"has_more": false,
314+
"last_id": "test_message_id"
315+
}
316+
headers:
317+
CF-RAY: test_cf_ray_id-ATL
318+
Connection:
319+
- keep-alive
320+
Content-Type:
321+
- application/json
322+
Date: Mon, 01 Jan 2024 00:00:00 GMT
323+
Server:
324+
- cloudflare
325+
Set-Cookie: test_set_cookie
326+
Strict-Transport-Security:
327+
- max-age=31536000; includeSubDomains; preload
328+
Transfer-Encoding:
329+
- chunked
330+
X-Content-Type-Options:
331+
- nosniff
332+
alt-svc:
333+
- h3=":443"; ma=86400
334+
cf-cache-status:
335+
- DYNAMIC
336+
content-length:
337+
- '824'
338+
openai-organization: test_openai_org_id
339+
openai-processing-ms: '100'
340+
openai-project: test_openai_project_id
341+
openai-version:
342+
- '2020-10-01'
343+
x-envoy-upstream-service-time: '100'
344+
x-openai-proxy-wasm:
345+
- v0.1
346+
x-request-id: test_request_id
347+
status:
348+
code: 200
349+
message: OK
350+
version: 1

0 commit comments

Comments
 (0)