Node.js
Package for Express and Fastify
The official DockRay package for Node.js lets you integrate server-side Node.js applications with the DockRay monitoring platform. It enables exception and message reporting as well as HTTP request performance monitoring.
Error and Exception Monitoring
DockRay allows you to report caught exceptions and custom messages directly to the monitoring dashboard.
Reported events can include:
- the error type and message,
- where the error occurred and the stack trace,
- environment and application version information,
- context related to the request being processed.
The package can also capture unhandled Node.js process errors. This feature is optional because it affects how your application handles critical errors.
Express and Fastify
DockRay provides ready-made integrations for Express and Fastify. They automatically monitor HTTP transactions and report errors that occur while processing requests.
Transactions are grouped by route pattern, allowing requests to the same route to be analyzed together regardless of the IDs passed in the URL.
Performance Monitoring
The package can measure HTTP request processing times and send transaction data to DockRay. The frequency of data collection can be controlled using a sampling rate.
The ready-made integrations exclude paths such as /health and /metrics by default.
Browser JavaScript Error Monitoring
DockRay also allows you to forward JavaScript errors from the browser through your own Node.js application. Your project’s private key remains on the server and is never exposed in the website’s client-side code.
Safe Reporting
Problems with the monitoring service do not cause additional exceptions in the monitored application. Network errors and rejected events are handled by the DockRay client.
Sensitive headers such as Authorization, Cookie, and X-Api-Key are removed from data reported by the ready-made HTTP integrations.
Built for Server-Side Applications
DockRay is designed for server-side applications and requires Node.js 18 or later. The package has no additional dependencies and uses the built-in fetch API.
Installation
Package Installation
Install DockRay using npm:
npm install @dockcodes/dock-ray
The package requires Node.js 18 or later.
Configuration
Create a DockRay client using your project token and private key:
import { DockRayClient } from '@dockcodes/dock-ray';
const ray = new DockRayClient({
token: process.env.RAY_TOKEN,
privateKey: process.env.RAY_PRIVATE_KEY,
environment: process.env.NODE_ENV,
release: process.env.APP_VERSION,
});
You can find your project token and private key in the DockRay dashboard.
If the client is created without credentials, it will remain inactive and will not make any connections to the monitoring platform.
When shutting down your application, call await ray.close() to complete pending operations and send any queued events.