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
feat: Added instrumentation for openai chat completion creation #1862
feat: Added instrumentation for openai chat completion creation #1862
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1862 +/- ##
========================================
Coverage 96.85% 96.85%
========================================
Files 206 208 +2
Lines 39252 39422 +170
========================================
+ Hits 38017 38184 +167
- Misses 1235 1238 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…abled of if openai <4.0.0
…atter. if a value is blank it will be omitted
81da691
to
9515bb4
Compare
9515bb4
to
9218fef
Compare
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.
Looks good to me.
Description
This PR adds instrumentation for chat completion create. It adds the relevant span and the associated LLM events: n chat completion messages, and 1 chat completion summary.
Note: Error handling has been deferred to #1845 as well as stream based chat completions(#1844).
Aside from instrumentation
openai.Chat.Completions.prototype.create
, I had to wrapopenai.prototype.makeRequest
to decorate the active segment with request headers and api key to be used when creating the LLM events. As you can see they are cleaned up before returning the result to the user. I also had to enhance shim to pass in the active segment as the last arg, this is because once a promise resolves the active segment is its parent. We need the active segment that was being recorded to decorate the LLM events.How to Test
npm run versioned:internal openai
node test/unit/instrumentation/openai.test.js
If you want to use a sample app you can use this as the basis of it:
Related Issues
Closes #1841