Instrument a Node.js application with the OpenTelemetry SDK. You'll learn the OTel architecture, add auto-instrumentation for traces and metrics, configure exporters to send data to your OTel Collector, and see real telemetry flowing through your observability stack. Starting state: ~/observability-lab/ running from Lesson 102 (Prometheus, Grafana, OTel Collector). After this lesson: a demo Node.js app at ~/observability-lab/app/ sending metrics and traces to your stack.
Before writing code, understand the three core components of OpenTelemetry: the API (defines instrumentation interfaces), the SDK (implements the API and handles telemetry processing), and the Collector (receives, processes, and exports telemetry).
cat <<'EOF'
=== OPENTELEMETRY COMPONENTS ===
1. OTel API
- Defines interfaces: TracerProvider, MeterProvider
- Libraries instrument against the API
- No-op by default (zero overhead if SDK not installed)
2. OTel SDK
- Implements the API
- Handles sampling, batching, exporting
- Configured once at application startup
3. OTel Collector
- Standalone process (already running in your lab)
- Receives OTLP data, processes it, exports to backends
- Decouples apps from backend choices
EOFThe separation between API and SDK is a key design decision. Library authors instrument against the lightweight API, which does nothing unless an SDK is installed. Application developers install the SDK and configure where telemetry goes. This means you get instrumentation from third-party libraries (like Express, pg, redis) for free, without those libraries needing to know about your specific observability backend.
You see the three OTel components printed with their responsibilities.