Skip to content

Feat/node lambda docs #2204

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

Closed
wants to merge 10 commits into from
Closed
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
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,27 @@ jobs:
- run: yarn install
- name: Run Tests
run: yarn build:test

job_linkcheck:
name: Test (Linkchecker)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: volta-cli/action@v1
- uses: actions/cache@v2
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
- run: yarn install
- run: yarn build
- name: Install linkcheck
run: |-
wget https://github.com/filiph/linkcheck/releases/download/v2.0.12/linkcheck-linux-x64.exe -O ./linkcheck
chmod +x ./linkcheck
- name: Install httpserver
run: volta install http-server
- name: Run linkcheck
run: |-
http-server public/ > /dev/null &
sleep 5
./linkcheck
68 changes: 68 additions & 0 deletions src/components/developmentApiSidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from "react";
import { graphql, useStaticQuery } from "gatsby";
import { useLocation } from "@reach/router";

import SidebarLink from "./sidebarLink";
import DynamicNav, { toTree } from "./dynamicNav";

const query = graphql`
query DevelopmentApiNavQuery {
allSitePage(
filter: { path: { regex: "//development-api//" } }
sort: { fields: path }
) {
nodes {
path
context {
title
}
}
}
}
`;

export default () => {
const data = useStaticQuery(query);
const tree = toTree(data.allSitePage.nodes.filter(n => !!n.context));
const endpoints = tree[0].children.filter(curr => curr.children.length > 1);
const location = useLocation();

const isActive = path => location && location.pathname.startsWith(path);

return (
<ul className="list-unstyled" data-sidebar-tree>
<DynamicNav
root="development-api"
title="API Reference"
tree={tree}
exclude={endpoints.map(elem => elem.node.path)}
/>
<li className="mb-3" data-sidebar-branch>
<div
className="sidebar-title d-flex align-items-center mb-0"
data-sidebar-link
>
<h6>Endpoints</h6>
</div>
<ul className="list-unstyled" data-sidebar-tree>
{endpoints.map(({ node: { path, context: { title } }, children }) => (
<React.Fragment key={path}>
<SidebarLink to={path}>{title}</SidebarLink>
{isActive(path) && (
<div style={{ paddingLeft: "0.5rem" }}>
{children
.filter(({ node }) => !!node)
.map(({ node: { path, context: { title } } }) => (
<SidebarLink key={path} to={path}>
{title}
</SidebarLink>
))}
</div>
)}
</React.Fragment>
))}
</ul>
</li>
</ul>
);
};
2 changes: 1 addition & 1 deletion src/components/dynamicNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Entity<T> = {
node: Node | null;
};

interface EntityTree extends Entity<EntityTree> {}
export interface EntityTree extends Entity<EntityTree> {}

