Prerequisites
Both of the following approaches require the following environment variables. SetOTEL_EXPORTER_OTLP_ENDPOINT to the address of your collector:
LANGSMITH_PROJECT, refer to Log traces to a specific project.
Configure the collector
Both approaches also require an OpenTelemetry collector running as an intermediary between your application 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:
Trace with LangChain or LangGraph
Use this approach if your application already uses LangChain or LangGraph. 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. For example, to set per-request project names or configure custom headers at runtime. You configure the provider explicitly in code rather than relying on environment variables alone:If you prefer to redact sensitive data without routing through a collector, see Prevent logging of sensitive data in traces.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

