UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

64 lines (60 loc) 2.15 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const instrumentation = require('@opentelemetry/instrumentation'); const nodeCore = require('@sentry/node-core'); const core = require('@sentry/core'); const debugBuild = require('../../debug-build.js'); const setHttpServerSpanRouteAttribute = require('../../utils/setHttpServerSpanRouteAttribute.js'); const INTEGRATION_NAME = "Express"; const SUPPORTED_VERSIONS = [">=4.0.0 <6"]; function setupExpressErrorHandler(app, options) { core.setupExpressErrorHandler(app, options); nodeCore.ensureIsWrapped(app.use, "express"); } const instrumentExpress = nodeCore.generateInstrumentOnce( INTEGRATION_NAME, (options) => new ExpressInstrumentation(options) ); class ExpressInstrumentation extends instrumentation.InstrumentationBase { constructor(config = {}) { super("sentry-express", core.SDK_VERSION, config); } init() { const module = new instrumentation.InstrumentationNodeModuleDefinition( "express", SUPPORTED_VERSIONS, (express) => { try { core.patchExpressModule(express, () => ({ ...this.getConfig(), onRouteResolved(route) { if (route) { setHttpServerSpanRouteAttribute.setHttpServerSpanRouteAttribute(route); } } })); } catch (e) { debugBuild.DEBUG_BUILD && core.debug.error("Failed to patch express module:", e); } return express; }, // we do not ever actually unpatch in our SDKs (express) => express ); return module; } } const _expressIntegration = ((options) => { return { name: INTEGRATION_NAME, setupOnce() { instrumentExpress(options); } }; }); const expressIntegration = core.defineIntegration(_expressIntegration); exports.expressErrorHandler = core.expressErrorHandler; exports.ExpressInstrumentation = ExpressInstrumentation; exports.expressIntegration = expressIntegration; exports.instrumentExpress = instrumentExpress; exports.setupExpressErrorHandler = setupExpressErrorHandler; //# sourceMappingURL=express.js.map