> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inference.net/llms.txt
> Use this file to discover all available pages before exploring further.

# LangSmith Traces

> Bridge LangSmith OpenTelemetry spans into the Catalyst tracer provider.

If your application already uses LangSmith tracing, Catalyst can bridge
LangSmith OpenTelemetry spans into the Catalyst tracer provider. This keeps
LangSmith `traceable` functions and framework integrations visible with the rest
of your application traces.

If a LangSmith-traced function is the boundary of an agent run, add an outer
`agentSpan()` / `agent_span()` with a stable `agent.id`. LangSmith spans remain
visible under that AGENT span.

## Install

<CodeGroup>
  <Metadata text="integrations/traces/langsmith-install-typescript" />

  ```bash TypeScript theme={"system"}
  bun add @inference/tracing langsmith
  ```

  <Metadata text="integrations/traces/langsmith-install-python" />

  ```bash Python theme={"system"}
  pip install 'inference-catalyst-tracing[langsmith]'
  ```
</CodeGroup>

## TypeScript Traceable Function

<Metadata text="integrations/traces/langsmith-traceable-ts" />

```typescript TypeScript theme={"system"}
import { setup } from "@inference/tracing";
import { Client } from "langsmith";
import { traceable } from "langsmith/traceable";

process.env.LANGSMITH_TRACING = "true";
process.env.LANGSMITH_TRACING_MODE = "otel";

const tracing = await setup({ serviceName: "langsmith-worker" });
const client = new Client({ tracingMode: "otel" });

const answerQuestion = traceable(
  async (input: { question: string }) => ({
    answer: input.question.toUpperCase(),
  }),
  {
    name: "answerQuestion",
    run_type: "tool",
    client,
    tracer: tracing.provider.getTracer("langsmith-app"),
  },
);

console.log(await answerQuestion({ question: "hi" }));
await client.flush();
await tracing.shutdown();
```

## Python Traceable Function

<Metadata text="integrations/traces/langsmith-traceable-python" />

```python Python theme={"system"}
import os

from inference_catalyst_tracing import setup
from langsmith import Client, traceable

os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_TRACING_MODE"] = "otel"

tracing = setup(service_name="langsmith-worker")
client = Client()

@traceable(name="answer_question", run_type="tool", client=client, enabled=True)
def answer_question(question: str) -> str:
    return question.upper()

print(answer_question("hi"))
client.flush()
tracing.shutdown()
```

## Hybrid Mode

If `LANGSMITH_TRACING=true` is set and `LANGSMITH_TRACING_MODE` is not set,
Catalyst defaults LangSmith to `hybrid` mode. That keeps existing LangSmith
tracing active while also routing OpenTelemetry spans through Catalyst.

<Metadata text="integrations/traces/langsmith-hybrid-mode" />

```bash theme={"system"}
export LANGSMITH_TRACING=true
# Catalyst sets LANGSMITH_TRACING_MODE=hybrid when unset.
```

## Stable Agent Identity

Use this pattern around LangSmith-traced work when you want the Agents dashboard
to group executions by your product agent ID.

<CodeGroup>
  <Metadata text="integrations/traces/langsmith-agent-identity-ts" />

  ```typescript TypeScript theme={"system"}
  import { agentSpan } from "@inference/tracing";

  await agentSpan(
    {
      agentId: "question-answer-agent",
      agentName: "Question Answer Agent",
      spanName: "question-answer.run",
      sessionId: "conversation-qa-1",
      role: "qa",
      system: "langsmith",
    },
    async (span) => {
      const input = { question: "hi" };
      span.setInput(input);
      const output = await answerQuestion(input);
      span.setOutput(output);
    },
  );
  ```

  <Metadata text="integrations/traces/langsmith-agent-identity-python" />

  ```python Python theme={"system"}
  from inference_catalyst_tracing import agent_span

  with agent_span(
      tracing.tracer,
      agent_id="question-answer-agent",
      agent_name="Question Answer Agent",
      span_name="question-answer.run",
      session_id="conversation-qa-1",
      agent_role="qa",
      system="langsmith",
  ) as span:
      question = "hi"
      span.set_input(question)
      answer = answer_question(question)
      span.set_output(answer)
  ```
</CodeGroup>
