Skip to content

Commit c8d9aa1

Browse files
committed
update Browser JS quick start guide
1 parent 969f7b9 commit c8d9aa1

File tree

6 files changed

+150
-64
lines changed

6 files changed

+150
-64
lines changed

docs/platforms/javascript/common/index.mdx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
<PlatformContent includePath="getting-started-primer" />
2-
31
<PlatformSection noGuides>
42

53
<PlatformContent includePath="llm-rules-platform" />
64

7-
<Alert title="Using a framework?">
5+
<Alert title="Using a framework?" level="warning">
86

9-
Check out the other SDKs we support in the left-hand dropdown.
7+
This guide focuses on plain JavaScript. If you're working with React, Next.js, or any other framework, choose the fitting SDK from the left-hand dropdown.
108

119
</Alert>
1210

1311
<PlatformContent includePath="getting-started-primer" />
1412

1513
</PlatformSection>
1614

17-
<PlatformSection supported={["javascript", "javascript.angular", "javascript.nextjs", "javascript.remix", "javascript.sveltekit", "javascript.bun", "javascript.ember", "javascript.angular", "javascript.deno","javascript.nuxt", "javascript.react", "javascript.solid", "javascript.svelte", "javascript.vue"]}>
15+
<PlatformSection supported={["javascript"]}>
16+
<PlatformContent includePath="getting-started-complete" />
17+
</PlatformSection>
18+
19+
<PlatformSection notSupported={["javascript"]}>
20+
21+
<PlatformSection supported={["javascript.angular", "javascript.nextjs", "javascript.remix", "javascript.sveltekit", "javascript.bun", "javascript.ember", "javascript.angular", "javascript.deno","javascript.nuxt", "javascript.react", "javascript.solid", "javascript.svelte", "javascript.vue"]}>
1822

1923
<PlatformContent includePath="getting-started-prerequisites" />
2024

2125
</PlatformSection>
2226

2327
<PlatformSection notSupported={["javascript.deno"]}>
2428

25-
<PlatformSection notSupported={["javascript", "javascript.astro", "javascript.cordova", "javascript.nextjs", "javascript.nuxt", "javascript.remix", "javascript.solidstart", "javascript.sveltekit", "javascript.bun", "javascript.cloudflare", "javascript.react-router"]}>
29+
<PlatformSection notSupported={["javascript.astro", "javascript.cordova", "javascript.nextjs", "javascript.nuxt", "javascript.remix", "javascript.solidstart", "javascript.sveltekit", "javascript.bun", "javascript.cloudflare", "javascript.react-router"]}>
2630

2731
## Features
2832

@@ -32,27 +36,23 @@ Select which Sentry features you'd like to install in addition to Error Monitori
3236

3337
</PlatformSection>
3438

35-
<PlatformSection supported={["javascript.nextjs"]}>
36-
3739
## Step 1: Install
3840

39-
</PlatformSection>
40-
41-
<PlatformSection notSupported={["javascript.nextjs"]}>
42-
43-
## Install
44-
45-
</PlatformSection>
46-
4741
<PlatformCategorySection notSupported={["server"]}>
48-
<PlatformSection notSupported={["javascript", "javascript.cordova"]}>
42+
<PlatformSection notSupported={["javascript"]}>
4943
<OnboardingOptionButtons
50-
options={["error-monitoring", "performance", "session-replay", "user-feedback", "logs"]}
44+
options={[
45+
"error-monitoring",
46+
"performance",
47+
"session-replay",
48+
"user-feedback",
49+
"logs",
50+
]}
5151
/>
5252
</PlatformSection>
5353
</PlatformCategorySection>
5454

55-
<PlatformSection notSupported={["javascript", "javascript.astro", "javascript.cordova", "javascript.nextjs", "javascript.nuxt", "javascript.remix", "javascript.sveltekit", "javascript.bun", "javascript.capacitor", "javascript.ember", "javascript.angular", "javascript.react", "javascript.solid", "javascript.solidstart", "javascript.svelte", "javascript.vue", "javascript.cloudflare", "javascript.react-router"]}>
55+
<PlatformSection notSupported={["javascript.astro", "javascript.cordova", "javascript.nextjs", "javascript.nuxt", "javascript.remix", "javascript.sveltekit", "javascript.bun", "javascript.capacitor", "javascript.ember", "javascript.angular", "javascript.react", "javascript.solid", "javascript.solidstart", "javascript.svelte", "javascript.vue", "javascript.cloudflare", "javascript.react-router"]}>
5656

5757
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/).
5858

