103 — OpenTelemetry Fundamentals

Beginner

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.

Learning Objectives

1
Understand the OpenTelemetry architecture (SDK, API, Collector)
2
Instrument a Node.js app with the OTel SDK
3
Configure trace and metric exporters to the OTel Collector
4
View auto-generated telemetry data in your observability stack
Step 1

Understand the OpenTelemetry architecture

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).

Commands to Run

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
EOF

What This Does

The 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.

Expected Outcome

You see the three OTel components printed with their responsibilities.

Pro Tips

  • 1
    The API + SDK separation means third-party libraries can be instrumented without depending on a specific backend
  • 2
    Your OTel Collector from Lesson 102 is already running and ready to receive data
  • 3
    If you stopped the lab since Lesson 102, restart it: cd ~/observability-lab && docker compose up -d

Common Mistakes to Avoid

  • ⚠️If your lab containers are not running, this lesson's hands-on steps will fail. Run 'docker compose ps' in ~/observability-lab/ to verify all three containers are Up
Was this step helpful?

All Steps (0 / 10 completed)