Instrument Node.js Apps with Azure Monitor
TypeScript skill for auto-instrumenting Node.js apps with Azure Monitor OpenTelemetry - traces, metrics, and logs.
Why it matters
Automatically instrument your Node.js applications to capture distributed tracing, metrics, and logs. Gain deep visibility into your application's performance and behavior within Azure Monitor.
Outcomes
What it gets done
Auto-instrument Node.js applications for distributed tracing.
Collect and export application metrics to Azure Monitor.
Ingest application logs for centralized analysis.
Configure custom instrumentation and sampling strategies.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-azure-monitor-opentelemetry-ts | bash Overview
Azure Monitor OpenTelemetry SDK for TypeScript
TypeScript skill for Azure Monitor OpenTelemetry, covering zero-code auto-instrumentation via useAzureMonitor, custom trace/metric emission with the OpenTelemetry API, manual exporter wiring, custom logs ingestion, span-level enrichment, sampling control, and graceful shutdown. Use when adding distributed tracing, metrics, and log collection to a Node.js application reporting to Azure Monitor/Application Insights.
What it does
This skill auto-instruments Node.js applications with distributed tracing, metrics, and logs sent to Azure Monitor (Application Insights) using @azure/monitor-opentelemetry, the recommended "distro" package for zero-code auto-instrumentation, with @azure/monitor-opentelemetry-exporter available for lower-level custom OpenTelemetry setups and @azure/monitor-ingestion for custom logs ingestion. The critical setup rule is calling useAzureMonitor({ azureMonitorExporterOptions: { connectionString } }) before importing any other application modules (including the framework itself, e.g. Express), so instrumentation hooks are installed before those modules load; for ESM projects on Node.js 18.19+, this is done instead via a --import @azure/monitor-opentelemetry/loader flag. Full configuration covers offline storage (a local directory buffering telemetry when disconnected, toggleable), a samplingRatio (0-1) for high-traffic trace volume control, feature toggles (enableLiveMetrics, enableStandardMetrics, enablePerformanceCounters), per-library instrumentation toggles (Azure SDK, HTTP, MongoDB, MySQL, PostgreSQL, and Redis enabled by default; Bunyan and Winston logging disabled by default), and a custom resource via resourceFromAttributes (e.g. setting service.name). Custom traces use the OpenTelemetry API directly (trace.getTracer โ startSpan, setting attributes, adding events, recording exceptions with a status code, then ending the span), and custom metrics cover a Counter (e.g. request totals with route/method labels), a Histogram (e.g. request duration), and an ObservableGauge with a polling callback (e.g. active connections). For fully manual setups bypassing the distro, AzureMonitorTraceExporter/AzureMonitorMetricExporter/AzureMonitorLogExporter wire directly into OpenTelemetry SDK providers (NodeTracerProvider with a BatchSpanProcessor, MeterProvider with a PeriodicExportingMetricReader, LoggerProvider with a BatchLogRecordProcessor). Separately, LogsIngestionClient uploads arbitrary custom log records to a Data Collection Endpoint/Rule and custom stream name, with isAggregateLogsUploadError distinguishing partial upload failures and surfacing exactly which log entries failed. A custom SpanProcessor example shows enriching spans with custom dimensions on onEnd and filtering out INTERNAL-kind spans by clearing their trace flags. Sampling can also be controlled directly via ApplicationInsightsSampler (e.g. sampling 75% of traces) passed to a NodeTracerProvider. Graceful shutdown flushes buffered telemetry via shutdownAzureMonitor(), typically wired to a SIGTERM handler.
When to use - and when NOT to
Use this skill when adding distributed tracing, metrics, and log collection to a Node.js/TypeScript application reporting to Azure Monitor/Application Insights - whether via zero-code auto-instrumentation or fully custom OpenTelemetry pipeline wiring. It is not for applications reporting to a non-Azure observability backend (though the underlying OpenTelemetry API code is portable, the exporters here are Azure Monitor-specific), and the auto-instrumentation approach requires useAzureMonitor() to run before any instrumented library is imported - getting that ordering wrong silently loses instrumentation coverage.
Inputs and outputs
Input is an Application Insights connection string, sampling/feature configuration, and application code emitting spans/metrics/logs (auto-instrumented or manual). Output is traces, metrics, and logs exported to Azure Monitor, plus live metrics and standard performance counters when enabled.
Integrations
Built on @azure/monitor-opentelemetry (auto-instrumentation distro) and @azure/monitor-opentelemetry-exporter (manual exporters), layered on the OpenTelemetry JS SDK and API, with @azure/monitor-ingestion's LogsIngestionClient for custom log data reporting to a Data Collection Rule.
npm install @azure/monitor-opentelemetry
Who it's for
Node.js/TypeScript developers instrumenting an application for observability in Azure Monitor/Application Insights, from zero-code auto-instrumentation to fully custom trace/metric/log pipelines, including custom log streams (e.g. a Custom-MyTable_CL stream name) uploaded to a Data Collection Rule.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.