Skip to content

feat(v8): Add @sentry/aws-serverless package #11052

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

Merged
merged 7 commits into from
Mar 12, 2024
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: 2 additions & 2 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ targets:

## 5. Node-based Packages
- name: npm
id: '@sentry/serverless'
includeNames: /^sentry-serverless-\d.*\.tgz$/
id: '@sentry/aws-serverless'
includeNames: /^sentry-aws-serverless-\d.*\.tgz$/
- name: npm
id: '@sentry/google-cloud'
includeNames: /^sentry-google-cloud-\d.*\.tgz$/
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ body:
- '@sentry/astro'
- '@sentry/angular'
- '@sentry/angular-ivy'
- '@sentry/aws-serverless'
- '@sentry/bun'
- '@sentry/deno'
- '@sentry/ember'
Expand All @@ -42,7 +43,6 @@ body:
- '@sentry/node'
- '@sentry/react'
- '@sentry/remix'
- '@sentry/serverless'
- '@sentry/google-cloud'
- '@sentry/svelte'
- '@sentry/sveltekit'
Expand Down
50 changes: 50 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ We've removed the following packages:
- [@sentry/hub](./MIGRATION.md#sentryhub)
- [@sentry/tracing](./MIGRATION.md#sentrytracing)
- [@sentry/integrations](./MIGRATION.md#sentryintegrations)
- [@sentry/serverless](./MIGRATION.md#sentryserverless)

#### @sentry/hub

Expand Down Expand Up @@ -167,6 +168,55 @@ Integrations that are now exported from `@sentry/node` and `@sentry/browser` (or

The `Transaction` integration has been removed from `@sentry/integrations`. There is no replacement API.

#### @sentry/serverless

`@sentry/serverless` has been removed and will no longer be published. The serverless package has been split into two
different packages, `@sentry/aws-serverless` and `@sentry/google-cloud`. These new packages have smaller bundle size
than `@sentry/serverless`, which should improve your serverless cold-start times.

`@sentry/aws-serverless` and `@sentry/google-cloud` has also been changed to only emit CJS builds. The ESM build for the
`@sentry/serverless` package was always broken and we decided to remove it entirely. ESM support will be re-added at a
later date.

In `@sentry/serverless` you had to use a namespace import to initialize the SDK. This has been removed so that you can
directly import from the SDK instead.

```js
// v7
const Sentry = require('@sentry/serverless');

Sentry.AWSLambda.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
});

// v8
const Sentry = require('@sentry/aws-serverless');

Sentry.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
});
```

```js
// v7
const Sentry = require('@sentry/serverless');

Sentry.GCPFunction.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
});

// v8
const Sentry = require('@sentry/google-cloud');

Sentry.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
});
```

## 3. Performance Monitoring Changes

- [Performance Monitoring API](./MIGRATION.md#performance-monitoring-api)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ package. Please refer to the README and instructions of those SDKs for more deta
- [`@sentry/gatsby`](https://github.com/getsentry/sentry-javascript/tree/master/packages/gatsby): SDK for Gatsby
- [`@sentry/nextjs`](https://github.com/getsentry/sentry-javascript/tree/master/packages/nextjs): SDK for Next.js
- [`@sentry/remix`](https://github.com/getsentry/sentry-javascript/tree/master/packages/remix): SDK for Remix
- [`@sentry/serverless`](https://github.com/getsentry/sentry-javascript/tree/master/packages/serverless): SDK for
Serverless Platforms (AWS, GCP)
- [`@sentry/aws-serverless`](https://github.com/getsentry/sentry-javascript/tree/master/packages/aws-serverless): SDK
for AWS Lambda Functions
- [`@sentry/google-cloud`](https://github.com/getsentry/sentry-javascript/tree/master/packages/google-cloud): SDK for
Google Cloud Functions
- [`@sentry/electron`](https://github.com/getsentry/sentry-electron): SDK for Electron with support for native crashes
- [`@sentry/react-native`](https://github.com/getsentry/sentry-react-native): SDK for React Native with support for
native crashes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@sentry/remix": "latest || *",
"@sentry/astro": "latest || *",
"@sentry/nextjs": "latest || *",
"@sentry/serverless": "latest || *",
"@sentry/aws-serverless": "latest || *",
"@sentry/google-cloud": "latest || *",
"@sentry/bun": "latest || *",
"@sentry/types": "latest || *",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import * as SentryNextJs from '@sentry/nextjs';
import * as SentryNode from '@sentry/node';
import * as SentryNodeExperimental from '@sentry/node-experimental';
import * as SentryRemix from '@sentry/remix';
import * as SentryServerless from '@sentry/serverless';
import * as SentrySvelteKit from '@sentry/sveltekit';

// SentryAWS is CJS only
const SentryAWS = require('@sentry/aws-serverless');

/* List of exports that are safe to ignore / we don't require in any depending package */
const NODE_EXPERIMENTAL_EXPORTS_IGNORE = [
'default',
Expand Down Expand Up @@ -77,10 +79,10 @@ const DEPENDENTS: Dependent[] = [
exports: Object.keys(SentryRemix),
},
{
package: '@sentry/serverless',
compareWith: nodeExperimentalExports,
exports: Object.keys(SentryServerless),
ignoreExports: ['cron', 'hapiErrorPlugin'],
package: '@sentry/aws-serverless',
compareWith: nodeExports,
exports: Object.keys(SentryAWS),
ignoreExports: ['makeMain'],
},
{
package: '@sentry/google-cloud',
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/e2e-tests/verdaccio-config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ packages:
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry/serverless':
'@sentry/aws-serverless':
access: $all
publish: $all
unpublish: $all
Expand Down
7 changes: 5 additions & 2 deletions dev-packages/rollup-utils/bundleHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
makeCleanupPlugin,
makeCommonJSPlugin,
makeIsDebugBuildPlugin,
makeJsonPlugin,
makeLicensePlugin,
makeNodeResolvePlugin,
makeRrwebBuildPlugin,
Expand Down Expand Up @@ -40,6 +41,8 @@ export function makeBaseBundleConfig(options) {
// at all, and without `transformMixedEsModules`, they're only included if they're imported, not if they're required.)
const commonJSPlugin = makeCommonJSPlugin({ transformMixedEsModules: true });

const jsonPlugin = makeJsonPlugin();

// used by `@sentry/browser`
const standAloneBundleConfig = {
output: {
Expand Down Expand Up @@ -84,12 +87,12 @@ export function makeBaseBundleConfig(options) {
plugins: [rrwebBuildPlugin, markAsBrowserBuildPlugin],
};

// used by `@sentry/serverless`, when creating the lambda layer
// used by `@sentry/aws-serverless`, when creating the lambda layer
const nodeBundleConfig = {
output: {
format: 'cjs',
},
plugins: [commonJSPlugin],
plugins: [jsonPlugin, commonJSPlugin],
// Don't bundle any of Node's core modules
external: builtinModules,
};
Expand Down
15 changes: 10 additions & 5 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ export function makeBaseNPMConfig(options = {}) {
});
}

export function makeNPMConfigVariants(baseConfig) {
const variantSpecificConfigs = [
{ output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } },
{ output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm'), plugins: [makePackageNodeEsm()] } },
];
export function makeNPMConfigVariants(baseConfig, options = {}) {
const { emitEsm = true } = options;

const variantSpecificConfigs = [{ output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } }];

if (emitEsm) {
variantSpecificConfigs.push({
output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm'), plugins: [makePackageNodeEsm()] },
});
}

return variantSpecificConfigs.map(variant => deepMerge(baseConfig, variant));
}
7 changes: 7 additions & 0 deletions dev-packages/rollup-utils/plugins/npmPlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase
*/

import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import sucrase from '@rollup/plugin-sucrase';
import cleanup from 'rollup-plugin-cleanup';
Expand All @@ -18,11 +19,17 @@ import cleanup from 'rollup-plugin-cleanup';
*/
export function makeSucrasePlugin(options = {}) {
return sucrase({
// Required for bundling OTEL code properly
exclude: ['**/*.json'],
transforms: ['typescript', 'jsx'],
...options,
});
}

export function makeJsonPlugin() {
return json();
}

/**
* Create a plugin which can be used to pause the build process at the given hook.
*
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"packages/angular",
"packages/angular-ivy",
"packages/astro",
"packages/aws-serverless",
"packages/browser",
"packages/bun",
"packages/core",
Expand All @@ -68,7 +69,6 @@
"packages/replay",
"packages/replay-canvas",
"packages/replay-worker",
"packages/serverless",
"packages/svelte",
"packages/sveltekit",
"packages/tracing-internal",
Expand All @@ -87,6 +87,7 @@
"devDependencies": {
"@biomejs/biome": "^1.4.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^3.0.1",
"@rollup/plugin-sucrase": "^4.0.3",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@
## General

This package is a wrapper around `@sentry/node`, with added functionality related to various Serverless solutions. All
methods available in `@sentry/node` can be imported from `@sentry/serverless`.
methods available in `@sentry/node` can be imported from `@sentry/aws-serverless`.

Currently supported environment:

### AWS Lambda

To use this SDK, call `Sentry.AWSLambda.init(options)` at the very beginning of your JavaScript file.
To use this SDK, call `Sentry.init(options)` at the very beginning of your JavaScript file.

```javascript
import * as Sentry from '@sentry/serverless';
import * as Sentry from '@sentry/aws-serverless';

Sentry.AWSLambda.init({
Sentry.init({
dsn: '__DSN__',
// ...
});

// async (recommended)
exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
exports.handler = Sentry.wrapHandler(async (event, context) => {
throw new Error('oh, hello there!');
});

// sync
exports.handler = Sentry.AWSLambda.wrapHandler((event, context, callback) => {
exports.handler = Sentry.wrapHandler((event, context, callback) => {
throw new Error('oh, hello there!');
});
```

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';
import * as Sentry from '@sentry/aws-serverless';

Sentry.AWSLambda.init({
dsn: '__DSN__',
Expand All @@ -59,38 +59,6 @@ Another and much simpler way to integrate Sentry to your AWS Lambda function is
1. Choose Layers -> Add Layer.
2. Specify an ARN: `arn:aws:lambda:us-west-1:TODO:layer:TODO:VERSION`.
3. Go to Environment variables and add:
- `NODE_OPTIONS`: `-r @sentry/serverless/build/npm/cjs/awslambda-auto`.
- `NODE_OPTIONS`: `-r @sentry/aws-serverless/build/npm/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).

### Google Cloud Functions

To use this SDK, call `Sentry.GCPFunction.init(options)` at the very beginning of your JavaScript file.

```javascript
import * as Sentry from '@sentry/serverless';

Sentry.GCPFunction.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
// ...
});

// For HTTP Functions:

exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
throw new Error('oh, hello there!');
});

// For Background Functions:

exports.helloEvents = Sentry.GCPFunction.wrapEventFunction((data, context, callback) => {
throw new Error('oh, hello there!');
});

// For CloudEvents:

exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction((context, callback) => {
throw new Error('oh, hello there!');
});
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sentry/serverless",
"name": "@sentry/aws-serverless",
"version": "8.0.0-alpha.2",
"description": "Official Sentry SDK for various serverless solutions",
"description": "Official Sentry SDK for AWS Lambda and AWS Serverless Environments",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/serverless",
"author": "Sentry",
Expand All @@ -11,20 +11,14 @@
},
"files": [
"cjs",
"esm",
"types",
"types-ts3.8"
],
"main": "build/npm/cjs/index.js",
"module": "build/npm/esm/index.js",
"types": "build/npm/types/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./build/npm/types/index.d.ts",
"default": "./build/npm/esm/index.js"
},
"require": {
"types": "./build/npm/types/index.d.ts",
"default": "./build/npm/cjs/index.js"
Expand All @@ -43,21 +37,16 @@
},
"dependencies": {
"@sentry/core": "8.0.0-alpha.2",
"@sentry/node-experimental": "8.0.0-alpha.2",
"@sentry/node": "8.0.0-alpha.2",
"@sentry/types": "8.0.0-alpha.2",
"@sentry/utils": "8.0.0-alpha.2",
"@types/aws-lambda": "^8.10.62",
"@types/express": "^4.17.14"
},
"devDependencies": {
"@google-cloud/bigquery": "^5.3.0",
"@google-cloud/common": "^3.4.1",
"@google-cloud/functions-framework": "^1.7.1",
"@google-cloud/pubsub": "^2.5.0",
"@types/node": "^14.6.4",
"aws-sdk": "^2.765.0",
"find-up": "^5.0.0",
"google-gax": "^2.9.0",
"nock": "^13.0.4",
"npm-packlist": "^2.1.4"
},
Expand Down
Loading