From 78db77c099d1feb83b4c7e63b9dfcfb35b59a427 Mon Sep 17 00:00:00 2001 From: Daniel Cook Date: Wed, 30 Jun 2021 14:04:16 +0100 Subject: [PATCH 1/4] Check the presence of _captureRequestSession before calling it --- packages/node/src/handlers.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 777cc3b0f19c..c1feb11619dc 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -433,7 +433,8 @@ export function requestHandler( const client = currentHub.getClient(); if (isAutoSessionTrackingEnabled(client)) { setImmediate(() => { - if (client) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + if (client && (client as any)._captureRequestSession) { // Calling _captureRequestSession to capture request session at the end of the request by incrementing // the correct SessionAggregates bucket i.e. crashed, errored or exited // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access From 5edfbf65965a4ec365f4c9c19eba769afd4f39f0 Mon Sep 17 00:00:00 2001 From: Daniel Cook Date: Wed, 30 Jun 2021 14:07:31 +0100 Subject: [PATCH 2/4] Update handlers.ts --- packages/node/src/handlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index c1feb11619dc..119e964fee51 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -433,7 +433,7 @@ export function requestHandler( const client = currentHub.getClient(); if (isAutoSessionTrackingEnabled(client)) { setImmediate(() => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (client && (client as any)._captureRequestSession) { // Calling _captureRequestSession to capture request session at the end of the request by incrementing // the correct SessionAggregates bucket i.e. crashed, errored or exited From 7b830b25326d2ac3e2f9fd097182cc486d9797b7 Mon Sep 17 00:00:00 2001 From: Daniel Cook Date: Wed, 30 Jun 2021 14:32:31 +0100 Subject: [PATCH 3/4] run prettier --- packages/node/src/handlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index c1feb11619dc..c8156896acc8 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -433,7 +433,7 @@ export function requestHandler( const client = currentHub.getClient(); if (isAutoSessionTrackingEnabled(client)) { setImmediate(() => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (client && (client as any)._captureRequestSession) { // Calling _captureRequestSession to capture request session at the end of the request by incrementing // the correct SessionAggregates bucket i.e. crashed, errored or exited From 40bffc1fb1e7011e1a5a47c8322c409ab467fedf Mon Sep 17 00:00:00 2001 From: Daniel Cook Date: Wed, 30 Jun 2021 14:34:13 +0100 Subject: [PATCH 4/4] prettier agaiin --- packages/node/src/handlers.ts | 40 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index dcfeb95a675d..c8156896acc8 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -43,12 +43,12 @@ export interface ExpressRequest { * Express-compatible tracing handler. * @see Exposed as `Handlers.tracingHandler` */ -export function tracingHandler (): ( +export function tracingHandler(): ( req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void, ) => void { - return function sentryTracingMiddleware ( + return function sentryTracingMiddleware( req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void, @@ -97,7 +97,7 @@ export function tracingHandler (): ( * Set parameterized as transaction name e.g.: `GET /users/:id` * Also adds more context data on the transaction from the request */ -function addExpressReqToTransaction (transaction: Transaction | undefined, req: ExpressRequest): void { +function addExpressReqToTransaction(transaction: Transaction | undefined, req: ExpressRequest): void { if (!transaction) return; transaction.name = extractExpressTransactionName(req, { path: true, method: true }); transaction.setData('url', req.originalUrl); @@ -115,7 +115,7 @@ function addExpressReqToTransaction (transaction: Transaction | undefined, req: * * @returns The fully constructed transaction name */ -function extractExpressTransactionName ( +function extractExpressTransactionName( req: ExpressRequest, options: { path?: boolean; method?: boolean } = {}, ): string { @@ -145,7 +145,7 @@ function extractExpressTransactionName ( type TransactionNamingScheme = 'path' | 'methodPath' | 'handler'; /** JSDoc */ -function extractTransaction (req: ExpressRequest, type: boolean | TransactionNamingScheme): string { +function extractTransaction(req: ExpressRequest, type: boolean | TransactionNamingScheme): string { switch (type) { case 'path': { return extractExpressTransactionName(req, { path: true }); @@ -164,7 +164,7 @@ function extractTransaction (req: ExpressRequest, type: boolean | TransactionNam const DEFAULT_USER_KEYS = ['id', 'username', 'email']; /** JSDoc */ -function extractUserData ( +function extractUserData( user: { [key: string]: any; }, @@ -193,7 +193,7 @@ const DEFAULT_REQUEST_KEYS = ['cookies', 'data', 'headers', 'method', 'query_str * provided. * @returns An object containing normalized request data */ -export function extractRequestData ( +export function extractRequestData( req: { [key: string]: any }, keys: string[] = DEFAULT_REQUEST_KEYS, ): ExtractedNodeRequestData { @@ -297,7 +297,7 @@ export interface ParseRequestOptions { * @param options object containing flags to enable functionality * @hidden */ -export function parseRequest (event: Event, req: ExpressRequest, options?: ParseRequestOptions): Event { +export function parseRequest(event: Event, req: ExpressRequest, options?: ParseRequestOptions): Event { // eslint-disable-next-line no-param-reassign options = { ip: false, @@ -375,7 +375,7 @@ export type RequestHandlerOptions = ParseRequestOptions & { * Express compatible request handler. * @see Exposed as `Handlers.requestHandler` */ -export function requestHandler ( +export function requestHandler( options?: RequestHandlerOptions, ): (req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void) => void { const currentHub = getCurrentHub(); @@ -391,7 +391,7 @@ export function requestHandler ( scope.setSession(); } } - return function sentryRequestMiddleware ( + return function sentryRequestMiddleware( req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void, @@ -399,7 +399,7 @@ export function requestHandler ( if (options && options.flushTimeout && options.flushTimeout > 0) { // eslint-disable-next-line @typescript-eslint/unbound-method const _end = res.end; - res.end = function (chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void { + res.end = function(chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void { void flush(options.flushTimeout) .then(() => { _end.call(this, chunk, encoding, cb); @@ -459,13 +459,13 @@ interface MiddlewareError extends Error { } /** JSDoc */ -function getStatusCodeFromResponse (error: MiddlewareError): number { +function getStatusCodeFromResponse(error: MiddlewareError): number { const statusCode = error.status || error.statusCode || error.status_code || (error.output && error.output.statusCode); return statusCode ? parseInt(statusCode as string, 10) : 500; } /** Returns true if response code is internal server error */ -function defaultShouldHandleError (error: MiddlewareError): boolean { +function defaultShouldHandleError(error: MiddlewareError): boolean { const status = getStatusCodeFromResponse(error); return status >= 500; } @@ -474,19 +474,19 @@ function defaultShouldHandleError (error: MiddlewareError): boolean { * Express compatible error handler. * @see Exposed as `Handlers.errorHandler` */ -export function errorHandler (options?: { +export function errorHandler(options?: { /** * Callback method deciding whether error should be captured and sent to Sentry * @param error Captured middleware error */ shouldHandleError?(error: MiddlewareError): boolean; }): ( - error: MiddlewareError, - req: http.IncomingMessage, - res: http.ServerResponse, - next: (error: MiddlewareError) => void, - ) => void { - return function sentryErrorMiddleware ( + error: MiddlewareError, + req: http.IncomingMessage, + res: http.ServerResponse, + next: (error: MiddlewareError) => void, +) => void { + return function sentryErrorMiddleware( error: MiddlewareError, _req: http.IncomingMessage, res: http.ServerResponse,