@@ -140,3 +140,4 @@ To view and resolve the recorded error, log into [sentry.io](https://sentry.io)
140140
</PlatformSection>
141141

142142
<PlatformContent includePath="getting-started-next-steps" />
143+
</PlatformSection>

docs/platforms/javascript/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
title: Browser JavaScript
2+
description: Learn how to manually set up Sentry in your JavaScript app and capture your first errors.
23
platformTitle: JavaScript
34
sidebar_title: JavaScript
45
caseStyle: camelCase
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<PlatformContent includePath="getting-started-prerequisites" />
2+
3+
## Step 1: Install
4+
5+
Choose the features you want to configure, and this guide will show you how:
6+
7+
<OnboardingOptionButtons
8+
options={[
9+
"error-monitoring",
10+
"performance",
11+
"session-replay",
12+
"user-feedback",
13+
"logs",
14+
]}
15+
/>
16+
17+
<PlatformContent includePath="getting-started-features-expandable" />
18+
19+
### Install the Sentry SDK
20+
21+
<PlatformContent includePath="getting-started-install" />
22+
23+
## Step 2: Configure
24+
25+
### Initialize the Sentry SDK
26+
27+
<PlatformContent includePath="getting-started-config" />
28+
29+
## Step 3: Add Readable Stack Traces With Source Maps (Optional)
30+
31+
<PlatformContent includePath="getting-started-sourcemaps-short-version" />
32+
33+
## Step 4: Avoid Ad Blockers With Tunneling (Optional)
34+
35+
<PlatformContent includePath="getting-started-tunneling" />
36+
37+
## Step 5: Verify Your Setup
38+
39+
<PlatformContent includePath="getting-started-verify" />
40+
41+
### View Captured Data in Sentry
42+
43+
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).
44+
45+
<PlatformContent includePath="getting-started-verify-locate-data" />
46+
47+
At this point, you should have integrated Sentry into your JavaScript application and should already be sending data to your Sentry project.
48+
49+
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
50+
51+
- Extend Sentry to your backend using one of our [SDKs](/)
52+
- Learn how to [manually capture errors](/platforms/javascript/usage/)
53+
- Continue to [customize your configuration](/platforms/javascript/configuration/)
54+
- Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts
55+
56+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
57+
58+
- Find various support topics in <PlatformLink to="/troubleshooting">troubleshooting</PlatformLink>
59+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
60+
61+
</Expandable>

platform-includes/getting-started-config/javascript.mdx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
<OnboardingOptionButtons
2-
options={[
3-
"error-monitoring",
4-
"performance",
5-
"session-replay",
6-
"user-feedback",
7-
"logs",
8-
]}
9-
/>
10-
11-
Once this is done, Sentry's JavaScript SDK will capture all unhandled exceptions, transactions, and Session Replays, based on the sample rates set.
12-
13-
Note, that configuration differs slightly depending on how you installed the Sentry SDK. Make sure to follow the instructions in the correct tab, depending on if you installed the Sentry SDK via NPM, using the Loader Script, or via CDN.
1+
Initialize Sentry as early as possible in your application's lifecycle. The setup differs slightly depending on how you installed the Sentry SDK. Be sure to follow the instructions in the right tab:
142

