Reset LangfuseDecorator context to allow nested traces #4247
vitalii-diachkov-sumup
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature or potential improvement
For our internal use case, we call one LLM "chain" inside other and we want this to be two separate Langfuse traces. Calling once function with
@observe()
decorator inside another causing second to be created as span.We want to be able to start a completely new trace within existing langfuse_context
Additional information
We have implemented a hack that patches
langfuse.decorators.langfuse_decorator
global context variables inside context manager and restores the previous values on manager exit. This invokes nested@observe()
inside fresh context, causing Langfuse to create trace instead of span object.Here's the code:
The issue I have with this code as we deeply rely on internal implementation of this module and you guys will introduce any other ContextVars or change the way you determine whether to start a new trace or not, our hack will break. I added another test to our test suite that ensures that Langfuse has not introduced any new
ContextVar
, but that rather looks like a workaround that need to be changed in the future.I am happy to supply a PR with such changes, introducing new method of
LangfuseDecorator
class to make it possible to override the global context, but I wanted to first start a discussion here to:@observe()
decorator fits our needs)The way it looks in code might be:
Beta Was this translation helpful? Give feedback.
All reactions