Ir al contenido

Quickstart: LangSmith OpenTelemetry

Esta página aún no está disponible en tu idioma.

LangSmith’s Python SDK can export LangChain and LangGraph runs as OpenTelemetry spans. This page points that export at Mibo, so your agent’s runs become traces you can test. The example ran without a LangSmith account or API key.

If you use OpenInference to instrument LangChain, see the LangGraph quickstart instead.

  • A Mibo account with a verified email. Open the verification link in the browser you signed up with.
  • Python 3.14 and uv.
  • An OpenAI API key for the model in the example.

Mibo’s ingest checks use langsmith 0.14.17 with langgraph 1.2.20 and langchain-openai 1.7.4. Tested with Python 3.14.9 and the package versions pinned below.

If you own the workspace, create an API key in Settings and copy it. Mibo shows the key only once. If you’re a workspace member, ask the owner for a key.

Terminal window
uv venv --python 3.14
uv pip install "langsmith[otel]==0.14.17" langgraph==1.2.20 langchain-openai==1.7.4 \
opentelemetry-sdk==1.45.2 opentelemetry-exporter-otlp-proto-http==1.45.2

Set these values in the same shell. Replace the two placeholders.

Terminal window
export OPENAI_API_KEY='<YOUR_OPENAI_API_KEY>'
export MIBO_API_KEY='<YOUR_MIBO_API_KEY>'
export MIBO_OTLP_TRACES_ENDPOINT=https://api.mibo-ai.com/public/traces
export OTEL_SERVICE_NAME=langsmith-support
export LANGSMITH_TRACING=true
export LANGSMITH_TRACING_MODE=otel
  • LANGSMITH_TRACING_MODE=otel sends traces only to your OpenTelemetry exporter and not to LangSmith. hybrid sends to both. LangSmith’s older LANGSMITH_OTEL_ENABLED and LANGSMITH_OTEL_ONLY variables are legacy variables that still work.
  • OTEL_SERVICE_NAME sets the service.name resource attribute. With a workspace key, Mibo routes by that name and creates an Agent on the first trace if your plan has a free slot. See trace routing.

LangSmith’s own OTEL_EXPORTER_OTLP_ENDPOINT variable expects a base URL and appends /v1/traces. Pass Mibo’s endpoint and header to the exporter in code instead, as shown below, so a LangSmith export in the same process keeps its own settings.

Save the following as support.py. Register the tracer provider before you create any LangChain components. Flush the LangSmith client before the provider, because LangSmith hands spans to OpenTelemetry from a background queue.

import os
from langchain_core.messages import SystemMessage
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.graph import START, MessagesState, StateGraph
from langgraph.prebuilt import ToolNode, tools_condition
from langsmith.run_trees import get_cached_client
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
provider = TracerProvider(
resource=Resource.create({"service.name": os.environ["OTEL_SERVICE_NAME"]}),
)
provider.add_span_processor(
BatchSpanProcessor(
OTLPSpanExporter(
endpoint=os.environ["MIBO_OTLP_TRACES_ENDPOINT"],
headers={"x-api-key": os.environ["MIBO_API_KEY"]},
timeout=10,
)
)
)
trace.set_tracer_provider(provider)
@tool
def lookup_order(order_id: str) -> str:
"""Look up shipping status by order ID."""
return {"A-1042": "shipped"}.get(order_id, "unknown")
model = ChatOpenAI(model="gpt-5.4-mini", timeout=30, max_retries=1).bind_tools([lookup_order])
def agent(state: MessagesState) -> dict[str, object]:
system = SystemMessage("You are an order support assistant. Use lookup_order for order status.")
return {"messages": [model.invoke([system, *state["messages"]])]}
graph = StateGraph(MessagesState)
graph.add_node("agent", agent)
graph.add_node("tools", ToolNode([lookup_order]))
graph.add_edge(START, "agent")
graph.add_conditional_edges("agent", tools_condition)
graph.add_edge("tools", "agent")
app = graph.compile()
try:
result = app.invoke({"messages": [{"role": "user", "content": "What is the status of order A-1042?"}]})
print(result["messages"][-1].content)
finally:
get_cached_client().flush()
provider.force_flush()
provider.shutdown()

Run the script.

Terminal window
uv run --no-project python support.py

The script prints the model’s answer, which should mention that order A-1042 shipped. Open Traces, select the Agent by its current name, and find lookup_order under What the agent did. Select View raw trace data to see the attributes LangSmith exported.

  1. Wait for the trace to finish, then click Create test from this trace.
  2. Set Name to Looks up the order and clear Checks a trace when so the test checks each new trace for this Agent.
  3. Keep the Tool call check, with Tool name lookup_order and Must call. Remove the other checks and click Save test.
  4. Run the script again. The new trace shows the result under Test results.

Mibo identifies LangSmith spans by their langsmith.* attributes and the langsmith instrumentation scope. It adds standard GenAI attributes next to what you sent. Your original attributes stay as exported.

Data Source in the LangSmith export
User input and final reply gen_ai.prompt and gen_ai.completion, including LangChain message JSON
Tool name gen_ai.tool.name
Tool arguments and result gen_ai.prompt and gen_ai.completion on the tool span
Token usage gen_ai.usage.* attributes
Reasoning and cache-read tokens langsmith.metadata.usage_metadata
Images in messages image_url blocks, standard image blocks and Anthropic image sources become image parts

Mibo reads these dialect attributes only when the instrumentation records them. Check View raw trace data if a field is empty.

Problem Likely cause Solution
HTTP 401 Missing, invalid, or revoked key Set MIBO_API_KEY to an active key. An expired key returns API_KEY_EXPIRED.
404 or connection error Wrong host or path Set MIBO_OTLP_TRACES_ENDPOINT to https://api.mibo-ai.com/public/traces.
HTTP 400 with “OTLP traces need the ‘service.name’ resource attribute” The export has no service.name Set OTEL_SERVICE_NAME and pass it as a resource attribute as shown above.
Export fails with a gRPC transport error The exporter uses OTLP/gRPC Import the exporter from opentelemetry.exporter.otlp.proto.http.trace_exporter.
The script prints a reply but no trace appears Spans were buffered when the process exited, or the provider was registered after LangChain objects were created Register the provider first. Call get_cached_client().flush(), then provider.force_flush() and provider.shutdown() before exit.
Traces go to LangSmith and not to Mibo OpenTelemetry mode is off Set LANGSMITH_TRACING_MODE=otel.
403 AGENT_LIMIT_REACHED Your plan has reached its Agent limit See Agent limit reached.
HTTP 403 with “Monthly trace ingestion limit reached” The workspace used its monthly trace quota Wait for the next period or upgrade, then rerun the script.
HTTP 413 with “Trace payload too large (max 10 MB)” The batch exceeds 10 MB Reduce max_export_batch_size. See Payload size limits.
The trace is hidden or has no tool calls The export has no user input or reply Check your tracing settings and look for gen_ai.prompt in the raw trace data.