-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(llma): add $ai_stop_reason property to LLM analytics #54037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6053da9
89c0a1d
f279639
d5f34d4
4baac50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,27 @@ describe('vercel-ai middleware', () => { | |
| expect(key).not.toBe('operation.name') | ||
| expect(key).not.toBe('resource.name') | ||
| } | ||
| expect(event.properties!['$ai_stop_reason']).toBe('stop') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Prompt To Fix With AIThis is a comment left during a code review.
Path: nodejs/src/ingestion/ai/otel/middleware/vercel-ai.test.ts
Line: 97
Comment:
**Missing test for `gen_ai.response.finish_reasons` array path**
The `gen_ai.response.finish_reasons` fallback (the `else if` branch in `vercel-ai.ts`) is untested. That branch has its own logic — array type check plus `[0]` indexing — and currently any breakage there would go undetected. A parametrised test covering `ai.response.finishReason` (primary), `gen_ai.response.finish_reasons` array (fallback), and neither present (undefined) would cover the three cases OnceAndOnlyOnce.
How can I resolve this? If you propose a fix, please make it concise. |
||
| }) | ||
|
|
||
| it('maps gen_ai.response.finish_reasons array to $ai_stop_reason', () => { | ||
| const event = createEvent('$ai_generation', { | ||
| 'ai.operationId': 'ai.generateText.doGenerate', | ||
| 'gen_ai.response.finish_reasons': ['length'], | ||
| }) | ||
| convertOtelEvent(event) | ||
|
|
||
| expect(event.properties!['gen_ai.response.finish_reasons']).toBeUndefined() | ||
| expect(event.properties!['$ai_stop_reason']).toBe('length') | ||
| }) | ||
|
|
||
| it('leaves $ai_stop_reason undefined when no finish reason is present', () => { | ||
| const event = createEvent('$ai_generation', { | ||
| 'ai.operationId': 'ai.generateText.doGenerate', | ||
| }) | ||
| convertOtelEvent(event) | ||
|
|
||
| expect(event.properties!['$ai_stop_reason']).toBeUndefined() | ||
| }) | ||
| }) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finish_reason-only path is not exercisedThe test has both
llm.response.stop_reasonandllm.response.finish_reasonpresent. The case where onlyllm.response.finish_reasonis provided (nostop_reason) is untested, so a regression in the??fallback would go undetected. A parametrised test covering both-present (stop_reason wins), finish_reason-only, and neither-present (undefined) would match the preference for parameterised tests.Prompt To Fix With AI