Hello, I want to send traces and metrics (if it has) of my LangChain apps to the back-end OpenTelemetry Collector along with other apps. This time I do not want to install a local LangSmith server. Is it possible?
hi @liurui-1
try to install langsmith[otel], then set:
LANGSMITH_OTEL_ENABLED=true
LANGSMITH_OTEL_ONLY=true # skip LangSmith writer entirely
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
- LANGSMITH_OTEL_ONLY=true makes the SDK’s background thread bypass the LangSmith ingest path - spans go only to OTLP
(langsmith/_internal/_background_thread.py::get_tracing_mode, lines 574–594). - OTEL_EXPORTER_OTLP_ENDPOINT is read before the default LangSmith endpoint is injected (_internal/otel/_otel_client.py::get_otlp_tracer_provider), so your collector
replaces api.smith.langchain.com/otel. No LANGSMITH_API_KEY required. - Caveat worth flagging to the OP: LangSmith’s OTEL bridge emits traces only, not OTLP metrics - token/latency data arrives as span attributes. For real metric instruments,
use the OTEL metrics SDK separately.
Hi @pawel-twardziak , Thanks a lot! Your answer works. One thing I see is that environment variable “LANGSMITH_TRACING=true” is still required.
The environment variables I’m using are:
export LANGSMITH_TRACING=true
export LANGSMITH_OTEL_ENABLED=true
export LANGSMITH_OTEL_ONLY=true
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
export LS_APM_OTEL_ENABLED=true
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_SERVICE_NAME=mylangchain