> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-javaex-1765204202-a1f8093.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Log traces to a specific project

You can change the destination project of your traces both statically through environment variables and dynamically at runtime.

## Set the destination project statically

As mentioned in the [Tracing Concepts](/langsmith/observability-concepts#projects) section, LangSmith uses the concept of a `Project` to group traces. If left unspecified, the project is set to `default`. You can set the `LANGSMITH_PROJECT` environment variable to configure a custom project name for an entire application run. This should be done before executing your application.

```
export LANGSMITH_PROJECT=my-custom-project
```

<Warning>
  The `LANGSMITH_PROJECT` flag is only supported in JS SDK versions >= 0.2.16, use `LANGCHAIN_PROJECT` instead if you are using an older version.
</Warning>

If the project specified does not exist, it will be created automatically when the first trace is ingested.

## Set the destination project dynamically

You can also set the project name at program runtime in various ways, depending on how you are [annotating your code for tracing](/langsmith/annotate-code). This is useful when you want to log traces to different projects within the same application.

<Note>
  Setting the project name dynamically using one of the below methods overrides the project name set by the `LANGSMITH_PROJECT` environment variable.
</Note>

<CodeGroup>
  ```python Python theme={null}
  import openai
  from langsmith import traceable
  from langsmith.run_trees import RunTree

  client = openai.Client()
  messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ]

  # Use the @traceable decorator with the 'project_name' parameter to log traces to LangSmith
  # Ensure that the LANGSMITH_TRACING environment variables is set for @traceable to work
  @traceable(
    run_type="llm",
    name="OpenAI Call Decorator",
    project_name="My Project"
  )
  def call_openai(
    messages: list[dict], model: str = "gpt-4o-mini"
  ) -> str:
    return client.chat.completions.create(
        model=model,
        messages=messages,
    ).choices[0].message.content

  # Call the decorated function
  call_openai(messages)

  # You can also specify the Project via the project_name parameter
  # This will override the project_name specified in the @traceable decorator
  call_openai(
    messages,
    langsmith_extra={"project_name": "My Overridden Project"},
  )

  # The wrapped OpenAI client accepts all the same langsmith_extra parameters
  # as @traceable decorated functions, and logs traces to LangSmith automatically.
  # Ensure that the LANGSMITH_TRACING environment variables is set for the wrapper to work.
  from langsmith import wrappers
  wrapped_client = wrappers.wrap_openai(client)
  wrapped_client.chat.completions.create(
    model="gpt-4o-mini",
    messages=messages,
    langsmith_extra={"project_name": "My Project"},
  )

  # Alternatively, create a RunTree object
  # You can set the project name using the project_name parameter
  rt = RunTree(
    run_type="llm",
    name="OpenAI Call RunTree",
    inputs={"messages": messages},
    project_name="My Project"
  )
  chat_completion = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=messages,
  )
  # End and submit the run
  rt.end(outputs=chat_completion)
  rt.post()
  ```

  ```typescript TypeScript theme={null}
  import OpenAI from "openai";
  import { traceable } from "langsmith/traceable";
  import { wrapOpenAI } from "langsmith/wrappers";
  import { RunTree} from "langsmith";

  const client = new OpenAI();
  const messages = [
    {role: "system", content: "You are a helpful assistant."},
    {role: "user", content: "Hello!"}
  ];

  const traceableCallOpenAI = traceable(async (messages: {role: string, content: string}[], model: string) => {
    const completion = await client.chat.completions.create({
        model: model,
        messages: messages,
    });
    return completion.choices[0].message.content;
  },{
    run_type: "llm",
    name: "OpenAI Call Traceable",
    project_name: "My Project"
  });

  // Call the traceable function
  await traceableCallOpenAI(messages, "gpt-4o-mini");

  // Create and use a RunTree object
  const rt = new RunTree({
    run_type: "llm",
    name: "OpenAI Call RunTree",
    inputs: { messages },
    project_name: "My Project"
  });

  await rt.postRun();

  // Execute a chat completion and handle it within RunTree
  const chatCompletion = await client.chat.completions.create({
    model: "gpt-4o-mini",
    messages: messages,
  });
  rt.end({outputs: chatCompletion});
  await rt.patchRun();
  ```

  ```java Java theme={null}
  import com.langchain.smith.client.LangsmithClient;
  import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
  import com.langchain.smith.core.JsonValue;
  import com.langchain.smith.models.runs.RunCreate;
  import com.langchain.smith.wrappers.openai.OpenTelemetryConfig;
  import com.langchain.smith.wrappers.openai.WrappedOpenAIClient;
  import com.openai.models.ChatModel;
  import com.openai.models.chat.completions.ChatCompletion;
  import com.openai.models.chat.completions.ChatCompletionCreateParams;
  import java.time.Instant;
  import java.util.Map;
  import java.util.UUID;

  public class ProjectTracing {
      public static void main(String[] args) {
          // Method 1: Set project via environment variable (recommended)
          // export LANGSMITH_PROJECT=my-custom-project

          // Method 2: Set project dynamically via OpenTelemetryConfig
          OpenTelemetryConfig.builder()
              .fromEnv()
              .projectName("My Project")  // Override the env var
              .build();

          WrappedOpenAIClient client = WrappedOpenAIClient.fromEnv();

          // Make calls - they'll be logged to "My Project"
          ChatCompletion completion = client.chat().completions().create(
              ChatCompletionCreateParams.builder()
                  .model(ChatModel.GPT_4O_MINI)
                  .addSystemMessage("You are a helpful assistant.")
                  .addUserMessage("Hello!")
                  .build()
          );

          // Method 3: Use REST API with sessionName parameter
          LangsmithClient lsClient = LangsmithOkHttpClient.fromEnv();

          UUID runId = UUID.randomUUID();
          lsClient.runs().create(RunCreate.builder()
              .id(runId)
              .name("OpenAI Call")
              .runType(RunCreate.RunType.LLM)
              .inputs(JsonValue.from(Map.of("messages", "Hello!")))
              .startTime(Instant.now())
              .sessionName("My Project")  // Specify project here
              .build());

          System.out.println("Traces logged to project: My Project");
          OpenTelemetryConfig.flush(5, java.util.concurrent.TimeUnit.SECONDS);
      }
  }
  ```
</CodeGroup>

***

<Callout icon="pen-to-square" iconType="regular">
  [Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/langsmith/log-traces-to-project.mdx)
</Callout>

<Tip icon="terminal" iconType="regular">
  [Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
</Tip>
