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

# LangSmith Via OpenInference

> Send spans from a web-search stock-news agent to the LangSmith EU OTLP endpoint using the OpenInference Agno instrumentor with API-key and project headers.

Demonstrates instrumenting an Agno agent with OpenInference and sending traces to LangSmith.

```python langsmith_via_openinference.py theme={null}
"""
LangSmith Via OpenInference
===========================

Demonstrates instrumenting an Agno agent with OpenInference and sending traces to LangSmith.
"""

import os

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.websearch import WebSearchTools
from openinference.instrumentation.agno import AgnoInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
endpoint = "https://eu.api.smith.langchain.com/otel/v1/traces"
headers = {
    "x-api-key": os.getenv("LANGSMITH_API_KEY"),
    "Langsmith-Project": os.getenv("LANGSMITH_PROJECT"),
}

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

# Start instrumenting agno
AgnoInstrumentor().instrument(tracer_provider=tracer_provider)


# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    name="Stock Market Agent",
    model=OpenAIChat(id="gpt-4o-mini"),
    tools=[WebSearchTools()],
    markdown=True,
    debug_mode=True,
)


# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What is news on the stock market?")
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno ddgs openai openinference-instrumentation-agno opentelemetry-exporter-otlp opentelemetry-sdk
    ```
  </Step>

  <Step title="Export environment variables">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export LANGSMITH_API_KEY="your_langsmith_api_key_here"
      export LANGSMITH_PROJECT="your_langsmith_project_here"
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:LANGSMITH_API_KEY="your_langsmith_api_key_here"
      $Env:LANGSMITH_PROJECT="your_langsmith_project_here"
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `langsmith_via_openinference.py`, then run:

    ```bash theme={null}
    python langsmith_via_openinference.py
    ```
  </Step>
</Steps>

Full source: [cookbook/observability/langsmith\_via\_openinference.py](https://github.com/agno-agi/agno/blob/main/cookbook/observability/langsmith_via_openinference.py)
