Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sentry/serverless

Package Overview
Dependencies
Maintainers
11
Versions
307
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/serverless - npm Package Compare versions

Comparing version 7.91.0 to 7.92.0

77

cjs/awslambda.js

@@ -25,3 +25,5 @@ var {

/**
* @see {@link Sentry.init}
* Initializes the Sentry AWS Lambda SDK.
*
* @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
*/

@@ -243,40 +245,9 @@ function init(options = {}) {

const hub = Sentry.getCurrentHub();
async function processResult(span) {
const scope = Sentry.getCurrentScope();
let transaction;
if (options.startTrace) {
const eventWithHeaders = event ;
const sentryTrace =
eventWithHeaders.headers && utils.isString(eventWithHeaders.headers['sentry-trace'])
? eventWithHeaders.headers['sentry-trace']
: undefined;
const baggage = _optionalChain([eventWithHeaders, 'access', _ => _.headers, 'optionalAccess', _2 => _2.baggage]);
const { traceparentData, dynamicSamplingContext, propagationContext } = utils.tracingContextFromHeaders(
sentryTrace,
baggage,
);
Sentry.getCurrentScope().setPropagationContext(propagationContext);
transaction = hub.startTransaction({
name: context.functionName,
op: 'function.aws.lambda',
origin: 'auto.function.serverless',
...traceparentData,
metadata: {
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
source: 'component',
},
});
}
return Sentry.withScope(async scope => {
let rv;
try {
enhanceScopeWithEnvironmentData(scope, context, START_TIME);
if (options.startTrace) {
enhanceScopeWithTransactionData(scope, context);
// We put the transaction on the scope so users can attach children to it
scope.setSpan(transaction);
}
rv = await asyncHandler(event, context);

@@ -296,3 +267,3 @@

clearTimeout(timeoutWarningTimer);
_optionalChain([transaction, 'optionalAccess', _3 => _3.end, 'call', _4 => _4()]);
_optionalChain([span, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
await Sentry.flush(options.flushTimeout).catch(e => {

@@ -303,2 +274,36 @@ debugBuild.DEBUG_BUILD && utils.logger.error(e);

return rv;
}
if (options.startTrace) {
const eventWithHeaders = event ;
const sentryTrace =
eventWithHeaders.headers && utils.isString(eventWithHeaders.headers['sentry-trace'])
? eventWithHeaders.headers['sentry-trace']
: undefined;
const baggage = _optionalChain([eventWithHeaders, 'access', _3 => _3.headers, 'optionalAccess', _4 => _4.baggage]);
const continueTraceContext = Sentry.continueTrace({ sentryTrace, baggage });
return Sentry.startSpanManual(
{
name: context.functionName,
op: 'function.aws.lambda',
origin: 'auto.function.serverless',
...continueTraceContext,
metadata: {
...continueTraceContext.metadata,
source: 'component',
},
},
span => {
enhanceScopeWithTransactionData(Sentry.getCurrentScope(), context);
return processResult(span);
},
);
}
return Sentry.withScope(async () => {
return processResult(undefined);
});

@@ -305,0 +310,0 @@ };

@@ -7,2 +7,3 @@ var {

const core = require('@sentry/core');
const Sentry = require('@sentry/node');

@@ -27,3 +28,2 @@ const utils$1 = require('@sentry/utils');

/** */
function _wrapCloudEventFunction(

@@ -38,60 +38,46 @@ fn,

return (context, callback) => {
const hub = Sentry.getCurrentHub();
return Sentry.startSpanManual(
{
name: context.type || '<unknown>',
op: 'function.gcp.cloud_event',
origin: 'auto.function.serverless.gcp_cloud_event',
metadata: { source: 'component' },
},
span => {
const scope = Sentry.getCurrentScope();
scope.setContext('gcp.function.context', { ...context });
const transaction = hub.startTransaction({
name: context.type || '<unknown>',
op: 'function.gcp.cloud_event',
origin: 'auto.function.serverless.gcp_cloud_event',
metadata: { source: 'component' },
}) ;
const newCallback = utils.domainify((...args) => {
if (args[0] !== null && args[0] !== undefined) {
Sentry.captureException(args[0], scope => utils.markEventUnhandled(scope));
}
_optionalChain([span, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
// getCurrentHub() is expected to use current active domain as a carrier
// since functions-framework creates a domain for each incoming request.
// So adding of event processors every time should not lead to memory bloat.
const scope = Sentry.getCurrentScope();
scope.setContext('gcp.function.context', { ...context });
// We put the transaction on the scope so users can attach children to it
scope.setSpan(transaction);
const newCallback = utils.domainify((...args) => {
if (args[0] !== null && args[0] !== undefined) {
Sentry.captureException(args[0], scope => utils.markEventUnhandled(scope));
}
_optionalChain([transaction, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.flush(options.flushTimeout)
.then(null, e => {
debugBuild.DEBUG_BUILD && utils$1.logger.error(e);
})
.then(() => {
callback(...args);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.flush(options.flushTimeout)
.then(null, e => {
debugBuild.DEBUG_BUILD && utils$1.logger.error(e);
})
.then(() => {
callback(...args);
});
});
});
if (fn.length > 1) {
let fnResult;
try {
fnResult = (fn )(context, newCallback);
} catch (err) {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
throw err;
}
if (fn.length > 1) {
return core.handleCallbackErrors(
() => (fn )(context, newCallback),
err => {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
},
);
}
if (utils$1.isThenable(fnResult)) {
fnResult.then(null, err => {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
throw err;
});
}
return fnResult;
}
return Promise.resolve()
.then(() => (fn )(context))
.then(
result => newCallback(null, result),
err => newCallback(err, undefined),
);
return Promise.resolve()
.then(() => (fn )(context))
.then(
result => newCallback(null, result),
err => newCallback(err, undefined),
);
},
);
};

@@ -98,0 +84,0 @@ }

@@ -7,2 +7,3 @@ var {

const core = require('@sentry/core');
const Sentry = require('@sentry/node');

@@ -39,62 +40,48 @@ const utils$1 = require('@sentry/utils');

const hub = Sentry.getCurrentHub();
return Sentry.startSpanManual(
{
name: context.eventType,
op: 'function.gcp.event',
origin: 'auto.function.serverless.gcp_event',
metadata: { source: 'component' },
},
span => {
const scope = Sentry.getCurrentScope();
scope.setContext('gcp.function.context', { ...context });
const transaction = hub.startTransaction({
name: context.eventType,
op: 'function.gcp.event',
origin: 'auto.function.serverless.gcp_event',
metadata: { source: 'component' },
}) ;
// getCurrentHub() is expected to use current active domain as a carrier
// since functions-framework creates a domain for each incoming request.
// So adding of event processors every time should not lead to memory bloat.
const scope = Sentry.getCurrentScope();
scope.setContext('gcp.function.context', { ...context });
// We put the transaction on the scope so users can attach children to it
scope.setSpan(transaction);
const newCallback = utils.domainify((...args) => {
if (args[0] !== null && args[0] !== undefined) {
Sentry.captureException(args[0], scope => utils.markEventUnhandled(scope));
}
_optionalChain([transaction, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.flush(options.flushTimeout)
.then(null, e => {
debugBuild.DEBUG_BUILD && utils$1.logger.error(e);
})
.then(() => {
if (typeof callback === 'function') {
callback(...args);
const newCallback = utils.domainify((...args) => {
if (args[0] !== null && args[0] !== undefined) {
Sentry.captureException(args[0], scope => utils.markEventUnhandled(scope));
}
});
});
_optionalChain([span, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
if (fn.length > 2) {
let fnResult;
try {
fnResult = (fn )(data, context, newCallback);
} catch (err) {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
throw err;
}
if (utils$1.isThenable(fnResult)) {
fnResult.then(null, err => {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
throw err;
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.flush(options.flushTimeout)
.then(null, e => {
debugBuild.DEBUG_BUILD && utils$1.logger.error(e);
})
.then(() => {
if (typeof callback === 'function') {
callback(...args);
}
});
});
}
return fnResult;
}
if (fn.length > 2) {
return core.handleCallbackErrors(
() => (fn )(data, context, newCallback),
err => {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
},
);
}
return Promise.resolve()
.then(() => (fn )(data, context))
.then(
result => newCallback(null, result),
err => newCallback(err, undefined),
);
return Promise.resolve()
.then(() => (fn )(data, context))
.then(
result => newCallback(null, result),
err => newCallback(err, undefined),
);
},
);
};

@@ -101,0 +88,0 @@ }

@@ -7,2 +7,3 @@ var {

const core = require('@sentry/core');
const Sentry = require('@sentry/node');

@@ -53,5 +54,2 @@ const utils$1 = require('@sentry/utils');

return (req, res) => {
const hub = Sentry.getCurrentHub();
const scope = Sentry.getCurrentScope();
const reqMethod = (req.method || '').toUpperCase();

@@ -62,67 +60,56 @@ const reqUrl = utils$1.stripUrlQueryAndFragment(req.originalUrl || req.url || '');

const baggage = _optionalChain([req, 'access', _ => _.headers, 'optionalAccess', _2 => _2.baggage]);
const { traceparentData, dynamicSamplingContext, propagationContext } = utils$1.tracingContextFromHeaders(
sentryTrace,
baggage,
);
scope.setPropagationContext(propagationContext);
const transaction = hub.startTransaction({
name: `${reqMethod} ${reqUrl}`,
op: 'function.gcp.http',
origin: 'auto.function.serverless.gcp_http',
...traceparentData,
metadata: {
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
source: 'route',
},
}) ;
const continueTraceContext = Sentry.continueTrace({ sentryTrace, baggage });
// getCurrentHub() is expected to use current active domain as a carrier
// since functions-framework creates a domain for each incoming request.
// So adding of event processors every time should not lead to memory bloat.
scope.setSDKProcessingMetadata({
request: req,
requestDataOptionsFromGCPWrapper: options.addRequestDataToEventOptions,
});
// We put the transaction on the scope so users can attach children to it
scope.setSpan(transaction);
return Sentry.startSpanManual(
{
...continueTraceContext,
name: `${reqMethod} ${reqUrl}`,
op: 'function.gcp.http',
origin: 'auto.function.serverless.gcp_http',
// We also set __sentry_transaction on the response so people can grab the transaction there to add
// spans to it later.
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
(res ).__sentry_transaction = transaction;
metadata: {
...continueTraceContext.metadata,
source: 'route',
},
},
span => {
Sentry.getCurrentScope().setSDKProcessingMetadata({
request: req,
requestDataOptionsFromGCPWrapper: options.addRequestDataToEventOptions,
});
// eslint-disable-next-line @typescript-eslint/unbound-method
const _end = res.end;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
res.end = function (chunk, encoding, cb) {
_optionalChain([transaction, 'optionalAccess', _3 => _3.setHttpStatus, 'call', _4 => _4(res.statusCode)]);
_optionalChain([transaction, 'optionalAccess', _5 => _5.end, 'call', _6 => _6()]);
if (span instanceof core.Transaction) {
// We also set __sentry_transaction on the response so people can grab the transaction there to add
// spans to it later.
// TODO(v8): Remove this
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
(res ).__sentry_transaction = span;
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.flush(options.flushTimeout)
.then(null, e => {
debugBuild.DEBUG_BUILD && utils$1.logger.error(e);
})
.then(() => {
_end.call(this, chunk, encoding, cb);
});
};
// eslint-disable-next-line @typescript-eslint/unbound-method
const _end = res.end;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
res.end = function (chunk, encoding, cb) {
_optionalChain([span, 'optionalAccess', _3 => _3.setHttpStatus, 'call', _4 => _4(res.statusCode)]);
_optionalChain([span, 'optionalAccess', _5 => _5.end, 'call', _6 => _6()]);
let fnResult;
try {
fnResult = fn(req, res);
} catch (err) {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
throw err;
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Sentry.flush(options.flushTimeout)
.then(null, e => {
debugBuild.DEBUG_BUILD && utils$1.logger.error(e);
})
.then(() => {
_end.call(this, chunk, encoding, cb);
});
};
if (utils$1.isThenable(fnResult)) {
fnResult.then(null, err => {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
throw err;
});
}
return fnResult;
return core.handleCallbackErrors(
() => fn(req, res),
err => {
Sentry.captureException(err, scope => utils.markEventUnhandled(scope));
},
);
},
);
};

@@ -129,0 +116,0 @@ }

@@ -7,5 +7,5 @@ import { _optionalChain } from '@sentry/utils';

import * as Sentry from '@sentry/node';
import { withScope, captureMessage, getCurrentHub, captureException, flush } from '@sentry/node';
import { defaultIntegrations as defaultIntegrations$1, SDK_VERSION, init as init$1, withScope, captureMessage, continueTrace, startSpanManual, getCurrentScope, captureException, flush } from '@sentry/node';
export * from '@sentry/node';
import { logger, isString, tracingContextFromHeaders } from '@sentry/utils';
import { logger, isString } from '@sentry/utils';
import { performance } from 'perf_hooks';

@@ -20,6 +20,8 @@ import { AWSServices } from './awsservices.js';

const defaultIntegrations = [...Sentry.defaultIntegrations, new AWSServices({ optional: true })];
const defaultIntegrations = [...defaultIntegrations$1, new AWSServices({ optional: true })];
/**
* @see {@link Sentry.init}
* Initializes the Sentry AWS Lambda SDK.
*
* @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
*/

@@ -39,9 +41,9 @@ function init(options = {}) {

name: 'npm:@sentry/serverless',
version: Sentry.SDK_VERSION,
version: SDK_VERSION,
},
],
version: Sentry.SDK_VERSION,
version: SDK_VERSION,
};
Sentry.init(opts);
init$1(opts);
}

@@ -242,40 +244,9 @@

const hub = getCurrentHub();
async function processResult(span) {
const scope = getCurrentScope();
let transaction;
if (options.startTrace) {
const eventWithHeaders = event ;
const sentryTrace =
eventWithHeaders.headers && isString(eventWithHeaders.headers['sentry-trace'])
? eventWithHeaders.headers['sentry-trace']
: undefined;
const baggage = _optionalChain([eventWithHeaders, 'access', _ => _.headers, 'optionalAccess', _2 => _2.baggage]);
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
sentryTrace,
baggage,
);
Sentry.getCurrentScope().setPropagationContext(propagationContext);
transaction = hub.startTransaction({
name: context.functionName,
op: 'function.aws.lambda',
origin: 'auto.function.serverless',
...traceparentData,
metadata: {
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
source: 'component',
},
});
}
return withScope(async scope => {
let rv;
try {
enhanceScopeWithEnvironmentData(scope, context, START_TIME);
if (options.startTrace) {
enhanceScopeWithTransactionData(scope, context);
// We put the transaction on the scope so users can attach children to it
scope.setSpan(transaction);
}
rv = await asyncHandler(event, context);

@@ -295,3 +266,3 @@

clearTimeout(timeoutWarningTimer);
_optionalChain([transaction, 'optionalAccess', _3 => _3.end, 'call', _4 => _4()]);
_optionalChain([span, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
await flush(options.flushTimeout).catch(e => {

@@ -302,2 +273,36 @@ DEBUG_BUILD && logger.error(e);

return rv;
}
if (options.startTrace) {
const eventWithHeaders = event ;
const sentryTrace =
eventWithHeaders.headers && isString(eventWithHeaders.headers['sentry-trace'])
? eventWithHeaders.headers['sentry-trace']
: undefined;
const baggage = _optionalChain([eventWithHeaders, 'access', _3 => _3.headers, 'optionalAccess', _4 => _4.baggage]);
const continueTraceContext = continueTrace({ sentryTrace, baggage });
return startSpanManual(
{
name: context.functionName,
op: 'function.aws.lambda',
origin: 'auto.function.serverless',
...continueTraceContext,
metadata: {
...continueTraceContext.metadata,
source: 'component',
},
},
span => {
enhanceScopeWithTransactionData(getCurrentScope(), context);
return processResult(span);
},
);
}
return withScope(async () => {
return processResult(undefined);
});

@@ -304,0 +309,0 @@ };

import { _optionalChain } from '@sentry/utils';
import { getCurrentHub, getCurrentScope, captureException, flush } from '@sentry/node';
import { isThenable, logger } from '@sentry/utils';
import { handleCallbackErrors } from '@sentry/core';
import { startSpanManual, getCurrentScope, captureException, flush } from '@sentry/node';
import { logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../debug-build.js';

@@ -21,3 +22,2 @@ import { proxyFunction, domainify, markEventUnhandled } from '../utils.js';

/** */
function _wrapCloudEventFunction(

@@ -32,60 +32,46 @@ fn,

return (context, callback) => {
const hub = getCurrentHub();
return startSpanManual(
{
name: context.type || '<unknown>',
op: 'function.gcp.cloud_event',
origin: 'auto.function.serverless.gcp_cloud_event',
metadata: { source: 'component' },
},
span => {
const scope = getCurrentScope();
scope.setContext('gcp.function.context', { ...context });
const transaction = hub.startTransaction({
name: context.type || '<unknown>',
op: 'function.gcp.cloud_event',
origin: 'auto.function.serverless.gcp_cloud_event',
metadata: { source: 'component' },
}) ;
const newCallback = domainify((...args) => {
if (args[0] !== null && args[0] !== undefined) {
captureException(args[0], scope => markEventUnhandled(scope));
}
_optionalChain([span, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
// getCurrentHub() is expected to use current active domain as a carrier
// since functions-framework creates a domain for each incoming request.
// So adding of event processors every time should not lead to memory bloat.
const scope = getCurrentScope();
scope.setContext('gcp.function.context', { ...context });
// We put the transaction on the scope so users can attach children to it
scope.setSpan(transaction);
const newCallback = domainify((...args) => {
if (args[0] !== null && args[0] !== undefined) {
captureException(args[0], scope => markEventUnhandled(scope));
}
_optionalChain([transaction, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
flush(options.flushTimeout)
.then(null, e => {
DEBUG_BUILD && logger.error(e);
})
.then(() => {
callback(...args);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
flush(options.flushTimeout)
.then(null, e => {
DEBUG_BUILD && logger.error(e);
})
.then(() => {
callback(...args);
});
});
});
if (fn.length > 1) {
let fnResult;
try {
fnResult = (fn )(context, newCallback);
} catch (err) {
captureException(err, scope => markEventUnhandled(scope));
throw err;
}
if (fn.length > 1) {
return handleCallbackErrors(
() => (fn )(context, newCallback),
err => {
captureException(err, scope => markEventUnhandled(scope));
},
);
}
if (isThenable(fnResult)) {
fnResult.then(null, err => {
captureException(err, scope => markEventUnhandled(scope));
throw err;
});
}
return fnResult;
}
return Promise.resolve()
.then(() => (fn )(context))
.then(
result => newCallback(null, result),
err => newCallback(err, undefined),
);
return Promise.resolve()
.then(() => (fn )(context))
.then(
result => newCallback(null, result),
err => newCallback(err, undefined),
);
},
);
};

@@ -92,0 +78,0 @@ }

import { _optionalChain } from '@sentry/utils';
import { getCurrentHub, getCurrentScope, captureException, flush } from '@sentry/node';
import { isThenable, logger } from '@sentry/utils';
import { handleCallbackErrors } from '@sentry/core';
import { startSpanManual, getCurrentScope, captureException, flush } from '@sentry/node';
import { logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../debug-build.js';

@@ -33,62 +34,48 @@ import { proxyFunction, domainify, markEventUnhandled } from '../utils.js';

const hub = getCurrentHub();
return startSpanManual(
{
name: context.eventType,
op: 'function.gcp.event',
origin: 'auto.function.serverless.gcp_event',
metadata: { source: 'component' },
},
span => {
const scope = getCurrentScope();
scope.setContext('gcp.function.context', { ...context });
const transaction = hub.startTransaction({
name: context.eventType,
op: 'function.gcp.event',
origin: 'auto.function.serverless.gcp_event',
metadata: { source: 'component' },
}) ;
// getCurrentHub() is expected to use current active domain as a carrier
// since functions-framework creates a domain for each incoming request.
// So adding of event processors every time should not lead to memory bloat.
const scope = getCurrentScope();
scope.setContext('gcp.function.context', { ...context });
// We put the transaction on the scope so users can attach children to it
scope.setSpan(transaction);
const newCallback = domainify((...args) => {
if (args[0] !== null && args[0] !== undefined) {
captureException(args[0], scope => markEventUnhandled(scope));
}
_optionalChain([transaction, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
flush(options.flushTimeout)
.then(null, e => {
DEBUG_BUILD && logger.error(e);
})
.then(() => {
if (typeof callback === 'function') {
callback(...args);
const newCallback = domainify((...args) => {
if (args[0] !== null && args[0] !== undefined) {
captureException(args[0], scope => markEventUnhandled(scope));
}
});
});
_optionalChain([span, 'optionalAccess', _ => _.end, 'call', _2 => _2()]);
if (fn.length > 2) {
let fnResult;
try {
fnResult = (fn )(data, context, newCallback);
} catch (err) {
captureException(err, scope => markEventUnhandled(scope));
throw err;
}
if (isThenable(fnResult)) {
fnResult.then(null, err => {
captureException(err, scope => markEventUnhandled(scope));
throw err;
// eslint-disable-next-line @typescript-eslint/no-floating-promises
flush(options.flushTimeout)
.then(null, e => {
DEBUG_BUILD && logger.error(e);
})
.then(() => {
if (typeof callback === 'function') {
callback(...args);
}
});
});
}
return fnResult;
}
if (fn.length > 2) {
return handleCallbackErrors(
() => (fn )(data, context, newCallback),
err => {
captureException(err, scope => markEventUnhandled(scope));
},
);
}
return Promise.resolve()
.then(() => (fn )(data, context))
.then(
result => newCallback(null, result),
err => newCallback(err, undefined),
);
return Promise.resolve()
.then(() => (fn )(data, context))
.then(
result => newCallback(null, result),
err => newCallback(err, undefined),
);
},
);
};

@@ -95,0 +82,0 @@ }

import { _optionalChain } from '@sentry/utils';
import { getCurrentHub, getCurrentScope, flush, captureException } from '@sentry/node';
import { stripUrlQueryAndFragment, isString, tracingContextFromHeaders, logger, isThenable } from '@sentry/utils';
import { Transaction, handleCallbackErrors } from '@sentry/core';
import { continueTrace, startSpanManual, getCurrentScope, flush, captureException } from '@sentry/node';
import { stripUrlQueryAndFragment, isString, logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../debug-build.js';

@@ -47,5 +48,2 @@ import { proxyFunction, domainify, markEventUnhandled } from '../utils.js';

return (req, res) => {
const hub = getCurrentHub();
const scope = getCurrentScope();
const reqMethod = (req.method || '').toUpperCase();

@@ -56,67 +54,56 @@ const reqUrl = stripUrlQueryAndFragment(req.originalUrl || req.url || '');

const baggage = _optionalChain([req, 'access', _ => _.headers, 'optionalAccess', _2 => _2.baggage]);
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
sentryTrace,
baggage,
);
scope.setPropagationContext(propagationContext);
const transaction = hub.startTransaction({
name: `${reqMethod} ${reqUrl}`,
op: 'function.gcp.http',
origin: 'auto.function.serverless.gcp_http',
...traceparentData,
metadata: {
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
source: 'route',
},
}) ;
const continueTraceContext = continueTrace({ sentryTrace, baggage });
// getCurrentHub() is expected to use current active domain as a carrier
// since functions-framework creates a domain for each incoming request.
// So adding of event processors every time should not lead to memory bloat.
scope.setSDKProcessingMetadata({
request: req,
requestDataOptionsFromGCPWrapper: options.addRequestDataToEventOptions,
});
// We put the transaction on the scope so users can attach children to it
scope.setSpan(transaction);
return startSpanManual(
{
...continueTraceContext,
name: `${reqMethod} ${reqUrl}`,
op: 'function.gcp.http',
origin: 'auto.function.serverless.gcp_http',
// We also set __sentry_transaction on the response so people can grab the transaction there to add
// spans to it later.
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
(res ).__sentry_transaction = transaction;
metadata: {
...continueTraceContext.metadata,
source: 'route',
},
},
span => {
getCurrentScope().setSDKProcessingMetadata({
request: req,
requestDataOptionsFromGCPWrapper: options.addRequestDataToEventOptions,
});
// eslint-disable-next-line @typescript-eslint/unbound-method
const _end = res.end;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
res.end = function (chunk, encoding, cb) {
_optionalChain([transaction, 'optionalAccess', _3 => _3.setHttpStatus, 'call', _4 => _4(res.statusCode)]);
_optionalChain([transaction, 'optionalAccess', _5 => _5.end, 'call', _6 => _6()]);
if (span instanceof Transaction) {
// We also set __sentry_transaction on the response so people can grab the transaction there to add
// spans to it later.
// TODO(v8): Remove this
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
(res ).__sentry_transaction = span;
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
flush(options.flushTimeout)
.then(null, e => {
DEBUG_BUILD && logger.error(e);
})
.then(() => {
_end.call(this, chunk, encoding, cb);
});
};
// eslint-disable-next-line @typescript-eslint/unbound-method
const _end = res.end;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
res.end = function (chunk, encoding, cb) {
_optionalChain([span, 'optionalAccess', _3 => _3.setHttpStatus, 'call', _4 => _4(res.statusCode)]);
_optionalChain([span, 'optionalAccess', _5 => _5.end, 'call', _6 => _6()]);
let fnResult;
try {
fnResult = fn(req, res);
} catch (err) {
captureException(err, scope => markEventUnhandled(scope));
throw err;
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
flush(options.flushTimeout)
.then(null, e => {
DEBUG_BUILD && logger.error(e);
})
.then(() => {
_end.call(this, chunk, encoding, cb);
});
};
if (isThenable(fnResult)) {
fnResult.then(null, err => {
captureException(err, scope => markEventUnhandled(scope));
throw err;
});
}
return fnResult;
return handleCallbackErrors(
() => fn(req, res),
err => {
captureException(err, scope => markEventUnhandled(scope));
},
);
},
);
};

@@ -123,0 +110,0 @@ }

{
"name": "@sentry/serverless",
"version": "7.91.0",
"version": "7.92.0",
"description": "Official Sentry SDK for various serverless solutions",

@@ -12,2 +12,8 @@ "repository": "git://github.com/getsentry/sentry-javascript.git",

},
"files": [
"cjs",
"esm",
"types",
"types-ts3.8"
],
"main": "cjs/index.js",

@@ -27,6 +33,6 @@ "module": "esm/index.js",

"dependencies": {
"@sentry/core": "7.91.0",
"@sentry/node": "7.91.0",
"@sentry/types": "7.91.0",
"@sentry/utils": "7.91.0",
"@sentry/core": "7.92.0",
"@sentry/node": "7.92.0",
"@sentry/types": "7.92.0",
"@sentry/utils": "7.92.0",
"@types/aws-lambda": "^8.10.62",

@@ -33,0 +39,0 @@ "@types/express": "^4.17.14"

@@ -1,2 +0,2 @@

import * as Sentry from '@sentry/node';
import { NodeOptions } from '@sentry/node';
import { Integration } from '@sentry/types';

@@ -29,3 +29,3 @@ import { Handler } from 'aws-lambda';

export declare const defaultIntegrations: Integration[];
interface AWSLambdaOptions extends Sentry.NodeOptions {
interface AWSLambdaOptions extends NodeOptions {
/**

@@ -38,3 +38,5 @@ * Internal field that is set to `true` when init() is called by the Sentry AWS Lambda layer.

/**
* @see {@link Sentry.init}
* Initializes the Sentry AWS Lambda SDK.
*
* @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
*/

@@ -41,0 +43,0 @@ export declare function init(options?: AWSLambdaOptions): void;

@@ -1,2 +0,2 @@

import * as Sentry from '@sentry/node';
import type { NodeOptions } from '@sentry/node';
import type { Integration } from '@sentry/types';

@@ -29,3 +29,3 @@ import type { Handler } from 'aws-lambda';

export declare const defaultIntegrations: Integration[];
interface AWSLambdaOptions extends Sentry.NodeOptions {
interface AWSLambdaOptions extends NodeOptions {
/**

@@ -38,3 +38,5 @@ * Internal field that is set to `true` when init() is called by the Sentry AWS Lambda layer.

/**
* @see {@link Sentry.init}
* Initializes the Sentry AWS Lambda SDK.
*
* @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
*/

@@ -41,0 +43,0 @@ export declare function init(options?: AWSLambdaOptions): void;

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc