MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / init

Function init

packages/aws-serverless/src/init.ts:71–115  ·  view source on GitHub ↗
(options: AwsServerlessOptions = {})

Source from the content-addressed store, hash-verified

69 * @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
70 */
71export function init(options: AwsServerlessOptions = {}): NodeClient | undefined {
72 const sdkSource = getSDKSource();
73 const proxyWouldInterfere = shouldDisableLayerExtensionForProxy();
74
75 // Determine useLayerExtension value with the following priority:
76 // 1. Explicit option value (if provided)
77 // 2. Environment variable SENTRY_LAYER_EXTENSION (if set)
78 // 3. Default logic based on sdkSource, tunnel, and proxy settings
79 const useLayerExtensionFromEnv = envToBool(process.env.SENTRY_LAYER_EXTENSION, { strict: true });
80 const defaultUseLayerExtension = sdkSource === 'aws-lambda-layer' && !options.tunnel && !proxyWouldInterfere;
81 const useLayerExtension = options.useLayerExtension ?? useLayerExtensionFromEnv ?? defaultUseLayerExtension;
82
83 const opts = {
84 defaultIntegrations: getDefaultIntegrations(options),
85 useLayerExtension,
86 ...options,
87 };
88
89 if (opts.useLayerExtension) {
90 if (sdkSource !== 'aws-lambda-layer') {
91 DEBUG_BUILD && debug.warn('The Sentry Lambda extension is only supported when using the AWS Lambda layer.');
92 } else if (opts.tunnel || proxyWouldInterfere) {
93 if (opts.tunnel) {
94 DEBUG_BUILD &&
95 debug.warn(
96 `Using a custom tunnel with the Sentry Lambda extension is not supported. Events will be tunnelled to ${opts.tunnel} and not through the extension.`,
97 );
98 }
99
100 if (proxyWouldInterfere) {
101 DEBUG_BUILD &&
102 debug.warn(
103 'Sentry Lambda extension is disabled due to proxy environment variables (http_proxy/https_proxy). Consider adding localhost to no_proxy to re-enable.',
104 );
105 }
106 } else {
107 DEBUG_BUILD && debug.log('Proxying Sentry events through the Sentry Lambda extension');
108 opts.tunnel = 'http://localhost:9000/envelope';
109 }
110 }
111
112 applySdkMetadata(opts, 'aws-serverless', ['aws-serverless', 'node'], sdkSource);
113
114 return initWithoutDefaultIntegrations(opts);
115}

Callers 2

init.test.tsFile · 0.90
sdk.test.tsFile · 0.90

Calls 8

getSDKSourceFunction · 0.90
applySdkMetadataFunction · 0.90
envToBoolFunction · 0.85
getDefaultIntegrationsFunction · 0.70
warnMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected