-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feat/node lambda docs #2204
Changes from all commits
775c52d
0d9249a
ee8ac6c
818bd7e
ef4b5d4
7d74441
98f4c3e
0408325
63d3c10
221e49f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,9 @@ redirect_from: | |||||||
- /platforms/node/aws_lambda/ | ||||||||
--- | ||||||||
|
||||||||
*Verify Version* | ||||||||
_(New in version 5.22.4 - Lambda integration is in Beta)_ | ||||||||
|
||||||||
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: | ||||||||
|
@@ -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: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd remove the |
||||||||
|
||||||||
```javascript | ||||||||
"use strict"; | ||||||||
const Sentry = require("@sentry/serverless"); | ||||||||
|
||||||||
Sentry.init({ | ||||||||
dsn: | ||||||||
"___PUBLIC_DSN___", | ||||||||
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
}); | ||||||||
|
||||||||
const myAsyncHandler = async (event, context, callback) => { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
//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`. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's nothing stopping you from setting timeout to |
||||||||
|
||||||||
|
||||||||
## 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 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the handler options* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
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