Skip to content

Commit 39aaf7b

Browse files
committed
update Bun quick start guide
1 parent d1c5bd6 commit 39aaf7b

File tree

3 files changed

+103
-46
lines changed

3 files changed

+103
-46
lines changed
Lines changed: 83 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Bun
3+
description: Learn how to manually set up Sentry in your Bun app and capture your first errors.
34
sdk: sentry.javascript.bun
45
categories:
56
- javascript
@@ -10,29 +11,30 @@ categories:
1011

1112
<PlatformContent includePath="getting-started-prerequisites" />
1213

13-
## Install
14+
## Step 1: Install
1415

15-
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/).
16+
Choose the features you want to configure, and this guide will show you how:
1617

17-
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
18+
<OnboardingOptionButtons
19+
options={["error-monitoring", "performance", "logs"]}
20+
/>
1821

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

21-
Sentry captures data by using an SDK within your application's runtime.
24+
### Install the SDK
25+
26+
Use the Bun package manager to add the Sentry SDK to your application:
2227

2328
```bash {tabTitle:Bun}
2429
bun add @sentry/bun
2530
```
2631

27-
## Configure
28-
29-
Configuration should happen as early as possible in your application's lifecycle.
32+
## Step 2: Configure
3033

31-
Sentry should be initialized as early in your app as possible. It is essential that you call `Sentry.init` before you require any other modules in your application—otherwise, auto-instrumentation of these modules will _not_ work.
34+
### Initialize the Sentry SDK
3235

33-
Once this is done, Sentry's Bun SDK captures unhandled exceptions as well as tracing data for your application.
34-
35-
You need to create a file named `instrument.js` that imports and initializes Sentry:
36+
Sentry should be initialized as early in your app as possible.
37+
To import and initialize Sentry, create a file named `instrument.js` in the root directory of your project and add the following code:
3638

3739
```javascript {filename: instrument.js}
3840
import * as Sentry from "@sentry/bun";
@@ -53,22 +55,17 @@ Sentry.init({
5355
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
5456
tracesSampleRate: 1.0,
5557
// ___PRODUCT_OPTION_END___ performance
58+
// ___PRODUCT_OPTION_START___ logs
59+
60+
// Enable logs to be sent to Sentry
61+
enableLogs: true,
62+
// ___PRODUCT_OPTION_END___ logs
5663
});
5764
```
5865

59-
Once you set a `tracesSampleRate`, performance instrumentation is automatically enabled for you. See <PlatformLink to="/tracing/instrumentation/automatic-instrumentation">Automatic Instrumentation</PlatformLink> to learn about all the things that the SDK automatically instruments for you.
60-
61-
You can also manually capture performance data - see <PlatformLink to="/tracing/instrumentation/custom-instrumentation">Custom Instrumentation</PlatformLink> for details.
62-
63-
<PlatformContent includePath="getting-started-sourcemaps" />
64-
65-
## Use
66+
### Apply Instrumentation to Your App
6667

67-
<Alert level='warning'>
68-
69-
Import `instrument.js` before any other modules to ensure Sentry initializes early. If you initialize later, auto-instrumentation and modules like database monitoring, agent monitoring, tracing may not work.
70-
71-
</Alert>
68+
Import `instrument.js` before any other modules to make sure Sentry initializes early. If you initialize later, auto-instrumentation and modules like tracing may not work.
7269

7370
```javascript {filename: app.js}
7471
// Import this first!
@@ -80,33 +77,73 @@ import http from "http";
8077
// Your application code goes here
8178
```
8279

83-
## Verify
80+
## Step 3: Add Readable Stack Traces With Source Maps (Optional)
81+
82+
<PlatformContent includePath="getting-started-sourcemaps-short-version" />
83+
84+
## Step 4: Verify Your Setup
85+
86+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
87+
88+
### Issues
8489

85-
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
90+
First, let's verify that Sentry captures errors and creates issues in your Sentry project. Add the following code snippet to your main application file, which will call an undefined function, triggering an error that Sentry will capture:
8691

8792
```javascript
88-
// ___PRODUCT_OPTION_START___ performance
89-
Sentry.startSpan({
90-
op: "test",
91-
name: "My First Test Transaction",
92-
// ___PRODUCT_OPTION_END___ performance
93-
}, () => {
94-
setTimeout(() => {
95-
try {
96-
foo();
97-
} catch (e) {
98-
Sentry.captureException(e);
99-
}
100-
}, 99);
101-
// ___PRODUCT_OPTION_START___ performance
102-
});
103-
// ___PRODUCT_OPTION_END___ performance
93+
setTimeout(() => {
94+
try {
95+
foo();
96+
} catch (e) {
97+
Sentry.captureException(e);
98+
}
99+
}, 99);
100+
```
101+
102+
<OnboardingOption optionId="performance">
103+
### Tracing
104+
To test your tracing configuration, update the previous code snippet by starting a trace to measure the time it takes for the execution of your code:
105+
106+
```javascript
107+
Sentry.startSpan(
108+
{
109+
op: "test",
110+
name: "My First Test Transaction",
111+
},
112+
() => {
113+
setTimeout(() => {
114+
try {
115+
foo();
116+
} catch (e) {
117+
Sentry.captureException(e);
118+
}
119+
}, 99);
120+
}
121+
);
104122
```
105123

106-
<Alert>
124+
</OnboardingOption>
125+
126+
### View Captured Data in Sentry
127+
128+
Finally, 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).
129+
130+
<PlatformContent includePath="getting-started-verify-locate-data" />
131+
132+
## Next Steps
133+
134+
At this point, you should have integrated Sentry into your Bun application, which should already be sending data to your Sentry project.
135+
136+
Now's a good time to customize your setup and look into more advanced topics.
137+
Our next recommended steps for you are:
138+
139+
- Extend Sentry to your frontend using one of our [frontend SDKs](/)
140+
- Learn how to <PlatformLink to="/usage">manually capture errors</PlatformLink>
141+
- Continue to <PlatformLink to="/configuration">customize your configuration</PlatformLink>
142+
- Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts
107143

108-
Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
144+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
109145

110-
</Alert>
146+
- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
147+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
111148

112-
To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
149+
</Expandable>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
- [**Logs**](/product/explore/logs): Centralize and analyze your application logs to
10+
correlate them with errors and performance issues. Search, filter, and
11+
visualize log data to understand what's happening in your applications.
12+
13+
</Expandable>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Expandable title="Need help locating the captured errors in your Sentry project?">
2+
3+
1. Open the [**Issues**](https://sentry.io/issues) page and select an error from the issues list to view the full details and context of this error. For more details, see this [interactive walkthrough](/product/sentry-basics/integrate-frontend/generate-first-error/#ui-walkthrough).
4+
2. Open the [**Traces**](https://sentry.io/explore/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 [**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).
6+
7+
</Expandable>

0 commit comments

Comments
 (0)