Skip to content

Conversation

@cbrewster
Copy link
Member

@cbrewster cbrewster commented Nov 23, 2024

Why

Streaming response procedures don't raise errors like the other procedures, instead the errors are included in the AsyncIterator.

Also fixes issues with using contextvars + async generators.

What changed

  • Check if the message from the async iterator is a RiverError, if so, record it on the span
  • Use start_span instead of start_as_current_span, the latter resets a contextvar in its finally clause which is invalid to do for async generators as the async generator's finalizers run in a different context
    • Thread the span through manually so we still propagate the tracing info

Test plan

  • Should see errors for failed streaming procedures
  • Logs about resetting contextvars in a different context should go away
  • Added some tests for the otel stuff to make sure the error handling works here

@cbrewster cbrewster requested a review from a team as a code owner November 23, 2024 04:35
@cbrewster
Copy link
Member Author

cbrewster commented Nov 23, 2024

Current dependencies on/for this PR:

This comment was autogenerated by Freephite.

@cbrewster cbrewster requested review from masad-frost and removed request for a team November 23, 2024 04:35
@cbrewster cbrewster force-pushed the 11-22-bugfix_tracing_include_streaming_procedure_errors branch 2 times, most recently from 5786b26 to 046355d Compare November 25, 2024 18:26
@cbrewster cbrewster force-pushed the 11-22-bugfix_tracing_include_streaming_procedure_errors branch 2 times, most recently from 7e4549d to e2432af Compare November 26, 2024 19:12
@masad-frost
Copy link
Member

@blast-hardcheese can I dump this on you please? :D

@masad-frost masad-frost requested review from blast-hardcheese and removed request for masad-frost November 26, 2024 19:12
@cbrewster cbrewster force-pushed the 11-22-bugfix_tracing_include_streaming_procedure_errors branch 2 times, most recently from 320fb9b to da90ab1 Compare November 26, 2024 19:14
@cbrewster cbrewster added the bug Something isn't working label Nov 26, 2024
Copy link
Contributor

@blast-hardcheese blast-hardcheese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trending in the right direction, for sure. Great call-out wrt the asyncio.wait not raising the captured exceptions. In a sense, it can't do that sensibly.

Otoh, this really makes me want a linting rule for "you called a function that returned a value, but you didn't receive it." Kind of challenging in Python due to the dynamic and multipurpose nature of many functions, but it would have caught this.

Copy link
Contributor

@blast-hardcheese blast-hardcheese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intended to approve. Pardon.

@cbrewster cbrewster force-pushed the 11-22-bugfix_tracing_include_streaming_procedure_errors branch from da90ab1 to e308d40 Compare November 26, 2024 19:39
@cbrewster cbrewster merged commit 88f4347 into main Nov 26, 2024
5 checks passed
@cbrewster cbrewster deleted the 11-22-bugfix_tracing_include_streaming_procedure_errors branch November 26, 2024 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants