@sophonz/instrumentation-node-exception
v0.0.8
Published
Readme
@sophonz/instrumentation-node-exception
OpenTelemetry instrumentation for exception handling in Node.js with framework integrations.
Part of the Sophonz OpenTelemetry suite.
Install
bun add @sophonz/instrumentation-node-exception
# or
pnpm add @sophonz/instrumentation-node-exception
# or
npm install @sophonz/instrumentation-node-exceptionUsage
import {
recordException,
setupExpressErrorHandler,
setupKoaErrorHandler,
} from '@sophonz/instrumentation-node-exception';
// Record an exception manually
try {
throw new Error('Something went wrong');
} catch (error) {
recordException(error as Error);
}
// Express error handler
import express from 'express';
const app = express();
setupExpressErrorHandler(app);
// Koa error handler
import Koa from 'koa';
const koaApp = new Koa();
setupKoaErrorHandler(koaApp);API
ExceptionInstrumentation- Main instrumentation classrecordException(error: Error)- Record an exception as a spansetupExpressErrorHandler(app: Express)- Attach error handler to Express appsetupKoaErrorHandler(app: Koa)- Attach error handler to Koa app
Peer dependencies
@opentelemetry/api@opentelemetry/instrumentation@sentry/core
License
See LICENSE in this package.
Part of sophonz-js.
