Skip to content

Commit 58cf305

Browse files
authored
fix(core): Fix operation name for openai responses API (#17206)
According to https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-operation-name > “If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.” and because the responses api also allows file and image input we can assume it's not really a chat completion closes: #17192
1 parent fccc60f commit 58cf305

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

dev-packages/node-integration-tests/suites/tracing/openai/test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe('OpenAI integration', () => {
3838
// Second span - responses API
3939
expect.objectContaining({
4040
data: {
41-
'gen_ai.operation.name': 'chat',
42-
'sentry.op': 'gen_ai.chat',
41+
'gen_ai.operation.name': 'responses',
42+
'sentry.op': 'gen_ai.responses',
4343
'sentry.origin': 'manual',
4444
'gen_ai.system': 'openai',
4545
'gen_ai.request.model': 'gpt-3.5-turbo',
@@ -55,8 +55,8 @@ describe('OpenAI integration', () => {
5555
'openai.usage.completion_tokens': 8,
5656
'openai.usage.prompt_tokens': 5,
5757
},
58-
description: 'chat gpt-3.5-turbo',
59-
op: 'gen_ai.chat',
58+
description: 'responses gpt-3.5-turbo',
59+
op: 'gen_ai.responses',
6060
origin: 'manual',
6161
status: 'ok',
6262
}),
@@ -105,8 +105,8 @@ describe('OpenAI integration', () => {
105105
// Fifth span - responses API streaming
106106
expect.objectContaining({
107107
data: {
108-
'gen_ai.operation.name': 'chat',
109-
'sentry.op': 'gen_ai.chat',
108+
'gen_ai.operation.name': 'responses',
109+
'sentry.op': 'gen_ai.responses',
110110
'sentry.origin': 'manual',
111111
'gen_ai.system': 'openai',
112112
'gen_ai.request.model': 'gpt-4',
@@ -124,8 +124,8 @@ describe('OpenAI integration', () => {
124124
'openai.usage.completion_tokens': 10,
125125
'openai.usage.prompt_tokens': 6,
126126
},
127-
description: 'chat gpt-4 stream-response',
128-
op: 'gen_ai.chat',
127+
description: 'responses gpt-4 stream-response',
128+
op: 'gen_ai.responses',
129129
origin: 'manual',
130130
status: 'ok',
131131
}),
@@ -182,8 +182,8 @@ describe('OpenAI integration', () => {
182182
// Second span - responses API with PII
183183
expect.objectContaining({
184184
data: {
185-
'gen_ai.operation.name': 'chat',
186-
'sentry.op': 'gen_ai.chat',
185+
'gen_ai.operation.name': 'responses',
186+
'sentry.op': 'gen_ai.responses',
187187
'sentry.origin': 'manual',
188188
'gen_ai.system': 'openai',
189189
'gen_ai.request.model': 'gpt-3.5-turbo',
@@ -201,8 +201,8 @@ describe('OpenAI integration', () => {
201201
'openai.usage.completion_tokens': 8,
202202
'openai.usage.prompt_tokens': 5,
203203
},
204-
description: 'chat gpt-3.5-turbo',
205-
op: 'gen_ai.chat',
204+
description: 'responses gpt-3.5-turbo',
205+
op: 'gen_ai.responses',
206206
origin: 'manual',
207207
status: 'ok',
208208
}),
@@ -255,8 +255,8 @@ describe('OpenAI integration', () => {
255255
// Fifth span - responses API streaming with PII
256256
expect.objectContaining({
257257
data: expect.objectContaining({
258-
'gen_ai.operation.name': 'chat',
259-
'sentry.op': 'gen_ai.chat',
258+
'gen_ai.operation.name': 'responses',
259+
'sentry.op': 'gen_ai.responses',
260260
'sentry.origin': 'manual',
261261
'gen_ai.system': 'openai',
262262
'gen_ai.request.model': 'gpt-4',
@@ -276,8 +276,8 @@ describe('OpenAI integration', () => {
276276
'openai.usage.completion_tokens': 10,
277277
'openai.usage.prompt_tokens': 6,
278278
}),
279-
description: 'chat gpt-4 stream-response',
280-
op: 'gen_ai.chat',
279+
description: 'responses gpt-4 stream-response',
280+
op: 'gen_ai.responses',
281281
origin: 'manual',
282282
status: 'ok',
283283
}),

packages/core/src/utils/gen-ai-attributes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,5 @@ export const OPENAI_RESPONSE_STREAM_ATTRIBUTE = 'openai.response.stream';
150150
*/
151151
export const OPENAI_OPERATIONS = {
152152
CHAT: 'chat',
153+
RESPONSES: 'responses',
153154
} as const;

packages/core/src/utils/openai/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ export function getOperationName(methodPath: string): string {
2929
return OPENAI_OPERATIONS.CHAT;
3030
}
3131
if (methodPath.includes('responses')) {
32-
// The responses API is also a chat operation
33-
return OPENAI_OPERATIONS.CHAT;
32+
return OPENAI_OPERATIONS.RESPONSES;
3433
}
3534
return methodPath.split('.').pop() || 'unknown';
3635
}

packages/core/test/lib/utils/openai-utils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe('openai-utils', () => {
1717
expect(getOperationName('some.path.chat.completions.method')).toBe('chat');
1818
});
1919

20-
it('should return chat for responses methods', () => {
21-
expect(getOperationName('responses.create')).toBe('chat');
22-
expect(getOperationName('some.path.responses.method')).toBe('chat');
20+
it('should return responses for responses methods', () => {
21+
expect(getOperationName('responses.create')).toBe('responses');
22+
expect(getOperationName('some.path.responses.method')).toBe('responses');
2323
});
2424

2525
it('should return the last part of path for unknown methods', () => {
@@ -35,7 +35,7 @@ describe('openai-utils', () => {
3535
describe('getSpanOperation', () => {
3636
it('should prefix operation with gen_ai', () => {
3737
expect(getSpanOperation('chat.completions.create')).toBe('gen_ai.chat');
38-
expect(getSpanOperation('responses.create')).toBe('gen_ai.chat');
38+
expect(getSpanOperation('responses.create')).toBe('gen_ai.responses');
3939
expect(getSpanOperation('some.custom.operation')).toBe('gen_ai.operation');
4040
});
4141
});

0 commit comments

Comments
 (0)