maple-agent-tracing-langchain

Installation
SKILL.md

Maple agent tracing: LangChain & LangGraph (Python and TypeScript)

Goal: every conversation = one Maple Agent Session. Each invoke()/stream() = one turn (one trace) with a readable transcript, chat model spans with tokens, tool spans with names/results, failed tools marked failed, sub-agents in their own lanes.

Mechanism: openinference-instrumentation-langchain (scope openinference.instrumentation.langchain). Maple groups sessions by the run's thread_id and reads transcript, tokens and tool calls from its spans. TraceConfig(enable_genai_semconv=True) is recommended: it also emits standard GenAI attributes (gen_ai.conversation.id from run metadata session_id > conversation_id > thread_id, gen_ai.input/output.messages in {role, parts} form).

TypeScript / JavaScript (LangChain.js, LangGraph.js): the JS instrumentor has no GenAI dual-write, so the setup adds a small span processor. Do Step 1 below for the key and region, then follow references/typescript.md instead of Steps 2-7. A repo with both Python and TS agents gets both setups.

Step 0: Detect

  1. Language: package.json depending on langchain, @langchain/core or @langchain/langgraph → TypeScript, see references/typescript.md (after Step 1). Python files importing langchain/langgraph → continue here.
  2. Versions: python -c "import langchain, langgraph, langchain_core; print(langchain.__version__, langchain_core.__version__)" and pip show langgraph (or read pyproject.toml / uv.lock / requirements*.txt). Tested: langchain 1.4.2, langgraph 1.2.12, langchain-core 1.6.5, langchain-openai 1.6.6, Python 3.12. Python must be >= 3.10.
  3. Existing OTel setup. Search for TracerProvider(, set_tracer_provider, logfire.configure, sentry_sdk.init, opentelemetry-instrument, Traceloop.init, LangChainInstrumentor, OpenAIInstrumentor, LANGSMITH_OTEL_ENABLED, LANGSMITH_TRACING_MODE.
    • A TracerProvider exists → add the processors from Step 2 to it; do NOT create a second provider.
    • LANGSMITH_OTEL_ENABLED/LANGSMITH_TRACING_MODE=otel set → it duplicates every run. Ask the user; remove it for Maple (plain LANGSMITH_TRACING=true to LangSmith cloud is fine to keep).
    • OpenAI/Anthropic OpenInference instrumentors or OpenLLMetry LangChain instrumentor → duplicate model spans. Ask before removing if they serve something else.
  4. Find: every create_agent(, create_react_agent(, StateGraph(/.compile(, every .invoke(/.ainvoke(/.stream(/.astream(/Command(resume= call on an agent/graph/chain, where the app's chat/thread id lives, every ChatOpenAI( (note base_url) and init_chat_model( / "openai:..." model string, and every tool that invokes another agent.
  5. LangGraph Server (langgraph.json present): import tracing at the top of the module(s) langgraph.json's graphs points to (the dir holding tracing.py must be in dependencies); OTEL_* env goes in the server env file/container. Server threads already carry configurable.thread_id: one Maple session per thread, no code.
Installs
5
GitHub Stars
1.9K
First Seen
Oct 8, 2026