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.
Before you start
Section titled “Before you start”- 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.
1. Create a Mibo API key
Section titled “1. Create a Mibo API key”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.
2. Install the packages
Section titled “2. Install the packages”uv venv --python 3.14uv 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.23. Configure the export
Section titled “3. Configure the export”Set these values in the same shell. Replace the two placeholders.
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/tracesexport OTEL_SERVICE_NAME=langsmith-supportexport LANGSMITH_TRACING=trueexport LANGSMITH_TRACING_MODE=otelLANGSMITH_TRACING_MODE=otelsends traces only to your OpenTelemetry exporter and not to LangSmith.hybridsends to both. LangSmith’s olderLANGSMITH_OTEL_ENABLEDandLANGSMITH_OTEL_ONLYvariables are legacy variables that still work.OTEL_SERVICE_NAMEsets theservice.nameresource 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.
4. Send your first trace
Section titled “4. Send your first trace”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 SystemMessagefrom langchain_core.tools import toolfrom langchain_openai import ChatOpenAIfrom langgraph.graph import START, MessagesState, StateGraphfrom langgraph.prebuilt import ToolNode, tools_conditionfrom langsmith.run_trees import get_cached_clientfrom opentelemetry import tracefrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporterfrom opentelemetry.sdk.resources import Resourcefrom opentelemetry.sdk.trace import TracerProviderfrom 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)
@tooldef 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.
uv run --no-project python support.pyThe 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.
5. Create your first test
Section titled “5. Create your first test”- Wait for the trace to finish, then click Create test from this trace.
- Set Name to
Looks up the orderand clear Checks a trace when so the test checks each new trace for this Agent. - Keep the Tool call check, with Tool name
lookup_orderand Must call. Remove the other checks and click Save test. - Run the script again. The new trace shows the result under Test results.
What Mibo reads from the trace
Section titled “What Mibo reads from the trace”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.
Troubleshooting
Section titled “Troubleshooting”| 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. |
What’s next
Section titled “What’s next”- LangGraph quickstart for the OpenInference route.
- OpenTelemetry (OTLP) for routing, batching, and response codes.
- Assertion reference for checks you can add to your test.