I made this while working on Langfuse integration and due to langfuse/langfuse#2495.
tl;dr is that I couldn't get Langfuse to flush()
an observation while it's still running, and that has ramifications in long running observations or when observations might terminate unexpectedly.
In this example, I replace the observe()
decorator with a version that will first populate the trace from the environment or explicit arguments passed to it and only then invoke the decorator with the pre-populated trace. This way there's no need update_current_trace()
after the fact and no need to flush()
it.