fix(auto-instrumentation): Fully preserve returned promise in tracing channel hook#1617
fix(auto-instrumentation): Fully preserve returned promise in tracing channel hook#1617Luca Forstner (lforst) wants to merge 1 commit intomainfrom
Conversation
Stephen Belanger (Qard)
left a comment
There was a problem hiding this comment.
This change would be incorrect though. It also breaks behavioural compatibility with Node.js core.
| } | ||
| }, | ||
| ); | ||
| return result; |
There was a problem hiding this comment.
The problem with doing this though is that we'd be silencing unhandledRejection events due to branching and ignoring failures rather than passing through and re-raising the error for the downstream consumer.
There was a problem hiding this comment.
I had the same thought actually. I am wondering though, is there any way to preserve exact Node.js behavior while also preserving the "extended" promise?
Can we throw inside the error callback?
There was a problem hiding this comment.
It's a bug on their part for not preserving the promise species correctly. Unsure if there's a way we can hack around it as correct species use also requires retaining the constructor signature for it to be able to correctly construct descendants, but Anthropic violated that contract and gave it a different constructor signature which makes species construction crash. 😐
| return result; | ||
| } catch (err) { | ||
| context.error = err; | ||
| error?.publish(context); | ||
| publishRejected(err); |
There was a problem hiding this comment.
This is incorrect as if it reaches here it did not run the async portion and so should not produce asyncStart and asyncEnd events.
Fix the auto-instrumentation node hook so Anthropic
messages.stream()keeps working undernode --import braintrust/hook.mjs.APIPromisehelpers likewithResponse()intactmessages.stream()againFixes #1591