[FEATURE] Set custom langfuse trace ID
Describe the feature you'd like When using langfuse the trace ID is randomly generated, this the default behaviour of the langfuse SDK. After the trace is created there is no way of matching a langfuse trace with a Flowise message.
One limitation of this is that it's impossible to use langfuse score API to store the feedback from the user, because we don't have the trace id of each message.
Different solution approaches could be:
- Allowing to set the trace ID through the input params when running a prediction. This is currently being used to inject values in langfuse like the user id.
- Always set the message id as trace id in langfuse.
- Return with the prediction response also the trace id.
I checked the code and Flowise is using both langfuse and langfuse-langchain SDKs for different use cases. I'm not entirely sure which use case use which SDK. I'm testing a basic chain flow and it uses the langfuse-langchain SDK.
There is also an ongoing dicussion on langfuse side: https://github.com/orgs/langfuse/discussions/953
I think its somewhat similar in this PR (https://github.com/FlowiseAI/Flowise/pull/2195/files) where we used a correlationId to track the parent message
I'm not sure how that correlationId is stored in Langchain, but we need the traceId anyways to do things through Langfuse's API.
What we are doing in the meantime is using the metadata field of the traces to store a custom responseId and then before setting a score for that trace, we go over all the traces in the session and get the one matching the responseId to get the traceId. This works but it's very hacky.
How do you set this metadata to each trace? @danieldabate