-
Notifications
You must be signed in to change notification settings - Fork 404
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 chat completion streams #1884
feat: Added instrumentation for chat completion streams #1884
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1884 +/- ##
=======================================
Coverage 96.87% 96.87%
=======================================
Files 209 209
Lines 39699 39759 +60
=======================================
+ Hits 38458 38518 +60
Misses 1241 1241
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
0b3fdb1
to
963dc88
Compare
963dc88
to
4878711
Compare
4878711
to
55be332
Compare
I am also convinced of this. It seems to silently swallow any errors thrown by the stream. Not knowing TS, it's really difficult to figure out all of their nested wrappers around their stream handling. |
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.
Just a couple minor comments, but otherwise looks good to me.
…sdoc on an optional param
Description
This PR adds instrumentation for chat completion streams. It intercepts the stream generator and proxies the iterations through chunks. It will then update the segment time and record LLM events when it finishes. Errors are funky and thanks to @jsumners-nr for helping create a test for it. I'm convinced the openai library has a bug but didn't spend time completely tracking down. It's worth noting that we only instrument streams in 4.12.2+. The interface was different in past versions and not worth supporting both. In that case the completion span + llm events will not occur. We still will get child spans for the external http call.
I also refactored the versioned tests as 1 file was getting unwieldy. Lastly, I fixed the span duration and manually end segments. We typically end segments implicitly and at transaction finalization we will calculate the durations. However since we're using the segment duration in the LLM events they must be the same so we end the segment right before recording events. This will be fine but a little different from what we typically do.
Related Issues
Closes #1844