153
```javascript {tabTitle:npm}
164
import * as Sentry from "@sentry/browser";
@@ -39,13 +27,13 @@ Sentry.init({
3927
}),
4028
// ___PRODUCT_OPTION_END___ user-feedback
4129
],
42-
4330
// ___PRODUCT_OPTION_START___ logs
31+
4432
// Enable logs to be sent to Sentry
4533
enableLogs: true,
4634
// ___PRODUCT_OPTION_END___ logs
47-
4835
// ___PRODUCT_OPTION_START___ performance
36+
4937
// Set tracesSampleRate to 1.0 to capture 100%
5038
// of transactions for tracing.
5139
// We recommend adjusting this value in production
@@ -56,8 +44,8 @@ Sentry.init({
5644
// Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
5745
tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
5846
// ___PRODUCT_OPTION_END___ performance
59-
6047
// ___PRODUCT_OPTION_START___ session-replay
48+
6149
// Capture Replay for 10% of all sessions,
6250
// plus for 100% of sessions with an error
6351
// Learn more at
@@ -100,13 +88,13 @@ Sentry.init({
10088
}),
10189
// ___PRODUCT_OPTION_END___ user-feedback
10290
],
103-
10491
// ___PRODUCT_OPTION_START___ logs
92+
10593
// Enable logs to be sent to Sentry
10694
enableLogs: true,
10795
// ___PRODUCT_OPTION_END___ logs
108-
10996
// ___PRODUCT_OPTION_START___ performance
97+
11098
// Set tracesSampleRate to 1.0 to capture 100%
11199
// of transactions for tracing.
112100
// We recommend adjusting this value in production
@@ -117,8 +105,8 @@ Sentry.init({
117105
// Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
118106
tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
119107
// ___PRODUCT_OPTION_END___ performance
120-
121108
// ___PRODUCT_OPTION_START___ session-replay
109+
122110
// Capture Replay for 10% of all sessions,
123111
// plus for 100% of sessions with an error
124112
// Learn more at
@@ -163,13 +151,13 @@ Sentry.init({
163151
}),
164152
// ___PRODUCT_OPTION_END___ user-feedback
165153
],
166-
167154
// ___PRODUCT_OPTION_START___ logs
155+
168156
// Enable logs to be sent to Sentry
169157
enableLogs: true,
170158
// ___PRODUCT_OPTION_END___ logs
171-
172159
// ___PRODUCT_OPTION_START___ performance
160+
173161
// Set tracesSampleRate to 1.0 to capture 100%
174162
// of transactions for tracing.
175163
// We recommend adjusting this value in production
@@ -180,8 +168,8 @@ Sentry.init({
180168
// Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
181169
tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
182170
// ___PRODUCT_OPTION_END___ performance
183-
184171
// ___PRODUCT_OPTION_START___ session-replay
172+
185173
// Capture Replay for 10% of all sessions,
186174
// plus for 100% of sessions with an error
187175
// Learn more at
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
In order to get started using the Sentry JavaScript SDK, add the following code to the top of your application, before all other scripts:
1+
We recommend installing Sentry via a package manager. If that isn't an option for you, you can use the [Loader Script](/platforms/javascript/install/loader/) or a CDN bundle.
22

3+
#### Option 1: Packet Manager (Recommended)
34

4-
```html
5-
<script
6-
src="https://js.sentry-cdn.com/___PUBLIC_KEY___.min.js"
7-
crossorigin="anonymous"
8-
></script>
9-
```
10-
11-
The Loader Script allows you to configure some SDK features from the Sentry UI, without having to redeploy your application. The [Loader Script documentation](/platforms/javascript/install/loader/) shows more information about how to use it.
12-
13-
Alternatively, you can also install the SDK via a package manager:
5+
Run the command for your preferred package manager to add the Sentry SDK to your application:
146

157
```bash {tabTitle:npm}
168
npm install @sentry/browser --save
@@ -24,12 +16,20 @@ yarn add @sentry/browser
2416
pnpm add @sentry/browser
2517
```
2618

27-
<Alert>
19+
#### Option 2: Loader Script
2820

29-
We also support installation via [CDN bundles](/platforms/javascript/install/loader/#cdn).
21+
In Sentry, go to
22+
**Settings > Projects > (select project) > SDK Setup > Loader Script**.
23+
Enable the features you want (for example, Tracing or Session Replay), copy the script tag, and place it before all other scripts in your app.
3024

31-
</Alert>
25+
#### Option 3: CDN Bundle
3226

33-
If you're updating your Sentry SDK to the latest version, check out our [migration guide](https://github.com/getsentry/sentry-javascript/blob/master/MIGRATION.md) to learn more about breaking changes.
27+
Sentry provides different bundles that include specific feature combinations. Go to our list of [available bundles](/platforms/javascript/install/loader/#cdn) and copy the one that fits your needs.
28+
Next, place the script tag before all other scripts in your app.
3429

35-
If you are using our previous Browser JavaScript SDK, you can access the <Link rel={`nofollow`} to={`/platforms/javascript/legacy-sdk/`}>legacy SDK documentation</Link>, until further notice.
30+
<Alert>
31+
If you're updating your Sentry SDK to the latest version, check out our
32+
[migration
33+
guide](https://github.com/getsentry/sentry-javascript/blob/master/MIGRATION.md)
34+
to learn more about breaking changes.
35+
</Alert>
Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1-
```javascript
2-
setTimeout(() => {
3-
throw new Error("Sentry Test Error");
4-
});
1+
Let's test your setup and confirm that data reaches your Sentry project.
2+
3+
### Issues
4+
5+
To verify that Sentry captures errors and creates issues in your Sentry project, add a button that throws an error when clicked:
6+
7+
```html
8+
<script>
9+
function triggerError() {
10+
throw new Error("Sentry Test Error");
11+
}
12+
</script>
13+
14+
<button onclick="triggerError()">Break the World</button>
515
```
616

7-
<Alert>
17+
<OnboardingOption optionId="performance" hideForThisOption>
18+
Open the page in a browser and click the button to throw an error.
19+
</OnboardingOption>
20+
21+
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
22+
23+
<OnboardingOption optionId="performance">
24+
### Tracing
25+
To test your tracing configuration, update the previous code to simulate a longer operation and start a trace:
26+
27+
```html
28+
<script>
29+
function triggerError() {
30+
await Sentry.startSpan(
31+
{ name: "Example Frontend Span", op: "test" },
32+
async () => {
33+
await new Promise(resolve => setTimeout(resolve, 200));
34+
35+
throw new Error("Sentry Test Error");
36+
},
37+
);
38+
}
39+
</script>
40+
41+
<button onclick="triggerError()">Break the World</button>
42+
```
843

9-
Errors triggered from within Browser DevTools are sandboxed and won't trigger an error handler. Place the snippet directly in your code instead.
44+
Open the page in a browser and click the button to throw an error and create a trace.
1045

11-
</Alert>
46+
</OnboardingOption>

0 commit comments

Comments
 (0)