Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(serverless): Point DSN to relay in lambda extension #5126

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@sentry/node';
import { extractTraceparentData } from '@sentry/tracing';
import { Integration } from '@sentry/types';
import { isString, logger } from '@sentry/utils';
import { extensionRelayDSN, isString, logger } 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';
Expand Down Expand Up @@ -79,6 +79,8 @@ export function init(options: Sentry.NodeOptions = {}): void {
version: Sentry.SDK_VERSION,
};

options.dsn = extensionRelayDSN(options.dsn)

Sentry.init(options);
Sentry.addGlobalEventProcessor(serverlessEventProcessor);
}
Expand Down
28 changes: 28 additions & 0 deletions packages/utils/src/dsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export function dsnToString(dsn: DsnComponents, withPassword: boolean = false):
);
}

/**
* Parses a Dsn from a given string.
*
* @param str A Dsn as string
* @returns Dsn as DsnComponents
*/
function dsnFromString(str: string): DsnComponents {
const match = DSN_REGEX.exec(str);

Expand Down Expand Up @@ -101,3 +107,25 @@ 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);
}