@sentry/tracing
Advanced tools
Comparing version 5.27.7-beta.0 to 5.28.0
import { Integration } from '@sentry/types'; | ||
declare type Method = 'all' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'checkout' | 'copy' | 'lock' | 'merge' | 'mkactivity' | 'mkcol' | 'move' | 'm-search' | 'notify' | 'purge' | 'report' | 'search' | 'subscribe' | 'trace' | 'unlock' | 'unsubscribe'; | ||
declare type Application = { | ||
[method in Method | 'use']: (...args: any) => any; | ||
declare type Method = 'all' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'checkout' | 'copy' | 'lock' | 'merge' | 'mkactivity' | 'mkcol' | 'move' | 'm-search' | 'notify' | 'purge' | 'report' | 'search' | 'subscribe' | 'trace' | 'unlock' | 'unsubscribe' | 'use'; | ||
declare type Router = { | ||
[method in Method]: (...args: unknown[]) => unknown; | ||
}; | ||
@@ -9,4 +9,3 @@ /** | ||
* | ||
* Provides an request and error handler for Express framework | ||
* as well as tracing capabilities | ||
* Provides an request and error handler for Express framework as well as tracing capabilities | ||
*/ | ||
@@ -25,3 +24,3 @@ export declare class Express implements Integration { | ||
*/ | ||
private readonly _app?; | ||
private readonly _router?; | ||
private readonly _methods?; | ||
@@ -32,3 +31,4 @@ /** | ||
constructor(options?: { | ||
app?: Application; | ||
app?: Router; | ||
router?: Router; | ||
methods?: Method[]; | ||
@@ -35,0 +35,0 @@ }); |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var utils_1 = require("@sentry/utils"); | ||
@@ -6,4 +7,3 @@ /** | ||
* | ||
* Provides an request and error handler for Express framework | ||
* as well as tracing capabilities | ||
* Provides an request and error handler for Express framework as well as tracing capabilities | ||
*/ | ||
@@ -20,4 +20,4 @@ var Express = /** @class */ (function () { | ||
this.name = Express.id; | ||
this._app = options.app; | ||
this._methods = options.methods; | ||
this._router = options.router || options.app; | ||
this._methods = (Array.isArray(options.methods) ? options.methods : []).concat('use'); | ||
} | ||
@@ -28,8 +28,7 @@ /** | ||
Express.prototype.setupOnce = function () { | ||
if (!this._app) { | ||
if (!this._router) { | ||
utils_1.logger.error('ExpressIntegration is missing an Express instance'); | ||
return; | ||
} | ||
instrumentMiddlewares(this._app); | ||
routeMiddlewares(this._app, this._methods); | ||
instrumentMiddlewares(this._router, this._methods); | ||
}; | ||
@@ -54,5 +53,7 @@ /** | ||
* app.use(function (err, req, res, next) { ... }) | ||
* | ||
* They all internally delegate to the `router[method]` of the given application instance. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
function wrap(fn) { | ||
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any | ||
function wrap(fn, method) { | ||
var arity = fn.length; | ||
@@ -63,7 +64,6 @@ switch (arity) { | ||
var transaction = res.__sentry_transaction; | ||
addExpressReqToTransaction(transaction, req); | ||
if (transaction) { | ||
var span_1 = transaction.startChild({ | ||
description: fn.name, | ||
op: 'middleware', | ||
op: "middleware." + method, | ||
}); | ||
@@ -74,4 +74,3 @@ res.once('finish', function () { | ||
} | ||
// eslint-disable-next-line prefer-rest-params | ||
return fn.apply(this, arguments); | ||
return fn.call(this, req, res); | ||
}; | ||
@@ -81,15 +80,16 @@ } | ||
return function (req, res, next) { | ||
var _a; | ||
var transaction = res.__sentry_transaction; | ||
addExpressReqToTransaction(transaction, req); | ||
var span = transaction && | ||
transaction.startChild({ | ||
description: fn.name, | ||
op: 'middleware', | ||
}); | ||
var span = (_a = transaction) === null || _a === void 0 ? void 0 : _a.startChild({ | ||
description: fn.name, | ||
op: "middleware." + method, | ||
}); | ||
fn.call(this, req, res, function () { | ||
if (span) { | ||
span.finish(); | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
// eslint-disable-next-line prefer-rest-params | ||
return next.apply(this, arguments); | ||
var _a; | ||
(_a = span) === null || _a === void 0 ? void 0 : _a.finish(); | ||
next.call.apply(next, tslib_1.__spread([this], args)); | ||
}); | ||
@@ -100,15 +100,16 @@ }; | ||
return function (err, req, res, next) { | ||
var _a; | ||
var transaction = res.__sentry_transaction; | ||
addExpressReqToTransaction(transaction, req); | ||
var span = transaction && | ||
transaction.startChild({ | ||
description: fn.name, | ||
op: 'middleware', | ||
}); | ||
var span = (_a = transaction) === null || _a === void 0 ? void 0 : _a.startChild({ | ||
description: fn.name, | ||
op: "middleware." + method, | ||
}); | ||
fn.call(this, err, req, res, function () { | ||
if (span) { | ||
span.finish(); | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
// eslint-disable-next-line prefer-rest-params | ||
return next.apply(this, arguments); | ||
var _a; | ||
(_a = span) === null || _a === void 0 ? void 0 : _a.finish(); | ||
next.call.apply(next, tslib_1.__spread([this], args)); | ||
}); | ||
@@ -123,19 +124,3 @@ }; | ||
/** | ||
* Set parameterized as transaction name e.g.: `GET /users/:id` | ||
* Also adds more context data on the transaction from the request | ||
*/ | ||
function addExpressReqToTransaction(transaction, req) { | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
if (transaction) { | ||
if (req.route && req.route.path) { | ||
transaction.name = req.method + " " + req.route.path; | ||
} | ||
transaction.setData('url', req.originalUrl); | ||
transaction.setData('baseUrl', req.baseUrl); | ||
transaction.setData('query', req.query); | ||
} | ||
/* eslint-enable @typescript-eslint/no-unsafe-member-access */ | ||
} | ||
/** | ||
* Takes all the function arguments passed to the original `app.use` call | ||
* Takes all the function arguments passed to the original `app` or `router` method, eg. `app.use` or `router.use` | ||
* and wraps every function, as well as array of functions with a call to our `wrap` method. | ||
@@ -149,6 +134,6 @@ * We have to take care of the arrays as well as iterate over all of the arguments, | ||
*/ | ||
function wrapUseArgs(args) { | ||
return Array.from(args).map(function (arg) { | ||
function wrapMiddlewareArgs(args, method) { | ||
return args.map(function (arg) { | ||
if (typeof arg === 'function') { | ||
return wrap(arg); | ||
return wrap(arg, method); | ||
} | ||
@@ -158,3 +143,3 @@ if (Array.isArray(arg)) { | ||
if (typeof a === 'function') { | ||
return wrap(a); | ||
return wrap(a, method); | ||
} | ||
@@ -168,27 +153,22 @@ return a; | ||
/** | ||
* Patches original App to utilize our tracing functionality | ||
* Patches original router to utilize our tracing functionality | ||
*/ | ||
function patchMiddleware(app, method) { | ||
var originalAppCallback = app[method]; | ||
app[method] = function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
return originalAppCallback.apply(this, wrapUseArgs(arguments)); | ||
function patchMiddleware(router, method) { | ||
var originalCallback = router[method]; | ||
router[method] = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return originalCallback.call.apply(originalCallback, tslib_1.__spread([this], wrapMiddlewareArgs(args, method))); | ||
}; | ||
return app; | ||
return router; | ||
} | ||
/** | ||
* Patches original app.use | ||
* Patches original router methods | ||
*/ | ||
function instrumentMiddlewares(app) { | ||
patchMiddleware(app, 'use'); | ||
} | ||
/** | ||
* Patches original app.METHOD | ||
*/ | ||
function routeMiddlewares(app, methods) { | ||
function instrumentMiddlewares(router, methods) { | ||
if (methods === void 0) { methods = []; } | ||
methods.forEach(function (method) { | ||
patchMiddleware(app, method); | ||
}); | ||
methods.forEach(function (method) { return patchMiddleware(router, method); }); | ||
} | ||
//# sourceMappingURL=express.js.map |
import { Integration } from '@sentry/types'; | ||
declare type Method = 'all' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'checkout' | 'copy' | 'lock' | 'merge' | 'mkactivity' | 'mkcol' | 'move' | 'm-search' | 'notify' | 'purge' | 'report' | 'search' | 'subscribe' | 'trace' | 'unlock' | 'unsubscribe'; | ||
declare type Application = { | ||
[method in Method | 'use']: (...args: any) => any; | ||
declare type Method = 'all' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'checkout' | 'copy' | 'lock' | 'merge' | 'mkactivity' | 'mkcol' | 'move' | 'm-search' | 'notify' | 'purge' | 'report' | 'search' | 'subscribe' | 'trace' | 'unlock' | 'unsubscribe' | 'use'; | ||
declare type Router = { | ||
[method in Method]: (...args: unknown[]) => unknown; | ||
}; | ||
@@ -9,4 +9,3 @@ /** | ||
* | ||
* Provides an request and error handler for Express framework | ||
* as well as tracing capabilities | ||
* Provides an request and error handler for Express framework as well as tracing capabilities | ||
*/ | ||
@@ -25,3 +24,3 @@ export declare class Express implements Integration { | ||
*/ | ||
private readonly _app?; | ||
private readonly _router?; | ||
private readonly _methods?; | ||
@@ -32,3 +31,4 @@ /** | ||
constructor(options?: { | ||
app?: Application; | ||
app?: Router; | ||
router?: Router; | ||
methods?: Method[]; | ||
@@ -35,0 +35,0 @@ }); |
@@ -0,1 +1,2 @@ | ||
import { __read, __spread } from "tslib"; | ||
import { logger } from '@sentry/utils'; | ||
@@ -5,4 +6,3 @@ /** | ||
* | ||
* Provides an request and error handler for Express framework | ||
* as well as tracing capabilities | ||
* Provides an request and error handler for Express framework as well as tracing capabilities | ||
*/ | ||
@@ -19,4 +19,4 @@ var Express = /** @class */ (function () { | ||
this.name = Express.id; | ||
this._app = options.app; | ||
this._methods = options.methods; | ||
this._router = options.router || options.app; | ||
this._methods = (Array.isArray(options.methods) ? options.methods : []).concat('use'); | ||
} | ||
@@ -27,8 +27,7 @@ /** | ||
Express.prototype.setupOnce = function () { | ||
if (!this._app) { | ||
if (!this._router) { | ||
logger.error('ExpressIntegration is missing an Express instance'); | ||
return; | ||
} | ||
instrumentMiddlewares(this._app); | ||
routeMiddlewares(this._app, this._methods); | ||
instrumentMiddlewares(this._router, this._methods); | ||
}; | ||
@@ -53,5 +52,7 @@ /** | ||
* app.use(function (err, req, res, next) { ... }) | ||
* | ||
* They all internally delegate to the `router[method]` of the given application instance. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
function wrap(fn) { | ||
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any | ||
function wrap(fn, method) { | ||
var arity = fn.length; | ||
@@ -62,7 +63,6 @@ switch (arity) { | ||
var transaction = res.__sentry_transaction; | ||
addExpressReqToTransaction(transaction, req); | ||
if (transaction) { | ||
var span_1 = transaction.startChild({ | ||
description: fn.name, | ||
op: 'middleware', | ||
op: "middleware." + method, | ||
}); | ||
@@ -73,4 +73,3 @@ res.once('finish', function () { | ||
} | ||
// eslint-disable-next-line prefer-rest-params | ||
return fn.apply(this, arguments); | ||
return fn.call(this, req, res); | ||
}; | ||
@@ -80,15 +79,16 @@ } | ||
return function (req, res, next) { | ||
var _a; | ||
var transaction = res.__sentry_transaction; | ||
addExpressReqToTransaction(transaction, req); | ||
var span = transaction && | ||
transaction.startChild({ | ||
description: fn.name, | ||
op: 'middleware', | ||
}); | ||
var span = (_a = transaction) === null || _a === void 0 ? void 0 : _a.startChild({ | ||
description: fn.name, | ||
op: "middleware." + method, | ||
}); | ||
fn.call(this, req, res, function () { | ||
if (span) { | ||
span.finish(); | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
// eslint-disable-next-line prefer-rest-params | ||
return next.apply(this, arguments); | ||
var _a; | ||
(_a = span) === null || _a === void 0 ? void 0 : _a.finish(); | ||
next.call.apply(next, __spread([this], args)); | ||
}); | ||
@@ -99,15 +99,16 @@ }; | ||
return function (err, req, res, next) { | ||
var _a; | ||
var transaction = res.__sentry_transaction; | ||
addExpressReqToTransaction(transaction, req); | ||
var span = transaction && | ||
transaction.startChild({ | ||
description: fn.name, | ||
op: 'middleware', | ||
}); | ||
var span = (_a = transaction) === null || _a === void 0 ? void 0 : _a.startChild({ | ||
description: fn.name, | ||
op: "middleware." + method, | ||
}); | ||
fn.call(this, err, req, res, function () { | ||
if (span) { | ||
span.finish(); | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
// eslint-disable-next-line prefer-rest-params | ||
return next.apply(this, arguments); | ||
var _a; | ||
(_a = span) === null || _a === void 0 ? void 0 : _a.finish(); | ||
next.call.apply(next, __spread([this], args)); | ||
}); | ||
@@ -122,19 +123,3 @@ }; | ||
/** | ||
* Set parameterized as transaction name e.g.: `GET /users/:id` | ||
* Also adds more context data on the transaction from the request | ||
*/ | ||
function addExpressReqToTransaction(transaction, req) { | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
if (transaction) { | ||
if (req.route && req.route.path) { | ||
transaction.name = req.method + " " + req.route.path; | ||
} | ||
transaction.setData('url', req.originalUrl); | ||
transaction.setData('baseUrl', req.baseUrl); | ||
transaction.setData('query', req.query); | ||
} | ||
/* eslint-enable @typescript-eslint/no-unsafe-member-access */ | ||
} | ||
/** | ||
* Takes all the function arguments passed to the original `app.use` call | ||
* Takes all the function arguments passed to the original `app` or `router` method, eg. `app.use` or `router.use` | ||
* and wraps every function, as well as array of functions with a call to our `wrap` method. | ||
@@ -148,6 +133,6 @@ * We have to take care of the arrays as well as iterate over all of the arguments, | ||
*/ | ||
function wrapUseArgs(args) { | ||
return Array.from(args).map(function (arg) { | ||
function wrapMiddlewareArgs(args, method) { | ||
return args.map(function (arg) { | ||
if (typeof arg === 'function') { | ||
return wrap(arg); | ||
return wrap(arg, method); | ||
} | ||
@@ -157,3 +142,3 @@ if (Array.isArray(arg)) { | ||
if (typeof a === 'function') { | ||
return wrap(a); | ||
return wrap(a, method); | ||
} | ||
@@ -167,27 +152,22 @@ return a; | ||
/** | ||
* Patches original App to utilize our tracing functionality | ||
* Patches original router to utilize our tracing functionality | ||
*/ | ||
function patchMiddleware(app, method) { | ||
var originalAppCallback = app[method]; | ||
app[method] = function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
return originalAppCallback.apply(this, wrapUseArgs(arguments)); | ||
function patchMiddleware(router, method) { | ||
var originalCallback = router[method]; | ||
router[method] = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return originalCallback.call.apply(originalCallback, __spread([this], wrapMiddlewareArgs(args, method))); | ||
}; | ||
return app; | ||
return router; | ||
} | ||
/** | ||
* Patches original app.use | ||
* Patches original router methods | ||
*/ | ||
function instrumentMiddlewares(app) { | ||
patchMiddleware(app, 'use'); | ||
} | ||
/** | ||
* Patches original app.METHOD | ||
*/ | ||
function routeMiddlewares(app, methods) { | ||
function instrumentMiddlewares(router, methods) { | ||
if (methods === void 0) { methods = []; } | ||
methods.forEach(function (method) { | ||
patchMiddleware(app, method); | ||
}); | ||
methods.forEach(function (method) { return patchMiddleware(router, method); }); | ||
} | ||
//# sourceMappingURL=express.js.map |
{ | ||
"name": "@sentry/tracing", | ||
"version": "5.27.7-beta.0", | ||
"version": "5.28.0", | ||
"description": "Extensions for Sentry AM", | ||
@@ -19,11 +19,11 @@ "repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"dependencies": { | ||
"@sentry/hub": "5.27.7-beta.0", | ||
"@sentry/minimal": "5.27.7-beta.0", | ||
"@sentry/types": "5.27.7-beta.0", | ||
"@sentry/utils": "5.27.7-beta.0", | ||
"@sentry/hub": "5.28.0", | ||
"@sentry/minimal": "5.28.0", | ||
"@sentry/types": "5.28.0", | ||
"@sentry/utils": "5.28.0", | ||
"tslib": "^1.9.3" | ||
}, | ||
"devDependencies": { | ||
"@sentry-internal/eslint-config-sdk": "5.27.7-beta.0", | ||
"@sentry/browser": "5.27.7-beta.0", | ||
"@sentry-internal/eslint-config-sdk": "5.28.0", | ||
"@sentry/browser": "5.28.0", | ||
"@types/express": "^4.17.1", | ||
@@ -30,0 +30,0 @@ "@types/jsdom": "^16.2.3", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
2024051
14826
+ Added@sentry/hub@5.28.0(transitive)
+ Added@sentry/minimal@5.28.0(transitive)
+ Added@sentry/types@5.28.0(transitive)
+ Added@sentry/utils@5.28.0(transitive)
- Removed@sentry/hub@5.27.7-beta.0(transitive)
- Removed@sentry/minimal@5.27.7-beta.0(transitive)
- Removed@sentry/types@5.27.7-beta.0(transitive)
- Removed@sentry/utils@5.27.7-beta.0(transitive)
Updated@sentry/hub@5.28.0
Updated@sentry/minimal@5.28.0
Updated@sentry/types@5.28.0
Updated@sentry/utils@5.28.0