Do another update call when we're updating an ended trace in update_current_trace #1093
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's possible to have observations that 'outlive' their trace, for example when returning a StreamingResponse in FastAPI.
Currently, calling update_current_trace in such cases only worked for the server_merged_attributes. We can work around this by sending the metadata in .trace() instead of storing it in the context.
Failing use case:
Important
Fix
update_current_trace
to handle updates for ended traces by checkingtrace_already_ended
and sending appropriate update events.update_current_trace
, handle cases where traces end before observations by checkingtrace_already_ended
.trace_already_ended
, send an update event for all attributes, not justserver_merged_attributes
._observation_params_context
iftrace_already_ended
.This description was created by for a8f972e. It will automatically update as commits are pushed.
Greptile Summary
Disclaimer: Experimental PR review
Modified the update_current_trace function to handle cases where observations outlive their traces, particularly in FastAPI StreamingResponse scenarios.
langfuse/decorators/langfuse_decorator.py
to detect if trace has already ended by checking observation params contexttests/test_decorators.py
to verify async streaming scenarios where observations continue after trace completion💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!