Skip to content

Commit 8669171

Browse files
dinmukhamedmnirga
andauthored
fix(openai): dump pydantic input message (#2979)
Co-authored-by: Nir Gazit <[email protected]>
1 parent bfa7b38 commit 8669171

File tree

4 files changed

+534
-0
lines changed

4 files changed

+534
-0
lines changed

packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ async def _set_prompts(span, messages):
369369

370370
for i, msg in enumerate(messages):
371371
prefix = f"{SpanAttributes.LLM_PROMPTS}.{i}"
372+
msg = msg if isinstance(msg, dict) else model_as_dict(msg)
372373

373374
_set_span_attribute(span, f"{prefix}.role", msg.get("role"))
374375
if msg.get("content"):
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
interactions:
2+
- request:
3+
body: '{"messages": [{"role": "user", "content": "Generate a random noun in Korean.
4+
Respond with just that word."}], "model": "gpt-4.1-nano"}'
5+
headers:
6+
accept:
7+
- application/json
8+
accept-encoding:
9+
- gzip, deflate
10+
connection:
11+
- keep-alive
12+
content-length:
13+
- '134'
14+
content-type:
15+
- application/json
16+
host:
17+
- api.openai.com
18+
traceparent:
19+
- 00-50385c6266930a3c2571ae06547d3d66-bb7cf190452daec9-01
20+
user-agent:
21+
- OpenAI/Python 1.51.2
22+
x-stainless-arch:
23+
- arm64
24+
x-stainless-async:
25+
- 'false'
26+
x-stainless-lang:
27+
- python
28+
x-stainless-os:
29+
- MacOS
30+
x-stainless-package-version:
31+
- 1.51.2
32+
x-stainless-retry-count:
33+
- '0'
34+
x-stainless-runtime:
35+
- CPython
36+
x-stainless-runtime-version:
37+
- 3.9.6
38+
method: POST
39+
uri: https://api.openai.com/v1/chat/completions
40+
response:
41+
body:
42+
string: !!binary |
43+
H4sIAAAAAAAAAwAAAP//jJJNbtswEIX3OgUxayuwLKWJvUs23bQoUHjRoggEmhzJTCgOQY6CFIFP
44+
0G2P0AP0XrlEQflHctsA2Wgx37zhe6N5zoQAo2ElQG0lq87b/La5WofPj09cfnrHuMby/eXNuth8
45+
2Hz0X7/ALCloc4+Kj6oLRZ23yIbcHquAkjFNLa6qZVEul/NyAB1ptEnWes6riyJ30lG+mC8u83mV
46+
F9VBviWjMMJKfMuEEOJ5+CajTuMTrMR8dqx0GKNsEVanJiEgkE0VkDGayNIxzEaoyDG6wfvL758v
47+
P35NYcCmjzI5dL21EyCdI5Yp4WDr7kB2JyOWWh9oE/+SQmOcids6oIzk0qORycNAd5kQd0Pg/iwD
48+
+ECd55rpAYfnFoe8MO55Ag+MiaWdlI/1s2G1RpbGxsm+QEm1RT0qx+XKXhuagGwS+V8v/5u9j21c
49+
+5bxI1AKPaOufUBt1HnesS1gOsLX2k4rHgxDxPBoFNZsMKTfoLGRvd1fBsTvkbGrG+NaDD6Y/Xk0
50+
vi6vy6qUi+a6gWyX/QEAAP//AwB0yAt+LQMAAA==
51+
headers:
52+
CF-RAY:
53+
- 94b0f287caba4428-LHR
54+
Connection:
55+
- keep-alive
56+
Content-Encoding:
57+
- gzip
58+
Content-Type:
59+
- application/json
60+
Date:
61+
- Thu, 05 Jun 2025 16:11:43 GMT
62+
Server:
63+
- cloudflare
64+
Set-Cookie:
65+
- __cf_bm=O9eAUpHGiHGrhiQetabnRwb5V_aaS9fmKt5mZA87bck-1749139903-1.0.1.1-T_6g4yzo0VSmeacWjX_XWznTeFpzZp1eH2c1my1gnQbigjPg.5O0cfciYSHV5yPw6M4QtnD7W_zYMy32piI1Tl9hrsNGDlCYA.0m8NiGUo4;
66+
path=/; expires=Thu, 05-Jun-25 16:41:43 GMT; domain=.api.openai.com; HttpOnly;
67+
Secure; SameSite=None
68+
- _cfuvid=JHo08JDcm1asanqe2mjXa5aF_Xl_UlmIQQmV15ZbM28-1749139903524-0.0.1.1-604800000;
69+
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
70+
Transfer-Encoding:
71+
- chunked
72+
X-Content-Type-Options:
73+
- nosniff
74+
access-control-expose-headers:
75+
- X-Request-ID
76+
alt-svc:
77+
- h3=":443"; ma=86400
78+
cf-cache-status:
79+
- DYNAMIC
80+
openai-organization:
81+
- user-xzaeeoqlanzncr8pomspsknu
82+
openai-processing-ms:
83+
- '201'
84+
openai-version:
85+
- '2020-10-01'
86+
strict-transport-security:
87+
- max-age=31536000; includeSubDomains; preload
88+
x-envoy-upstream-service-time:
89+
- '205'
90+
x-ratelimit-limit-requests:
91+
- '30000'
92+
x-ratelimit-limit-tokens:
93+
- '150000000'
94+
x-ratelimit-remaining-requests:
95+
- '29999'
96+
x-ratelimit-remaining-tokens:
97+
- '149999982'
98+
x-ratelimit-reset-requests:
99+
- 2ms
100+
x-ratelimit-reset-tokens:
101+
- 0s
102+
x-request-id:
103+
- req_cffda49c63c2b346e62f864e91161d3a
104+
status:
105+
code: 200
106+
message: OK
107+
- request:
108+
body: '{"messages": [{"role": "user", "content": "Generate a random noun in Korean.
109+
Respond with just that word."}, {"role": "assistant", "content": "\ubc14\ub2e4"},
110+
{"role": "user", "content": "Now, generate a sentence using the word you just
111+
gave me."}], "model": "gpt-4.1-nano"}'
112+
headers:
113+
accept:
114+
- application/json
115+
accept-encoding:
116+
- gzip, deflate
117+
connection:
118+
- keep-alive
119+
content-length:
120+
- '274'
121+
content-type:
122+
- application/json
123+
cookie:
124+
- __cf_bm=O9eAUpHGiHGrhiQetabnRwb5V_aaS9fmKt5mZA87bck-1749139903-1.0.1.1-T_6g4yzo0VSmeacWjX_XWznTeFpzZp1eH2c1my1gnQbigjPg.5O0cfciYSHV5yPw6M4QtnD7W_zYMy32piI1Tl9hrsNGDlCYA.0m8NiGUo4;
125+
_cfuvid=JHo08JDcm1asanqe2mjXa5aF_Xl_UlmIQQmV15ZbM28-1749139903524-0.0.1.1-604800000
126+
host:
127+
- api.openai.com
128+
traceparent:
129+
- 00-7ac5a7feb3b991b4bfe1e3a7aad93ccd-d81d0e2473995f47-01
130+
user-agent:
131+
- OpenAI/Python 1.51.2
132+
x-stainless-arch:
133+
- arm64
134+
x-stainless-async:
135+
- 'false'
136+
x-stainless-lang:
137+
- python
138+
x-stainless-os:
139+
- MacOS
140+
x-stainless-package-version:
141+
- 1.51.2
142+
x-stainless-retry-count:
143+
- '0'
144+
x-stainless-runtime:
145+
- CPython
146+
x-stainless-runtime-version:
147+
- 3.9.6
148+
method: POST
149+
uri: https://api.openai.com/v1/chat/completions
150+
response:
151+
body:
152+
string: !!binary |
153+
H4sIAAAAAAAAAwAAAP//jFI9j9QwFOzzKyzXm1Wym7AfJaKGhgahU+S1X7IGxzb2Cwd32gZRce2e
154+
hCjR0VNQ8o+y9x9OTvY2OTgkmhRv3kxmxu8yIoRKQdeE8i1DXlsVPy0XL7GqlssL8fyZvMjP5+82
155+
L+BVY/K6OaeTwDCbN8DxnjXlprYKUBrdw9wBQwiq6SJbpfPVKsk7oDYCVKBVFuNsmsaaaRPPklke
156+
J1mcZkf61kgOnq7J64gQQi67bzCqBXyga5JM7ic1eM8qoOvTEiHUGRUmlHkvPTKNdDKA3GgE3Xlv
157+
P31tv+xJ+3PfXt20P36Tw/erw/Xn2+tfh2/76ZjkoGw8C851o9QIYFobZCF5Z/fsiOxOBpWprDMb
158+
/weVllJLvy0cMG90MOPRWNqhu4iQs66I5kE2ap2pLRZo3kL3u2zey9Gh/wFcHjE0yNQwztPJI2KF
159+
AGRS+VGPlDO+BTEwh9JZI6QZAdEo8t9eHtPuY0td/Y/8AHAOFkEU1oGQ/GHeYc1BOM5/rZ0q7gxT
160+
D+695FCgBBeeQUDJGtVfDPUfPUJdlFJX4KyT/dmUtijTWfpksZkvEhrtojsAAAD//wMA5dqzDkUD
161+
AAA=
162+
headers:
163+
CF-RAY:
164+
- 94b0f28d8eef4428-LHR
165+
Connection:
166+
- keep-alive
167+
Content-Encoding:
168+
- gzip
169+
Content-Type:
170+
- application/json
171+
Date:
172+
- Thu, 05 Jun 2025 16:11:45 GMT
173+
Server:
174+
- cloudflare
175+
Transfer-Encoding:
176+
- chunked
177+
X-Content-Type-Options:
178+
- nosniff
179+
access-control-expose-headers:
180+
- X-Request-ID
181+
alt-svc:
182+
- h3=":443"; ma=86400
183+
cf-cache-status:
184+
- DYNAMIC
185+
openai-organization:
186+
- user-xzaeeoqlanzncr8pomspsknu
187+
openai-processing-ms:
188+
- '299'
189+
openai-version:
190+
- '2020-10-01'
191+
strict-transport-security:
192+
- max-age=31536000; includeSubDomains; preload
193+
x-envoy-upstream-service-time:
194+
- '304'
195+
x-ratelimit-limit-requests:
196+
- '30000'
197+
x-ratelimit-limit-tokens:
198+
- '150000000'
199+
x-ratelimit-remaining-requests:
200+
- '29999'
201+
x-ratelimit-remaining-tokens:
202+
- '149999963'
203+
x-ratelimit-reset-requests:
204+
- 2ms
205+
x-ratelimit-reset-tokens:
206+
- 0s
207+
x-request-id:
208+
- req_1989c72bc545874e463ac5ed5c4d3595
209+
status:
210+
code: 200
211+
message: OK
212+
version: 1

0 commit comments

Comments
 (0)