Lab 13: Observability
Overview
Step 1: OpenTelemetry TypeScript Setup
// src/telemetry/sdk.ts
import { NodeSDK } from '@opentelemetry/sdk-node';
import { Resource } from '@opentelemetry/resources';
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
const sdk = new NodeSDK({
resource: new Resource({
[ATTR_SERVICE_NAME]: 'my-service',
[ATTR_SERVICE_VERSION]: '1.0.0',
'deployment.environment': process.env.NODE_ENV,
}),
traceExporter: new OTLPTraceExporter({
url: 'http://otel-collector:4318/v1/traces',
}),
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: 'http://otel-collector:4318/v1/metrics',
}),
exportIntervalMillis: 30_000,
}),
});
sdk.start();
process.on('SIGTERM', () => sdk.shutdown());Step 2: Typed Spans
Step 3: AsyncLocalStorage for Request Context
Step 4: Pino — Type-Safe Structured Logging
Step 5: Typed Metrics
Step 6: Distributed Tracing — Context Propagation
Step 7: Error Tracking with Types
Step 8: Capstone — OpenTelemetry Typed Spans
Summary
Tool
Type Feature
Benefit
Last updated
