Monitoring TypeScript Applications: Libraries, Tools, and Setup

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Monitoring TypeScript Applications: A Complete Guide to Tools and Libraries



Monitoring is an integral part of developing modern web applications in TypeScript. Without it, you are working blindly: errors go unnoticed, performance degrades, and users leave. In this article, we will break down the key libraries and tools for monitoring TypeScript applications, including Sentry, OpenTelemetry, Prometheus, and built-in logging. You will learn how to set up error collection, metrics, and real-time tracing.



1. Sentry: Real-Time Error Tracking



Sentry is the most popular error monitoring platform. It supports TypeScript out of the box and allows you to catch exceptions, log execution context, and receive crash notifications.



Installation and Basic Setup



npm install @sentry/node @sentry/tracing


Example of initializing Sentry in a TypeScript application on Node.js:



import * as Sentry from "@sentry/node";import { ProfilingIntegration } from "@sentry/profiling-node";

Sentry.init({ dsn: "https://examplePublicKey@o0.ingest.sentry.io/0", integrations: [ new ProfilingIntegration(), ], tracesSampleRate: 1.0, profilesSampleRate: 1.0,});

// Force sending an errorapp.get("/debug-sentry", function mainHandler(req, res) { throw new Error("Sentry test error!");});


Context Logging



Sentry allows you to add custom tags and context:



Sentry.setUser({ email: "user@example.com" });Sentry.setTag("environment", "production");Sentry.captureException(new Error("Error processing order"));


2. OpenTelemetry: Standard for Tracing and Metrics



OpenTelemetry is an open standard for collecting telemetry: traces, metrics, and logs. It supports TypeScript and integrates easily with any backends (Jaeger, Zipkin, Prometheus).



Installing Packages



npm install @opentelemetry/api @opentelemetry/sdk-node @opentelemetry/instrumentation-http @opentelemetry/instrumentation-express


Example of Tracing Setup



import { NodeSDK } from "@opentelemetry/sdk-node";import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-node";

const sdk = new NodeSDK({ traceExporter: new ConsoleSpanExporter(), instrumentations: [getNodeAutoInstrumentations()],});

sdk.start();


Now every HTTP request will be automatically wrapped in a span with metadata. You can add custom spans:



import { trace } from "@opentelemetry/api";

const tracer = trace.getTracer("my-service");

app.get("/api/data", async (req, res) => { const span = tracer.startSpan("processData"); try { const data = await fetchData(); span.setAttribute("data.size", data.length); res.json(data); } finally { span.end(); }});


3. Prometheus + express-prom-bundle: Metrics for Node.js



To collect performance metrics (RPS, response time, error count), use Prometheus together with the express-prom-bundle library. It automatically collects metrics from Express applications.



Installation



npm install prom-client express-prom-bundle


Example Setup



import express from "express";import promBundle from "express-prom-bundle";

const app = express();

const metricsMiddleware = promBundle({ includeMethod: true, includePath: true, includeStatusCode: true, customLabels: { project: "my-app" }, metricsPath: "/metrics",});

app.use(metricsMi

Recommendations