> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-docs-scavio-google-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LangSmith

> Send Agno traces to a LangSmith project with OpenInference and OpenTelemetry.

Send Agno agent traces to LangSmith through its OpenTelemetry endpoint.

## Prerequisites

1. **Create a LangSmith Account**

   * Sign up for an account at [LangSmith](https://smith.langchain.com).
   * Obtain your API key from the LangSmith dashboard.

2. **Set Environment Variables**

   ```bash theme={null}
   export LANGSMITH_API_KEY=<your-key>
   export LANGSMITH_ENDPOINT=https://eu.api.smith.langchain.com  # or https://api.smith.langchain.com for US
   export LANGSMITH_PROJECT=<your-project-name>
   export OPENAI_API_KEY=<your-openai-key>
   ```

3. **Install Dependencies**

   ```bash theme={null}
   uv pip install -U agno openai openinference-instrumentation-agno opentelemetry-sdk opentelemetry-exporter-otlp
   ```

## Sending Traces to LangSmith

```python langsmith_tracing.py theme={null}
import os

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.hackernews import HackerNewsTools
from openinference.instrumentation.agno import AgnoInstrumentor
from opentelemetry import trace as trace_api
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

langsmith_endpoint = os.environ["LANGSMITH_ENDPOINT"].rstrip("/")
endpoint = f"{langsmith_endpoint}/otel/v1/traces"
headers = {
    "x-api-key": os.environ["LANGSMITH_API_KEY"],
    "Langsmith-Project": os.environ["LANGSMITH_PROJECT"],
}

tracer_provider = TracerProvider()
tracer_provider.add_span_processor(
    SimpleSpanProcessor(OTLPSpanExporter(endpoint=endpoint, headers=headers))
)
trace_api.set_tracer_provider(tracer_provider=tracer_provider)

AgnoInstrumentor().instrument()

agent = Agent(
    name="Stock Market Agent",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[HackerNewsTools()],
    markdown=True,
    debug_mode=True,
)

agent.print_response("What is news on the stock market?")
```

## Run the Example

Save the code as `langsmith_tracing.py`, then run:

```bash theme={null}
python langsmith_tracing.py
```

## Data Region

Set `LANGSMITH_ENDPOINT` to the endpoint for your LangSmith data region. The code appends `/otel/v1/traces` to that value.
