This page covers trace and log instrumentation for LangChain applications using the OpenTelemetry Python SDK. TheDocumentation Index
Fetch the complete documentation index at: https://docs.bronto.io/llms.txt
Use this file to discover all available pages before exploring further.
opentelemetry-instrument wrapper automatically patches LangChain with zero code changes, exporting spans and logs to a local OTel Collector over OTLP/gRPC, which forwards them to Bronto.
Prerequisites
- Python 3.8 or later
- pip
- An LLM provider API key (e.g. OpenAI or Anthropic)
- A running OTel Collector configured to forward traces and logs to Bronto — see Connect Open Telemetry to Bronto
Install the OTel Collector (macOS)
Download and unpack the binary for your chip:On macOS, Gatekeeper may block the binary on first run. If so, go to System Settings → Privacy & Security and click Allow.
Configure the OTel Collector
Bronto requires a dedicated exporter for traces (otlphttp/brontotraces) separate from the logs exporter. Create an otel-config.yaml file in the same directory as the binary:
otel-config.yaml
<REGION> with your Bronto region (e.g. eu or us) and <YOUR_API_KEY> with a key from Account Management → API Keys.
| Header | Description |
|---|---|
x-bronto-api-key | Your Bronto ingestion API key |
x-bronto-dataset | Maps to the dataset name in Bronto |
x-bronto-collection | Groups related services — e.g. local-dev, production |
Install dependencies
Create a virtual environment and install the OpenTelemetry distribution alongside your LangChain provider package:| Package | Purpose |
|---|---|
opentelemetry-distro | OTel distribution — includes SDK and auto-instrumentation entry point |
opentelemetry-exporter-otlp | OTLP gRPC/HTTP exporter |
opentelemetry-instrumentation-langchain | Auto-patches LangChain with OTel spans |
Always run
opentelemetry-bootstrap -a install after adding new packages. It detects installed libraries and installs the matching OTel instrumentation packages automatically.Create a LangChain application
The example below creates a simple prompt → LLM → parser chain. No OTel imports are needed — theopentelemetry-instrument wrapper handles everything at runtime.
Run with auto-instrumentation
Set the required environment variables and run your app through theopentelemetry-instrument wrapper. This requires no changes to your application code:
| Environment variable | Value | Description |
|---|---|---|
OTEL_SERVICE_NAME | langchain-sample-app | Identifies your service in traces |
OTEL_EXPORTER_OTLP_ENDPOINT | http://localhost:4317 | Local Collector gRPC endpoint |
OTEL_EXPORTER_OTLP_PROTOCOL | grpc | Transport protocol |
OTEL_TRACES_EXPORTER | otlp | Enables trace export |
OTEL_LOGS_EXPORTER | otlp | Enables log export |
What gets captured
The LangChain instrumentation automatically captures spans for every step in the chain, following the OpenTelemetry Semantic Conventions for GenAI:| Span name | Description |
|---|---|
ChatOpenAI.invoke / ChatAnthropic.invoke | LLM call duration, model name, token counts |
ChatPromptTemplate.invoke | Prompt formatting step |
RunnableSequence.invoke | Full chain execution |
StrOutputParser.parse | Output parsing step |
gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, gen_ai.request.model, and the full prompt and completion content for debugging.
Add custom spans (optional)
Auto-instrumentation does not prevent you from adding your own spans. Reference the global tracer to wrap business logic with custom context:Verify in Bronto
After running your instrumented application, open the Search page in Bronto. Filter by the service name you set inOTEL_SERVICE_NAME — traces and logs should appear within a few seconds.
If no data appears, check:
- The OTel Collector is running and reachable on ports
4317(gRPC) and4318(HTTP). - Your
otel-config.yamlhas separate exporters for traces (otlphttp/brontotraces) and logs (otlphttp/bronto) — both must be wired into their respective pipelines. opentelemetry-bootstrap -a installwas run after installing LangChain — without this step, the LangChain instrumentation package may not be installed.- For short-lived scripts, the batch exporter may not flush before the process exits. Add a shutdown call to force a final flush:
Direct export to Bronto
If you are not using an OTel Collector, export traces and logs directly from your application to Bronto by setting the environment variables to point at the Bronto ingestion endpoints:| Region | Traces endpoint | Logs endpoint |
|---|---|---|
| EU | https://ingestion.eu.bronto.io/v1/traces | https://ingestion.eu.bronto.io/v1/logs |
| US | https://ingestion.us.bronto.io/v1/traces | https://ingestion.us.bronto.io/v1/logs |

