Build an Observability Pipeline with OpenTelemetry & Loki
Read this article in clean Markdown format for LLMs and AI context.If you’re drowning in disconnected logs and missing traces, this guide shows exactly how to create a unified observability pipeline with OpenTelemetry and Loki—no fluff, just copy‑paste‑ready steps that get you from zero to a searchable, single‑pane‑of‑glass view in minutes.
Why the Chaos Happens
Running separate tools for logs and traces forces you to jump between dashboards, copy timestamps, and still miss the context that ties a log line to a request. The result? Slower root‑cause analysis and endless frustration. OpenTelemetry solves this by emitting logs and traces from the same SDK, while Loki stores them side‑by‑side for instant correlation.
Quick‑Start Setup (Copy‑Paste Ready)
1. Install the OpenTelemetry SDK
For a Node.js service, run:
npm install @opentelemetry/api @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node
2. Initialize the SDK with OTLP exporters
Add the following to your entry file (e.g., index.js):
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
const { OTLPLogExporter } = require('@opentelemetry/exporter-logs-otlp-http');
const { LoggerProvider, BatchLogRecordProcessor } = require('@opentelemetry/sdk-logs-node');
const sdk = new NodeSDK({
traceExporter: new OTLPTraceExporter({ url: 'http://localhost:4318/v1/traces' }),
instrumentations: [getNodeAutoInstrumentations()],
logExporter: new OTLPLogExporter({ url: 'http://localhost:4318/v1/logs' }),
});
sdk.start();
const loggerProvider = new LoggerProvider();
loggerProvider.addLogRecordProcessor(
new BatchLogRecordProcessor(new OTLPLogExporter({ url: 'http://localhost:4318/v1/logs' }))
);
What this does: It configures both tracing and logging exporters to point at an OTLP endpoint that Loki (via Tempo) will ingest.
3. Spin up Loki and Promtail with Docker Compose
Create a docker-compose.yml file:
version: "3"
services:
loki:
image: grafana/loki:latest
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
promtail:
image: grafana/promtail:latest
volumes:
- /var/log:/var/log
- ./promtail-config.yaml:/etc/promtail/config.yaml
Key point: Promtail tails your application logs and forwards them to Loki over HTTP, while the OTLP exporter sends traces to the same Loki instance (or to Tempo, which Grafana can query alongside Loki).
4. Visualize in Grafana
- Open Grafana → Add data source → select Loki (and Tempo if you separated traces).
- In Explore, pick Loki logs, click a
trace_idfield, and the corresponding trace appears instantly.
Now you have centralized logging and tracing—a single pane of glass for debugging.
Scaling the Pipeline Across Microservices
Treat every service the same way:
- Install the OpenTelemetry SDK for the language you use.
- Configure the OTLP exporter to point at your shared Loki/Tempo endpoint.
- Enable auto‑instrumentations so incoming requests, outbound calls, and database queries are captured automatically.
This pattern eliminates the need for manual instrumentation in each service and doubles as a complete OpenTelemetry tracing tutorial for microservice architectures.
Benefits You’ll See Immediately
- Half the debugging time – logs and traces appear together, so you never chase a missing piece again.
- Reduced operational stress – one configuration, one backend, one UI.
- Faster deployments – confidence that any issue is instantly observable.
Wrap‑Up
By unifying logs and traces with OpenTelemetry and Loki, you transform a chaotic, fragmented observability stack into a clean, searchable pipeline that accelerates root‑cause analysis and boosts team productivity. Try the snippets above, adapt them to your stack, and experience the difference for yourself.
If this guide helped, share it with a teammate stuck in the log‑trace nightmare, and stay tuned for more no‑fluff DevOps tutorials.
- →
- →
- →