Skip to content

Commit d11c384

Browse files
docs(js): Create Azure Functions quick start guide (#15831)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR This branch contains the updated quick start guide for Azure Functions. Closes: #15780 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 929c7f5 commit d11c384

File tree

3 files changed

+140
-21
lines changed

3 files changed

+140
-21
lines changed
Lines changed: 118 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Azure Functions
3-
description: Azure Functions is a serverless compute service offered as part of Microsoft Azure. Learn how to set it up with Sentry.
3+
description: Learn how to manually set up Sentry in your Azure Functions and capture your first errors.
44
sdk: sentry.javascript.astro
55
categories:
66
- javascript
@@ -9,23 +9,27 @@ categories:
99
- serverless
1010
---
1111

12-
## Features
12+
<PlatformContent includePath="getting-started-prerequisites" />
1313

14-
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also collect and analyze performance profiles from real users with [profiling](/product/explore/profiling/).
14+
## Step 1: Install
1515

16-
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
16+
Choose the features you want to configure, and this guide will show you how:
1717

18-
## Install
18+
<OnboardingOptionButtons
19+
options={["error-monitoring", "performance", "profiling", "logs"]}
20+
/>
1921

20-
<OnboardingOptionButtons options={["error-monitoring", "performance", "profiling", "logs"]} />
22+
<PlatformContent includePath="getting-started-features-expandable" />
2123

22-
Sentry captures data by using an SDK within your application's runtime. This means that you have to add `@sentry/node` as a runtime dependency to your application:
24+
### Install the Sentry SDK
25+
26+
Run the command for your preferred package manager to add `@sentry/node` as a runtime dependency to your application:
2327

2428
<PlatformContent includePath="getting-started-install" />
2529

26-
## Configure
30+
## Step 2: Configure
2731

28-
To set up Sentry error logging for an Azure Function:
32+
Make sure to initialize Sentry at the top of your function file before importing any other modules:
2933

3034
```javascript {tabTitle:async}
3135
const Sentry = require("@sentry/node");
@@ -35,53 +39,146 @@ const { nodeProfilingIntegration } = require("@sentry/profiling-node");
3539
// ___PRODUCT_OPTION_END___ profiling
3640
Sentry.init({
3741
dsn: "___PUBLIC_DSN___",
38-
42+
3943
// Adds request headers and IP for users, for more info visit:
4044
// https://docs.sentry.io/platforms/javascript/guides/azure-functions/configuration/options/#sendDefaultPii
4145
sendDefaultPii: true,
4246
// ___PRODUCT_OPTION_START___ profiling
43-
44-
integrations: [
45-
nodeProfilingIntegration(),
46-
],
47-
// ___PRODUCT_OPTION_END___ profiling
4847

48+
integrations: [nodeProfilingIntegration()],
49+
// ___PRODUCT_OPTION_END___ profiling
4950
// ___PRODUCT_OPTION_START___ performance
51+
5052
// Add Performance Monitoring by setting tracesSampleRate
5153
// Set tracesSampleRate to 1.0 to capture 100% of transactions
5254
// We recommend adjusting this value in production
5355
// Learn more at
5456
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
5557
tracesSampleRate: 1.0,
5658
// ___PRODUCT_OPTION_END___ performance
57-
5859
// ___PRODUCT_OPTION_START___ profiling
60+
5961
// Set sampling rate for profiling - this is relative to tracesSampleRate
6062
profilesSampleRate: 1.0,
6163
// ___PRODUCT_OPTION_END___ profiling
64+
// ___PRODUCT_OPTION_START___ logs
65+
66+
// Enable logs to be sent to Sentry
67+
enableLogs: true,
68+
// ___PRODUCT_OPTION_END___ logs
6269
});
6370

71+
// your function code
72+
```
73+
74+
### Capture Errors
75+
76+
Because Azure Functions are short-lived, you have to explicitly `flush` Sentry events after calling `captureException`, or they may be lost before being sent to Sentry.
77+
78+
```javascript {tabTitle:async}
79+
const Sentry = require("@sentry/node");
80+
81+
// your Sentry init code
82+
6483
module.exports = async function (context, req) {
6584
try {
66-
await notExistFunction();
85+
// Your function code
6786
} catch (e) {
87+
// use Sentry.withScope to enrich the event with request data
6888
Sentry.withScope((scope) => {
89+
// Attach request context (requires sendDefaultPii: true)
6990
scope.setSDKProcessingMetadata({ request: req });
7091
Sentry.captureException(e);
7192
});
7293
await Sentry.flush(2000);
7394
}
95+
// ...
96+
};
97+
```
98+
99+
## Step 3: Add Readable Stack Traces With Source Maps (Optional)
100+
101+
<PlatformContent includePath="getting-started-sourcemaps-short-version" />
102+
103+
## Step 4: Verify Your Setup
104+
105+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
106+
107+
### Issues
108+
109+
First, let's verify that Sentry captures errors and creates issues in your Sentry project. Add an intentional error in your function:
110+
111+
```javascript {tabTitle:async}
112+
const Sentry = require("@sentry/node");
113+
114+
module.exports = async function (context, req) {
115+
try {
116+
// This function does not exist, triggering an error
117+
await notExistFunction();
118+
} catch (e) {
119+
Sentry.withScope((scope) => {
120+
scope.setSDKProcessingMetadata({ request: req });
121+
Sentry.captureException(e);
122+
});
123+
}
124+
125+
// Wait for the event to be sent before the function execution ends
126+
await Sentry.flush(2000);
127+
128+
context.res = {
129+
status: 500,
130+
body: "Test error sent to Sentry.",
131+
};
132+
};
133+
```
134+
135+
Deploy and trigger your function to throw an error.
136+
137+
<OnboardingOption optionId="performance">
138+
### Tracing
139+
To test tracing, update your function to include a custom span:
140+
141+
```javascript {tabTitle:async}
142+
const Sentry = require("@sentry/node");
143+
144+
module.exports = async function (context, req) {
145+
await Sentry.startSpan({ name: "My Custom Span", op: "task" }, async () => {
146+
// Simulate some work
147+
await new Promise((resolve) => setTimeout(resolve, 100));
148+
});
149+
150+
// Wait for the event to be sent before the function execution ends
151+
await Sentry.flush(2000);
74152

75153
context.res = {
76154
status: 200,
77-
body: "Hello from Azure Cloud Function!",
155+
body: "Hello world!",
78156
};
79157
};
80158
```
81159

160+
Deploy and trigger your function to start a child span.
161+
162+
</OnboardingOption>
163+
164+
### View Captured Data in Sentry
165+
166+
Now, head over to your project on [Sentry.io](https://sentry.io/) to view the collected data (it takes a couple of moments for the data to appear).
167+
168+
<PlatformContent includePath="getting-started-verify-locate-data" />
169+
170+
## Next Steps
171+
172+
At this point, you should have integrated Sentry into your Azure Function and should already be sending data to your Sentry project.
173+
174+
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
82175

83-
You can obtain the DSN using your Sentry account from your organization's _Settings > Projects > Client Keys (DSN)_ in the Sentry web UI.
176+
- Continue to <PlatformLink to="/configuration">customize your configuration</PlatformLink>
177+
- Learn how to <PlatformLink to="/usage">manually capture errors</PlatformLink>
178+
- Get familiar with [Sentry's product features](/) like tracing, insights, and alerts
84179

85-
Note: You need to call both `captureException` and `flush` for captured events to be successfully delivered to Sentry.
180+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
181+
- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
182+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
86183

87-
Check out Sentry's [Azure sample apps](https://github.com/getsentry/examples/tree/master/azure-functions/node) for detailed examples. Refer to the [JavaScript docs](/platforms/javascript/) for more configuration options.
184+
</Expandable>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Expandable title="Want to learn more about these features?">
2+
3+
- [**Issues**](/product/issues) (always enabled): Sentry's core error monitoring product that automatically reports errors,
4+
uncaught exceptions, and unhandled rejections. If you have something that
5+
looks like an exception, Sentry can capture it.
6+
- [**Tracing**](/product/tracing): Track software performance while seeing the
7+
impact of errors across multiple systems. For example, distributed tracing
8+
allows you to follow a request from the frontend to the backend and back.
9+
- [**Profiling**](/product/explore/profiling/): Gain deeper insight than traditional tracing without custom instrumentation, letting you discover slow-to-execute or resource-intensive functions in your app.
10+
- [**Logs**](/product/explore/logs): Centralize and analyze your application logs to
11+
correlate them with errors and performance issues. Search, filter, and
12+
visualize log data to understand what's happening in your applications.
13+
14+
</Expandable>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Expandable title="Need help locating the captured errors in your Sentry project?">
2+
3+
1. Open the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues) page and select an error from the issues list to view the full details and context of this error. For an interactive UI walkthrough, click [here](/product/sentry-basics/integrate-frontend/generate-first-error/#ui-walkthrough).
4+
2. Open the [**Traces**](https://sentry.io/orgredirect/organizations/:orgslug/traces) page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click [here](/product/sentry-basics/distributed-tracing/generate-first-error/#ui-walkthrough).
5+
3. Open the [**Profiles**](https://sentry.io/orgredirect/organizations/:orgslug/profiling) page, select a transaction, and then a profile ID to view its flame graph. For more information, click [here](/product/explore/profiling/profile-details/).
6+
4. Open the [**Logs**](https://sentry.io/explore/logs) page and filter by service, environment, or search keywords to view log entries from your application. For an interactive UI walkthrough, click [here](/product/explore/logs/#overview).
7+
8+
</Expandable>

0 commit comments

Comments
 (0)