export const toTree = (nodeList: Node[]): EntityTree[] => {
const result = [];
Expand Down
2 changes: 1 addition & 1 deletion src/gatsby/createPages/createDevelopmentApiReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default async ({ actions, graphql, reporter }) => {
const data = await getDataOrPanic(
`
query {
allFile(filter: {absolutePath: {}, relativePath: {in: ["permissions.mdx", "auth.mdx", "index.mdx", "requests.mdx"]}, dir: {regex: "/api/"}}) {
allFile(filter: {absolutePath: {}, relativePath: {in: ["permissions.mdx", "auth.mdx", "index.mdx", "requests.mdx", "pagination.mdx"]}, dir: {regex: "/api/"}}) {
nodes {
id
childMarkdownRemark {
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/common/configuration/filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ All Sentry SDKs support the `beforeSend` callback method. `before-send` is calle

<PlatformContent includePath="configuration/before-send" />

Note also that breadcrumbs can be filtered, as discussed in [our Breadcrumbs documentation](/docs/product/error-monitoring/breadcrumbs/).
Note also that breadcrumbs can be filtered, as discussed in [our Breadcrumbs documentation](/product/error-monitoring/breadcrumbs/).

#### Event Hints

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ If Sentry captures some predefined data but doesn’t expose it as a tag, you ca

`level`

: Defines the severity of an event. The level can be set to one of five values, which are, in order of severity: `fatal`, `error`, `warning`, `info`, and `debug.error`. Learn how to set the level in [Set the Level](#set-the-level)
: Defines the severity of an event. The level can be set to one of five values, which are, in order of severity: `fatal`, `error`, `warning`, `info`, and `debug.error`. Learn how to set the level in [Set the Level](./set-level/)

`user`

: Providing user information to Sentry helps you evaluate the number of users affecting an issue and evaluate the quality of the application. Learn how to capture user information in Capture the User

`fingerprint`

: Sentry uses one or more fingerprints to determine how to group errors into issues. Learn more about Sentry's approach to grouping algorithms in [Grouping Events into Issues](/data-management/event-grouping/). Learn how to override the default group in very advanced use cases in [Modify the Default Fingerprint](#modify-the-default-fingerprint)
: Sentry uses one or more fingerprints to determine how to group errors into issues. Learn more about Sentry's approach to grouping algorithms in [Grouping Events into Issues](../../data-management/event-grouping/). Learn how to override the default group in very advanced use cases in [Modify the Default Fingerprint](../../data-management/event-grouping/sdk-fingerprinting/)

`environment`

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/java/guides/logback/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Example configuration using the `logback.xml` format:
</configuration>
```

Next, **you’ll need to configure your DSN** (client key) and optionally other values such as `environment` and `release`. [See the configuration page](config/#setting-the-dsn) for ways you can do this.
Next, **you’ll need to configure your DSN** (client key) and optionally other values such as `environment` and `release`. [See the configuration page](configuration/options/#setting-the-dsn) for ways you can do this.

<!-- TODO-ADD-VERIFICATION-EXAMPLE -->

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/java/guides/spring/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public HandlerExceptionResolver sentryExceptionResolver() {
}
```

Next, **you’ll need to configure your DSN** (client key) and optionally other values such as `environment` and `release`. [See the configuration page](config/#setting-the-dsn) for ways you can do this.
Next, **you’ll need to configure your DSN** (client key) and optionally other values such as `environment` and `release`. [See the configuration page](configuration/options/#setting-the-dsn) for ways you can do this.

#### Spring Boot HTTP Data

Expand Down
70 changes: 48 additions & 22 deletions src/platforms/node/guides/aws-lambda/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ redirect_from:
- /platforms/node/aws_lambda/
---

*Verify Version*
_(New in version 5.22.4 - Lambda integration is in Beta)_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be 5.23.0


Create a deployment package on your local machine and install the required dependencies in the deployment package. For more information, see [Building an AWS Lambda deployment package for Node.js](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-deployment-package-nodejs/).

Add `@sentry/node` as a dependency:
Expand All @@ -16,37 +19,60 @@ $ npm install --save @sentry/node
$ yarn add @sentry/node
```

To set up Sentry error logging for a Lambda Function, build a wrapper:
You can use the AWS Lambda integration for the Node SDK like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove the SDK part from the Node SDK


```javascript
"use strict";
const Sentry = require("@sentry/serverless");

Sentry.init({
dsn:
"___PUBLIC_DSN___",
Comment on lines +28 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dsn:
"___PUBLIC_DSN___",
dsn: "___PUBLIC_DSN___"

});

const myAsyncHandler = async (event, context, callback) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const myAsyncHandler = async (event, context, callback) => {
const myAsyncHandler = async (event, context) => {

async functions are mutually exclusive with callback. It's either async or sync with callback.

//Your handler code
};

exports.handler = Sentry.AWSLambda.wrapHandler(myAsyncHandler);
```

<!-- TODO-ADD-VERIFICATION-EXAMPLE -->

const Sentry = require("@sentry/node");
## Timeout Warning

Sentry reports timeout warning when the function is within 500ms of it's execution time. You can turn off timeout warnings by setting `captureTimeoutWarning` to `false` during initiatlization. To change timeout warning limit, assign a numeric value (in ms) to `timeoutWarning`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now how options are set for handlers.

Sentry.AWSLambda.wrapHandler(yourHandler, {
  captureTimeoutWarning: false
});

So both, description and code examples are incorrect.


```javascript {tabTitle:captumeTimeoutWarning}
Sentry.init({
dsn: "___PUBLIC_DSN___",
dsn:
"___PUBLIC_DSN___",
captureTimeoutWarning: false
});
```

function sentryHandler(lambdaHandler) {
return async event => {
try {
return await lambdaHandler(event);
} catch (e) {
Sentry.captureException(e);
await Sentry.flush(2000);
return e;
}
};
}

module.exports.hello = sentryHandler(async event => {
notExistFunction();
return event;
```javascript {tabTitle:timeoutWarning}
Sentry.init({
dsn:
"___PUBLIC_DSN___",
timeoutWarning: 50
});
```

You can obtain the DSN using your Sentry account from your organization's _Settings > Projects > Client Keys (DSN)_ in the Sentry web UI.
The timeout warning is sent only if the "timeout" in the Lambda Function configuration is set to a value greater than one second.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing stopping you from setting timeout to 1s and still capture the warning if limit is small enough.



## Behavior

With the AWS Lambda integration enabled, the Node SDK will:

- Automatically report all exceptions from your lambda functions
- Issue reports automatically include:

Note: You need to call both `captureException` and `flush` for captured events to be successfully delivered to Sentry.
- A link to the cloudwatch logs
- Function details
- sys.argv for the function
- AWS Request ID
- Function execution time
- Function version

Create the deployment package in `.zip` format, then upload it to AWS Lambda as a Lambda Function. Checkout Sentry's [aws sample apps](https://github.com/getsentry/examples/tree/master/aws-lambda/node) for detailed examples. Refer to the [JavaScript docs](/platforms/javascript/) for more configuration options.
- Sentry holds the thread for upto 2 seconds to report errors. You can change flush time limit by defining a `flushTimeout` value during initiatlization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the handler options*

2 changes: 1 addition & 1 deletion src/platforms/python/guides/aws-lambda/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ If you are using another web framework inside of AWS Lambda, the framework might
With the AWS Lambda integration enabled, the Python SDK will:

- Automatically report all exceptions from your lambda functions
- Issues reports automatically include:
- Issue reports automatically include:

- A link to the cloudwatch logs
- Function details
Expand Down
3 changes: 2 additions & 1 deletion src/templates/developmentAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Prism from "prismjs";

import BasePage from "~src/components/basePage";
import SmartLink from "~src/components/smartLink";
import DevelopmentApiSidebar from "~src/components/developmentApiSidebar";

import "prismjs/components/prism-json";

Expand Down Expand Up @@ -71,7 +72,7 @@ export default props => {
}, []);

return (
<BasePage {...props}>
<BasePage sidebar={<DevelopmentApiSidebar />} {...props}>
<div className="row">
<div className="col-6">
{data.summary && <p>{data.summary}</p>}
Expand Down
3 changes: 2 additions & 1 deletion src/templates/developmentApiDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { graphql } from "gatsby";

import BasePage from "~src/components/basePage";
import SmartLink from "~src/components/smartLink";
import DevelopmentApiSidebar from "~src/components/developmentApiSidebar";

export default props => {
const {
data: { allOpenApi },
} = props;

return (
<BasePage {...props}>
<BasePage sidebar={<DevelopmentApiSidebar />} {...props}>
<ul>
{allOpenApi.edges.map(({ node: { path } }) => (
<li
Expand Down
3 changes: 2 additions & 1 deletion src/templates/developmentApiReference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { graphql } from "gatsby";

import BasePage from "~src/components/basePage";
import SmartLink from "~src/components/smartLink";
import DevelopmentApiSidebar from "~src/components/developmentApiSidebar";

export default props => {
const {
Expand All @@ -19,7 +20,7 @@ export default props => {
}, {});

return (
<BasePage {...props}>
<BasePage sidebar={<DevelopmentApiSidebar />} {...props}>
<h2>Endpoints</h2>
<p>A full list of the currently supported API endpoints:</p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion src/wizard/java/logback.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ Example configuration using the `logback.xml` format:
</configuration>
```

Next, **you’ll need to configure your DSN** (client key) and optionally other values such as `environment` and `release`. [See the configuration page](/platforms/java/guides/logback/config/#setting-the-dsn) for ways you can do this.
Next, **you’ll need to configure your DSN** (client key) and optionally other values such as `environment` and `release`. [See the configuration page](/platforms/java/guides/logback/configuration/options/#setting-the-dsn) for ways you can do this.

<!-- TODO-ADD-VERIFICATION-EXAMPLE -->
51 changes: 31 additions & 20 deletions src/wizard/node/awslambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ doc_link: https://docs.sentry.io/platforms/node/guides/aws-lambda/
support_level: production
type: framework
---

Create a deployment package on your local machine and install the required dependencies in the deployment package. For more information, see [Building an AWS Lambda deployment package for Node.js](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-deployment-package-nodejs/).

Add `@sentry/node` as a dependency:
Expand All @@ -16,33 +17,43 @@ $ npm install --save @sentry/node
$ yarn add @sentry/node
```

To set up Sentry error logging for a Lambda Function, build a wrapper:
You can use the AWS Lambda integration for the Node SDK like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the comments apply to this file as well, so I won't double-post them.


```javascript
"use strict";
const Sentry = require("@sentry/serverless");

Sentry.init({
dsn:
"___PUBLIC_DSN___",
});

const myAsyncHandler = async (event, context, callback) => {
//Your handler code
};

const Sentry = require("@sentry/node");
exports.handler = Sentry.AWSLambda.wrapHandler(myAsyncHandler);
```

<!-- TODO-ADD-VERIFICATION-EXAMPLE -->

## Timeout Warning

Sentry reports timeout warning when the function is within 500ms of it's execution time. You can turn off timeout warnings by setting `captureTimeoutWarning` to `false` during initiatlization. To change timeout warning limit, assign a numeric value (in ms) to `timeoutWarning`.

```javascript {tabTitle:captumeTimeoutWarning}
Sentry.init({
dsn: "___PUBLIC_DSN___",
dsn:
"___PUBLIC_DSN___",
captureTimeoutWarning: false
});
```

function sentryHandler(lambdaHandler) {
return async event => {
try {
return await lambdaHandler(event);
} catch (e) {
Sentry.captureException(e);
await Sentry.flush(2000);
return e;
}
};
}

module.exports.hello = sentryHandler(async event => {
notExistFunction();
return event;
```javascript {tabTitle:timeoutWarning}
Sentry.init({
dsn:
"___PUBLIC_DSN___",
timeoutWarning: 50
});
```

Note: You need to call both `captureException` and `flush` for captured events to be successfully delivered to Sentry.
The timeout warning is sent only if the "timeout" in the Lambda Function configuration is set to a value greater than one second.