DOC: <Issue related to /observability/how_to_guides/monitoring/threads> #46

Closed
opened 2026-02-21 17:17:03 -05:00 by yindo · 2 comments
Owner

Originally created by @gzrubio on GitHub (Dec 23, 2024).

Originally assigned to: @angus-langchain on GitHub.

Hello!

I'm having some issues setting Threads for my project despite following this guide and Add metadata and tags literally.

The issue I am having is that although all the runs from my thread have the same session_id they are not bundled into a Thread. I tried using thread_id but that metadata key has no effect either.

This is how I am setting up the metadata:

@traceable
def chat_completion_request(messages, session_id, functions=None, model="gpt-3.5-turbo"):
    client = wrap_openai(OpenAI(api_key=secrets['OPENAI_APIKEY'],), tracing_extra={"metadata":
                                                                                   {"session_id": session_id}})
    try:
        response = client.chat.completions.create(
            model=model,
            messages=messages,
            functions=functions,
        )
        print(f"Model Response: {response}")

Is there any other condition required for Threads to work? If so, could we include it in the guide?

Originally created by @gzrubio on GitHub (Dec 23, 2024). Originally assigned to: @angus-langchain on GitHub. Hello! I'm having some issues setting Threads for my project despite following this guide and [Add metadata and tags](https://docs.smith.langchain.com/observability/how_to_guides/tracing/add_metadata_tags) literally. The issue I am having is that although all the runs from my thread have the same `session_id` they are not bundled into a Thread. I tried using `thread_id` but that metadata key has no effect either. This is how I am setting up the metadata: ``` @traceable def chat_completion_request(messages, session_id, functions=None, model="gpt-3.5-turbo"): client = wrap_openai(OpenAI(api_key=secrets['OPENAI_APIKEY'],), tracing_extra={"metadata": {"session_id": session_id}}) try: response = client.chat.completions.create( model=model, messages=messages, functions=functions, ) print(f"Model Response: {response}") ``` Is there any other condition required for Threads to work? If so, could we include it in the guide?
yindo closed this issue 2026-02-21 17:17:03 -05:00
Author
Owner

@angus-langchain commented on GitHub (Apr 7, 2025):

Hi @gzrubio, The thread metadata should be set on the root run, so in this case that would be the @traceable decorator.

here's how you can modify your example to work with threads

from langsmith.run_helpers import LangSmithExtra

langsmith_extra = LangSmithExtra(metadata={"session_id": session_id})

chat_completion_request(messages1, langsmith_extra=langsmith_extra)
@angus-langchain commented on GitHub (Apr 7, 2025): Hi @gzrubio, The thread metadata should be set on the root run, so in this case that would be the `@traceable` decorator. here's how you can modify your example to work with threads ``` from langsmith.run_helpers import LangSmithExtra langsmith_extra = LangSmithExtra(metadata={"session_id": session_id}) chat_completion_request(messages1, langsmith_extra=langsmith_extra) ```
Author
Owner

@gzrubio commented on GitHub (Apr 9, 2025):

Hi @angus-langchain thanks for the working example :)

I am not 100% sure but I believe the docs have changed since I opened this, so it all looks clear to me. Feel free to close this issue now.

Thanks for the help!

@gzrubio commented on GitHub (Apr 9, 2025): Hi @angus-langchain thanks for the working example :) I am not 100% sure but I believe the docs have changed since I opened this, so it all looks clear to me. Feel free to close this issue now. Thanks for the help!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langsmith-docs#46