This library provides OpenTelemetry instrumentation for applications built with LangChain, enabling comprehensive tracing of LLM interactions and associated components. It is part of the OpenLLMetry project, which extends OpenTelemetry for enhanced LLM observability. The project maintains a rapid release cadence, with frequent updates often driven by advancements in OpenTelemetry's Generative AI semantic conventions.
pip install opentelemetry-instrumentation-langchainVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instrument a basic LangChain application using `opentelemetry-instrumentation-langchain`. It includes the necessary OpenTelemetry SDK setup with a `ConsoleSpanExporter` to print traces to the console, followed by the `LangchainInstrumentor().instrument()` call. A simple LangChain expression language (LCEL) chain is then invoked to generate a story, and its execution will be automatically traced by OpenTelemetry.
Review the release notes and official OpenTelemetry Generative AI semantic conventions documentation when upgrading. You may need to update dashboards, queries, and custom processors that rely on specific span attributes. Using `OTEL_SEMCONV_STABILITY_OPT_IN=latest` can help with migration during transitions.
To disable the logging of content for privacy reasons, set the environment variable `TRACELOOP_TRACE_CONTENT` to `false`. `os.environ['TRACELOOP_TRACE_CONTENT'] = 'false'`.
Ensure you configure the OpenTelemetry SDK before instrumenting. This involves setting up a `TracerProvider`, adding a `SpanProcessor` (e.g., `BatchSpanProcessor` for production), and configuring an appropriate `SpanExporter` (e.g., `OTLPSpanExporter` to send to a collector).