From 3e0ac888a85a9d26d5ff277a63df4fe4abc306c1 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 31 May 2022 15:01:43 +0200 Subject: [PATCH 01/11] Reactivated deployment of aws lambda layer --- .craft.yml | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/.craft.yml b/.craft.yml index c28e4777a220..44d48ec03684 100644 --- a/.craft.yml +++ b/.craft.yml @@ -2,20 +2,16 @@ minVersion: '0.23.1' changelogPolicy: simple preReleaseCommand: bash scripts/craft-pre-release.sh targets: - # - # Deactivated for now. This needs to be reactivated if the new Sentry Lambda Extension is deployed to production. - # (ask Anton Pirker if you have questions.) - # - # - name: aws-lambda-layer - # includeNames: /^sentry-node-serverless-\d+.\d+.\d+(-(beta|alpha)\.\d+)?\.zip$/ - # layerName: SentryNodeServerlessSDK - # compatibleRuntimes: - # - name: node - # versions: - # - nodejs10.x - # - nodejs12.x - # - nodejs14.x - # license: MIT + - name: aws-lambda-layer + includeNames: /^sentry-node-serverless-\d+.\d+.\d+(-(beta|alpha)\.\d+)?\.zip$/ + layerName: SentryNodeServerlessSDK + compatibleRuntimes: + - name: node + versions: + - nodejs10.x + - nodejs12.x + - nodejs14.x + license: MIT - name: gcs includeNames: /.*\.js.*$/ bucket: sentry-js-sdk From 53f8cba9625bac990a73399df35f82eabac50a6f Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 3 Jun 2022 15:55:41 +0200 Subject: [PATCH 02/11] Fixed deploy script for local code base. --- scripts/aws-deploy-local-layer.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/aws-deploy-local-layer.sh b/scripts/aws-deploy-local-layer.sh index b86dcd344d78..7d659eb82921 100755 --- a/scripts/aws-deploy-local-layer.sh +++ b/scripts/aws-deploy-local-layer.sh @@ -37,12 +37,28 @@ echo "Done copying Lambda layer in ./packages/serverless/build/aws/dist-serverle # is building the Lambda layer in production! # see: https://github.com/getsentry/action-build-aws-lambda-extension/blob/main/action.yml#L23-L40 -# Adding Sentry Lambda extension to Lambda layer -echo "Adding Sentry Lambda extension to Lambda layer in ./dist-serverless..." +echo "Downloading relay..." +mkdir -p dist-serverless/relay +# curl -0 --silent \ +# --output dist-serverless/relay/relay \ +# "$(curl -s https://release-registry.services.sentry.io/apps/relay/latest | jq -r .files.\"relay-Linux-x86_64\".url)" +cp /Users/antonpirker/code/relay/target/x86_64-unknown-linux-gnu/release/relay dist-serverless/relay/ # REMOVE THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +chmod +x dist-serverless/relay/relay +echo "Done downloading relay." + +echo "Creating start script..." mkdir -p dist-serverless/extensions -curl -0 --silent --output dist-serverless/extensions/sentry-lambda-extension $(curl -s https://release-registry.services.sentry.io/apps/sentry-lambda-extension/latest | jq -r .files.\"sentry-lambda-extension\".url) +cat > dist-serverless/extensions/sentry-lambda-extension << EOT +#!/bin/bash +set -euo pipefail +exec /opt/relay/relay run \ + --mode=proxy \ + --shutdown-timeout=2 \ + --upstream-dsn="\$SENTRY_DSN" \ + --aws-runtime-api="\$AWS_LAMBDA_RUNTIME_API" +EOT chmod +x dist-serverless/extensions/sentry-lambda-extension -echo "Done adding Sentry Lambda extension to Lambda layer in ./dist-serverless." +echo "Done creating start script." # Zip Lambda layer and included Lambda extension echo "Zipping Lambda layer and included Lambda extension..." From 677840f8bb7022fff6a35d79cea36ec0904b8fcf Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 3 Jun 2022 15:58:56 +0200 Subject: [PATCH 03/11] Removed debug command --- scripts/aws-deploy-local-layer.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/aws-deploy-local-layer.sh b/scripts/aws-deploy-local-layer.sh index 7d659eb82921..d1827454f334 100755 --- a/scripts/aws-deploy-local-layer.sh +++ b/scripts/aws-deploy-local-layer.sh @@ -39,10 +39,9 @@ echo "Done copying Lambda layer in ./packages/serverless/build/aws/dist-serverle echo "Downloading relay..." mkdir -p dist-serverless/relay -# curl -0 --silent \ -# --output dist-serverless/relay/relay \ -# "$(curl -s https://release-registry.services.sentry.io/apps/relay/latest | jq -r .files.\"relay-Linux-x86_64\".url)" -cp /Users/antonpirker/code/relay/target/x86_64-unknown-linux-gnu/release/relay dist-serverless/relay/ # REMOVE THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +curl -0 --silent \ + --output dist-serverless/relay/relay \ + "$(curl -s https://release-registry.services.sentry.io/apps/relay/latest | jq -r .files.\"relay-Linux-x86_64\".url)" chmod +x dist-serverless/relay/relay echo "Done downloading relay." From 7c272843c0d5e81aa3029d00c3ed927cddedb515 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 7 Jun 2022 10:10:35 +0200 Subject: [PATCH 04/11] Added more comments --- scripts/aws-deploy-local-layer.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/aws-deploy-local-layer.sh b/scripts/aws-deploy-local-layer.sh index d1827454f334..a979ddbbdcbe 100755 --- a/scripts/aws-deploy-local-layer.sh +++ b/scripts/aws-deploy-local-layer.sh @@ -10,7 +10,7 @@ set -euo pipefail -# Cleanup +# Remove old distribution directories and zip files. echo "Preparing local directories for new build..." rm -rf dist-serverless/ rm -rf ./packages/serverless/build @@ -38,15 +38,23 @@ echo "Done copying Lambda layer in ./packages/serverless/build/aws/dist-serverle # see: https://github.com/getsentry/action-build-aws-lambda-extension/blob/main/action.yml#L23-L40 echo "Downloading relay..." +# Make directory (if not existing) mkdir -p dist-serverless/relay +# Download releay from release registry to dist-serverless/relay/relay curl -0 --silent \ --output dist-serverless/relay/relay \ "$(curl -s https://release-registry.services.sentry.io/apps/relay/latest | jq -r .files.\"relay-Linux-x86_64\".url)" +# Make file executable chmod +x dist-serverless/relay/relay echo "Done downloading relay." echo "Creating start script..." +# Make directory (if not existing) mkdir -p dist-serverless/extensions +# Create 'sentry-lambda-extension' script that starts relay. +# The file has to have exactly this name, because the executable files of +# Lambda extensions need to have same file name as the name that they use +# to register with AWS Lambda environment cat > dist-serverless/extensions/sentry-lambda-extension << EOT #!/bin/bash set -euo pipefail @@ -56,6 +64,7 @@ exec /opt/relay/relay run \ --upstream-dsn="\$SENTRY_DSN" \ --aws-runtime-api="\$AWS_LAMBDA_RUNTIME_API" EOT +# Make script executable chmod +x dist-serverless/extensions/sentry-lambda-extension echo "Done creating start script." From 51fdf68641077ae7378c148bb781ef7d02298ab3 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 7 Jun 2022 10:19:43 +0200 Subject: [PATCH 05/11] Added comment for clarification --- packages/serverless/src/awslambda.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index a2825b1e1e2e..89ab95e40424 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -79,6 +79,7 @@ export function init(options: Sentry.NodeOptions = {}): void { version: Sentry.SDK_VERSION, }; + // Point the SDK to the Lambda Extension instead of the host specified in the DSN options.dsn = extensionRelayDSN(options.dsn); Sentry.init(options); From 22e95dc5b776a5abfab84c7af56ddc9e7dfd0d55 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 29 Jun 2022 14:45:18 +0200 Subject: [PATCH 06/11] Fixed linting --- packages/serverless/README.md | 8 +++++--- packages/serverless/src/awslambda.ts | 3 +-- packages/serverless/tsconfig.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/serverless/README.md b/packages/serverless/README.md index c0ac6f7659aa..93d979194590 100644 --- a/packages/serverless/README.md +++ b/packages/serverless/README.md @@ -41,7 +41,8 @@ exports.handler = Sentry.AWSLambda.wrapHandler((event, context, callback) => { }); ``` -If you also want to trace performance of all the incoming requests and also outgoing AWS service requests, just set the `tracesSampleRate` option. +If you also want to trace performance of all the incoming requests and also outgoing AWS service requests, just set the +`tracesSampleRate` option. ```javascript import * as Sentry from '@sentry/serverless'; @@ -61,8 +62,9 @@ Another and much simpler way to integrate Sentry to your AWS Lambda function is 3. Go to Environment variables and add: - `NODE_OPTIONS`: `-r @sentry/serverless/cjs/awslambda-auto`. - `SENTRY_DSN`: `your dsn`. - - `SENTRY_TRACES_SAMPLE_RATE`: a number between 0 and 1 representing the chance a transaction is sent to Sentry. For more information, see [docs](https://docs.sentry.io/platforms/node/guides/aws-lambda/configuration/options/#tracesSampleRate). - + - `SENTRY_TRACES_SAMPLE_RATE`: a number between 0 and 1 representing the chance a transaction is sent to Sentry. For + more information, see + [docs](https://docs.sentry.io/platforms/node/guides/aws-lambda/configuration/options/#tracesSampleRate). ### Google Cloud Functions diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index feb198aecd34..8dfdca283ac0 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -11,8 +11,7 @@ import { } from '@sentry/node'; import { extractTraceparentData } from '@sentry/tracing'; import { Integration } from '@sentry/types'; -import { isString, logger, parseBaggageSetMutability } from '@sentry/utils'; -import { extensionRelayDSN } from '@sentry/utils' +import { extensionRelayDSN, isString, logger, parseBaggageSetMutability } from '@sentry/utils'; // NOTE: I have no idea how to fix this right now, and don't want to waste more time, as it builds just fine — Kamil // eslint-disable-next-line import/no-unresolved import { Context, Handler } from 'aws-lambda'; diff --git a/packages/serverless/tsconfig.json b/packages/serverless/tsconfig.json index 7fccf7258ead..05c709778aa0 100644 --- a/packages/serverless/tsconfig.json +++ b/packages/serverless/tsconfig.json @@ -5,6 +5,6 @@ "compilerOptions": { // package-specific options - "target": "ES2018", + "target": "ES2018" } } From dab5f85448955e5c453573ec3fd51ba2b5607783 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 4 Jul 2022 16:07:55 +0200 Subject: [PATCH 07/11] Only change DSN when init() is invoked by the Sentry AWS Lambda layer --- packages/node/src/types.ts | 9 ++++++++- packages/serverless/src/awslambda-auto.ts | 4 +++- packages/serverless/src/awslambda.ts | 9 +++++++-- yarn.lock | 18 ------------------ 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/packages/node/src/types.ts b/packages/node/src/types.ts index 57b19dcd1820..bf59d24d6406 100644 --- a/packages/node/src/types.ts +++ b/packages/node/src/types.ts @@ -6,15 +6,22 @@ export interface BaseNodeOptions { /** Sets an optional server name (device name) */ serverName?: string; + invokedByLambdaLayer?: boolean; + /** Callback that is executed when a fatal global error occurs. */ onFatalError?(error: Error): void; } +export interface AWSLambdaOptions { + /** Set when init() is called by the Sentry AWS Lambda layer. */ + invokedByLambdaLayer?: boolean; +} + /** * Configuration options for the Sentry Node SDK * @see @sentry/types Options for more information. */ -export interface NodeOptions extends Options, BaseNodeOptions {} +export interface NodeOptions extends Options, BaseNodeOptions, AWSLambdaOptions {} /** * Configuration options for the Sentry Node SDK Client class diff --git a/packages/serverless/src/awslambda-auto.ts b/packages/serverless/src/awslambda-auto.ts index ac63f117063f..f933345a1b9f 100644 --- a/packages/serverless/src/awslambda-auto.ts +++ b/packages/serverless/src/awslambda-auto.ts @@ -6,7 +6,9 @@ if (lambdaTaskRoot) { if (!handlerString) { throw Error(`LAMBDA_TASK_ROOT is non-empty(${lambdaTaskRoot}) but _HANDLER is not set`); } - Sentry.AWSLambda.init(); + Sentry.AWSLambda.init({ + invokedByLambdaLayer: true, + }); Sentry.AWSLambda.tryPatchHandler(lambdaTaskRoot, handlerString); } else { throw Error('LAMBDA_TASK_ROOT environment variable is not set'); diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index 8dfdca283ac0..4f08dfbec90c 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -78,8 +78,13 @@ export function init(options: Sentry.NodeOptions = {}): void { version: Sentry.SDK_VERSION, }; - // Point the SDK to the Lambda Extension instead of the host specified in the DSN - options.dsn = extensionRelayDSN(options.dsn); + // If invoked by the Sentry Lambda Layer, + // point the SDK to the Lambda Extension (inside the layer) instead of the host specified in the DSN + if ('invokedByAWSLambdaLayer' in options && options.invokedByAWSLambdaLayer === true) { + options.dsn = extensionRelayDSN(options.dsn); + } + // Do not leak `invokedByAWSLambdaLayer` into the call to Sentry.init(). + delete options.invokedByAWSLambdaLayer; Sentry.init(options); Sentry.addGlobalEventProcessor(serverlessEventProcessor); diff --git a/yarn.lock b/yarn.lock index e7683ac1d4c1..66bc20ec403c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26724,11 +26724,6 @@ yargs-parser@^20.2.3: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.7.tgz#61df85c113edfb5a7a4e36eb8aa60ef423cbc90a" integrity sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw== -yargs-parser@^21.0.0: - version "21.0.1" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35" - integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg== - yargs-unparser@1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-1.6.0.tgz#ef25c2c769ff6bd09e4b0f9d7c605fb27846ea9f" @@ -26802,19 +26797,6 @@ yargs@^16.1.1, yargs@^16.2.0: y18n "^5.0.5" yargs-parser "^20.2.2" -yargs@^17.5.1: - version "17.5.1" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.5.1.tgz#e109900cab6fcb7fd44b1d8249166feb0b36e58e" - integrity sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA== - dependencies: - cliui "^7.0.2" - escalade "^3.1.1" - get-caller-file "^2.0.5" - require-directory "^2.1.1" - string-width "^4.2.3" - y18n "^5.0.5" - yargs-parser "^21.0.0" - yauzl@^2.10.0: version "2.10.0" resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9" From acb476c77a36be4c8353b4a51b0ce4e0d8c3b6d1 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 4 Jul 2022 16:28:34 +0200 Subject: [PATCH 08/11] Cleaned up experiment. --- packages/node/src/types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/node/src/types.ts b/packages/node/src/types.ts index bf59d24d6406..50413b66d368 100644 --- a/packages/node/src/types.ts +++ b/packages/node/src/types.ts @@ -6,8 +6,6 @@ export interface BaseNodeOptions { /** Sets an optional server name (device name) */ serverName?: string; - invokedByLambdaLayer?: boolean; - /** Callback that is executed when a fatal global error occurs. */ onFatalError?(error: Error): void; } From 0a894c1edadccc3f9eb42e10e4378331e9ac5d3d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 4 Jul 2022 16:18:28 +0000 Subject: [PATCH 09/11] Reshuffle things --- packages/node/src/types.ts | 7 +------ packages/serverless/README.md | 7 ++----- packages/serverless/src/awslambda-auto.ts | 4 +++- packages/serverless/src/awslambda.ts | 18 ++++++++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/node/src/types.ts b/packages/node/src/types.ts index 50413b66d368..57b19dcd1820 100644 --- a/packages/node/src/types.ts +++ b/packages/node/src/types.ts @@ -10,16 +10,11 @@ export interface BaseNodeOptions { onFatalError?(error: Error): void; } -export interface AWSLambdaOptions { - /** Set when init() is called by the Sentry AWS Lambda layer. */ - invokedByLambdaLayer?: boolean; -} - /** * Configuration options for the Sentry Node SDK * @see @sentry/types Options for more information. */ -export interface NodeOptions extends Options, BaseNodeOptions, AWSLambdaOptions {} +export interface NodeOptions extends Options, BaseNodeOptions {} /** * Configuration options for the Sentry Node SDK Client class diff --git a/packages/serverless/README.md b/packages/serverless/README.md index 93d979194590..0f61fae3afb9 100644 --- a/packages/serverless/README.md +++ b/packages/serverless/README.md @@ -41,8 +41,7 @@ exports.handler = Sentry.AWSLambda.wrapHandler((event, context, callback) => { }); ``` -If you also want to trace performance of all the incoming requests and also outgoing AWS service requests, just set the -`tracesSampleRate` option. +If you also want to trace performance of all the incoming requests and also outgoing AWS service requests, just set the `tracesSampleRate` option. ```javascript import * as Sentry from '@sentry/serverless'; @@ -62,9 +61,7 @@ Another and much simpler way to integrate Sentry to your AWS Lambda function is 3. Go to Environment variables and add: - `NODE_OPTIONS`: `-r @sentry/serverless/cjs/awslambda-auto`. - `SENTRY_DSN`: `your dsn`. - - `SENTRY_TRACES_SAMPLE_RATE`: a number between 0 and 1 representing the chance a transaction is sent to Sentry. For - more information, see - [docs](https://docs.sentry.io/platforms/node/guides/aws-lambda/configuration/options/#tracesSampleRate). + - `SENTRY_TRACES_SAMPLE_RATE`: a number between 0 and 1 representing the chance a transaction is sent to Sentry. For more information, see [docs](https://docs.sentry.io/platforms/node/guides/aws-lambda/configuration/options/#tracesSampleRate). ### Google Cloud Functions diff --git a/packages/serverless/src/awslambda-auto.ts b/packages/serverless/src/awslambda-auto.ts index f933345a1b9f..ac048cde5aed 100644 --- a/packages/serverless/src/awslambda-auto.ts +++ b/packages/serverless/src/awslambda-auto.ts @@ -6,9 +6,11 @@ if (lambdaTaskRoot) { if (!handlerString) { throw Error(`LAMBDA_TASK_ROOT is non-empty(${lambdaTaskRoot}) but _HANDLER is not set`); } + Sentry.AWSLambda.init({ - invokedByLambdaLayer: true, + _invokedByLambdaLayer: true, }); + Sentry.AWSLambda.tryPatchHandler(lambdaTaskRoot, handlerString); } else { throw Error('LAMBDA_TASK_ROOT environment variable is not set'); diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index 4f08dfbec90c..f0bb3d287da1 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -57,10 +57,18 @@ export interface WrapperOptions { export const defaultIntegrations: Integration[] = [...Sentry.defaultIntegrations, new AWSServices({ optional: true })]; +interface AWSLambdaOptions extends Sentry.NodeOptions { + /** + * Internal field that is set to `true` when init() is called by the Sentry AWS Lambda layer. + * + */ + _invokedByLambdaLayer?: boolean; +} + /** * @see {@link Sentry.init} */ -export function init(options: Sentry.NodeOptions = {}): void { +export function init(options: AWSLambdaOptions = {}): void { if (options.defaultIntegrations === undefined) { options.defaultIntegrations = defaultIntegrations; } @@ -78,13 +86,11 @@ export function init(options: Sentry.NodeOptions = {}): void { version: Sentry.SDK_VERSION, }; - // If invoked by the Sentry Lambda Layer, - // point the SDK to the Lambda Extension (inside the layer) instead of the host specified in the DSN - if ('invokedByAWSLambdaLayer' in options && options.invokedByAWSLambdaLayer === true) { + // If invoked by the Sentry Lambda Layer point the SDK to the Lambda Extension (inside the layer) instead of the host + // specified in the DSN + if (options._invokedByLambdaLayer) { options.dsn = extensionRelayDSN(options.dsn); } - // Do not leak `invokedByAWSLambdaLayer` into the call to Sentry.init(). - delete options.invokedByAWSLambdaLayer; Sentry.init(options); Sentry.addGlobalEventProcessor(serverlessEventProcessor); From 174dbb820bc0429094cb28c4e263a4d23936e31a Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 4 Jul 2022 16:19:01 +0000 Subject: [PATCH 10/11] Move extensionRelayDSN into serverless --- packages/serverless/src/awslambda.ts | 23 ++++++++++++++++++++++- packages/utils/src/dsn.ts | 23 +---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index f0bb3d287da1..bd5c8ced25af 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -11,7 +11,7 @@ import { } from '@sentry/node'; import { extractTraceparentData } from '@sentry/tracing'; import { Integration } from '@sentry/types'; -import { extensionRelayDSN, isString, logger, parseBaggageSetMutability } from '@sentry/utils'; +import { dsnFromString, dsnToString, isString, logger, parseBaggageSetMutability } from '@sentry/utils'; // NOTE: I have no idea how to fix this right now, and don't want to waste more time, as it builds just fine — Kamil // eslint-disable-next-line import/no-unresolved import { Context, Handler } from 'aws-lambda'; @@ -57,6 +57,27 @@ export interface WrapperOptions { export const defaultIntegrations: Integration[] = [...Sentry.defaultIntegrations, new AWSServices({ optional: true })]; +/** + * Changes a Dsn to point to the `relay` server running in the Lambda Extension. + * + * This is only used by the serverless integration for AWS Lambda. + * + * @param originalDsn The original Dsn of the customer. + * @returns Dsn pointing to Lambda extension. + */ +function extensionRelayDSN(originalDsn: string | undefined): string | undefined { + if (originalDsn === undefined) { + return undefined; + } + + const dsn = dsnFromString(originalDsn); + dsn.host = 'localhost'; + dsn.port = '3000'; + dsn.protocol = 'http'; + + return dsnToString(dsn); +} + interface AWSLambdaOptions extends Sentry.NodeOptions { /** * Internal field that is set to `true` when init() is called by the Sentry AWS Lambda layer. diff --git a/packages/utils/src/dsn.ts b/packages/utils/src/dsn.ts index 35c3f0d5d141..a364c47d5d6b 100644 --- a/packages/utils/src/dsn.ts +++ b/packages/utils/src/dsn.ts @@ -32,7 +32,7 @@ export function dsnToString(dsn: DsnComponents, withPassword: boolean = false): * @param str A Dsn as string * @returns Dsn as DsnComponents */ -function dsnFromString(str: string): DsnComponents { +export function dsnFromString(str: string): DsnComponents { const match = DSN_REGEX.exec(str); if (!match) { @@ -106,24 +106,3 @@ export function makeDsn(from: DsnLike): DsnComponents { validateDsn(components); return components; } - -/** - * Changes a Dsn to point to the `relay` server running in the Lambda Extension. - * - * This is only used by the serverless integration for AWS Lambda. - * - * @param originalDsn The original Dsn of the customer. - * @returns Dsn pointing to Lambda extension. - */ -export function extensionRelayDSN(originalDsn: string | undefined): string | undefined { - if (originalDsn === undefined) { - return undefined; - } - - const dsn = dsnFromString(originalDsn); - dsn.host = 'localhost'; - dsn.port = '3000'; - dsn.protocol = 'http'; - - return dsnToString(dsn); -} From 8c6e5ab7c1996eea7169e76abe5d9127c276372e Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 4 Jul 2022 17:37:16 +0000 Subject: [PATCH 11/11] Revert yarn.lock --- yarn.lock | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/yarn.lock b/yarn.lock index 66bc20ec403c..e7683ac1d4c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26724,6 +26724,11 @@ yargs-parser@^20.2.3: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.7.tgz#61df85c113edfb5a7a4e36eb8aa60ef423cbc90a" integrity sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw== +yargs-parser@^21.0.0: + version "21.0.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35" + integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg== + yargs-unparser@1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-1.6.0.tgz#ef25c2c769ff6bd09e4b0f9d7c605fb27846ea9f" @@ -26797,6 +26802,19 @@ yargs@^16.1.1, yargs@^16.2.0: y18n "^5.0.5" yargs-parser "^20.2.2" +yargs@^17.5.1: + version "17.5.1" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.5.1.tgz#e109900cab6fcb7fd44b1d8249166feb0b36e58e" + integrity sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA== + dependencies: + cliui "^7.0.2" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.3" + y18n "^5.0.5" + yargs-parser "^21.0.0" + yauzl@^2.10.0: version "2.10.0" resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"