-
Notifications
You must be signed in to change notification settings - Fork 124
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
🐛 Fix OpentelemetryFinch handler on Finch.stream_while #398
base: main
Are you sure you want to change the base?
🐛 Fix OpentelemetryFinch handler on Finch.stream_while #398
Conversation
Hello 👋 |
@@ -44,8 +44,17 @@ defmodule OpentelemetryFinch do | |||
|
|||
status = | |||
case meta.result do | |||
{:ok, response} -> response.status | |||
_ -> 0 | |||
{:ok, response} when is_map(response) -> |
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.
The main issue was here. Not every response contains a status key as it depends on the implementation of the streaming callback functions.
A fallback case is also added. In this fix, I'm not trying to come up with a general solution but just one that works for the patterns I saw. The tests use callbacks that return values in the patterns I was already working with.
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.
I guess you could just match on the presence of the status:
case meta.result do
{:ok, %{status: status}} when is_integer(status) -> status
{:ok, {_request, %{status: status}}} when is_integer(status) -> status
{:ok, {status, _headers, _body}} when is_integer(status) -> status
_ -> 0
end
Because there is a risk that even when response
is a map, response.status
may not be set. As far as I can tell that part of the event is the stream accumulator and it could be anything, any term.
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.
(edit fixed my clauses 😅 )
+1 for this PR. We are using the Langchain lib with streams, and it is not compatible with OTEL. |
Fixes #327