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.

langsmith_via_openinference.py
"""
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-5.6-luna"),
    tools=[WebSearchTools()],
    markdown=True,
)


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

The source targets LangSmith's EU region. If your project is hosted elsewhere, replace endpoint with your deployment's OTLP HTTP trace endpoint from LangSmith's OpenTelemetry setup.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno ddgs openai openinference-instrumentation-agno opentelemetry-exporter-otlp opentelemetry-sdk

Export environment variables

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"

Run the example

Save the code above as langsmith_via_openinference.py, then run:

python langsmith_via_openinference.py

Full source: cookbook/observability/langsmith_via_openinference.py