-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do i add a session id or user or custom metadata to Langfuse traces? #4274
Comments
Hey @hamzaxd11! I'm here to help you with your Langfuse traces. Let's get this sorted out! To add a session ID or custom metadata to Langfuse traces when working with Langflow, you can use the
By following these steps, you can ensure that each session is uniquely tracked using the session ID provided in the API request [1]. |
@dosu Can you tell me about the inputs dictionary in this context? This is the body schema of the run api: { Do you mean that i should send the session_id over here where the session_id is or in the query params or what? |
You should include the |
@dosu I integrated your code and then tested the api with a session id, i got this error: AttributeError: This is the code you provided and i integrated: |
The error you're encountering suggests that the To resolve this, you should ensure that the # Check if a session ID is provided in the inputs and is not the same as the flow ID
if "session_id" in inputs and inputs["session_id"] != self.flow_id:
# Ensure the trace has a metadata attribute
if not hasattr(self.trace, 'metadata') or self.trace.metadata is None:
self.trace.metadata = {}
# Update the trace metadata with the session ID as the thread_id
self.trace.update(metadata=self.trace.metadata | {"thread_id": inputs["session_id"]}) This code snippet first checks if the |
I'm working with Langflow and need to pass custom metadata (like session ID, user ID, or other relevant information) into Langfuse traces. I find it difficult to understand the class hierarchies and code structure, and I’m not sure where to inject this metadata for it to be tracked properly in the trace lifecycle.
Additionally, my desired functionality is to be able to send a session ID as part of the API request to Langflow, and have that session ID be used as the session identifier within the Langfuse traces. Essentially, I want to ensure that each session is uniquely tracked using the session ID provided in the API request.
Could someone please guide me or provide a simple solution to achieve this? A step-by-step explanation or pointers to the relevant parts of the code would be really helpful!
Thanks in advance!
The text was updated successfully, but these errors were encountered: