In an agent-based workspace, create an agent once before sending traces. Use agent addressing to select its identifier and environment. If an integration requires
project_name, use the selected environment’s tracer_session_name as a compatibility value.Prerequisites
Both approaches require the following environment variables. SetOTEL_EXPORTER_OTLP_ENDPOINT to the address of your collector:
LANGSMITH_AGENT_ID and LANGSMITH_AGENT_ENVIRONMENT name the agent and environment the traces belong to. For more information, see Log traces to an agent.
Configure the collector
Both approaches also require an OpenTelemetry collector running as an intermediary between your agent and LangSmith. The following configuration sets up an OTLP receiver on port4318, a transform processor that redacts the gen_ai.prompt and gen_ai.completion span attributes, and an exporter that forwards the sanitized traces to the LangSmith API:
LANGSMITH_API_KEY, LANGSMITH_AGENT_ID, and LANGSMITH_AGENT_ENVIRONMENT from its own environment, not from your application’s. Set them where the collector runs, along with LANGSMITH_TENANT_ID if your API key is not scoped to a specific workspace.
Send traces to an agent
The collector, not your application, decides which agent and environment receive the traces. The collector sends its own headers to LangSmith and does not forward the headers your application sends by default. Theotlphttp/langsmith exporter in the preceding configuration sets both agent headers:
Langsmith-Agent-Id: The identifier of the agent. It must be 1 to 63 lowercase letters, digits, or hyphens, start with a letter, and end with a letter or digit.Langsmith-Agent-Environment: The environment the traces belong to. One oflocal,development,staging, orproduction.
Langsmith-Project, with a 400 error.
The headers apply to every span the exporter sends. To send traces to more than one agent or environment, define one exporter for each, and route each agent’s spans to its exporter. Span attributes, including gen_ai.agent.name, do not send traces to an agent. To learn more about sending traces to an agent, see Log traces to an agent.
Trace with LangChain, LangGraph, or Deep Agents
Use this approach if your agent already uses LangChain, LangGraph, or Deep Agents. The tracing integration handles span creation automatically based on your environment variables, so no additional instrumentation code is required:Trace with the OpenTelemetry SDK directly
Use this approach if you need programmatic control over the tracer provider and exporter, such as which span processors run or where the exporter sends spans. You configure the provider explicitly in code rather than relying on environment variables alone. The collector’s exporter, not your code, decides which agent receives the traces:If you prefer to redact sensitive data without routing through a collector, see Prevent logging of sensitive data in traces.
Connect these docs to your agent of choice via MCP for real-time answers.

