Skip to content

Commit 556a008

Browse files
committed
docs: Add docs for node setup in v8
1 parent 963c3de commit 556a008

File tree

43 files changed

+685
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+685
-494
lines changed

.github/CANARY_FAILURE_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
title: '{{ env.TITLE }}'
33
labels: 'Type: Tests, Waiting for: Product Owner'
44
---
5+
56
Canary tests failed: {{ env.RUN_LINK }}

dev-packages/browser-integration-tests/README.md

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
# Integration Tests for Sentry Browser SDK
22

3-
Integration tests for Sentry's Browser SDK use [Playwright](https://playwright.dev/) internally. These tests are run on latest stable versions of Chromium, Firefox and Webkit.
3+
Integration tests for Sentry's Browser SDK use [Playwright](https://playwright.dev/) internally. These tests are run on
4+
latest stable versions of Chromium, Firefox and Webkit.
45

56
## Structure
67

7-
The tests are grouped by their scope such as `breadcrumbs` or `onunhandledrejection`. In every group of tests, there are multiple folders containing test cases with their optional supporting assets.
8+
The tests are grouped by their scope such as `breadcrumbs` or `onunhandledrejection`. In every group of tests, there are
9+
multiple folders containing test cases with their optional supporting assets.
810

9-
Each case group has a default HTML skeleton named `template.hbs`, and also a default initialization script named `init.js `, which contains the `Sentry.init()` call. These defaults are used as fallbacks when a specific `template.hbs` or `init.js` is not defined in a case folder.
11+
Each case group has a default HTML skeleton named `template.hbs`, and also a default initialization script named
12+
`init.js `, which contains the `Sentry.init()` call. These defaults are used as fallbacks when a specific `template.hbs`
13+
or `init.js` is not defined in a case folder.
1014

11-
`subject.js` contains the logic that sets up the environment to be tested. It also can be defined locally and as a group fallback. Unlike `template.hbs` and `init.js`, it's not required to be defined for a group, as there may be cases that does not require a subject, instead the logic is injected using `injectScriptAndGetEvents` from `utils/helpers.ts`.
15+
`subject.js` contains the logic that sets up the environment to be tested. It also can be defined locally and as a group
16+
fallback. Unlike `template.hbs` and `init.js`, it's not required to be defined for a group, as there may be cases that
17+
does not require a subject, instead the logic is injected using `injectScriptAndGetEvents` from `utils/helpers.ts`.
1218

13-
`test.ts` is required for each test case, which contains the assertions (and if required the script injection logic). For every case, any set of `init.js`, `template.hbs` and `subject.js` can be defined locally, and each one of them will have precedence over the default definitions of the test group.
19+
`test.ts` is required for each test case, which contains the assertions (and if required the script injection logic).
20+
For every case, any set of `init.js`, `template.hbs` and `subject.js` can be defined locally, and each one of them will
21+
have precedence over the default definitions of the test group.
1422

15-
To test page multi-page navigations, you can specify additional `page-*.html` (e.g. `page-0.html`, `page-1.html`) files. These will also be compiled and initialized with the same `init.js` and `subject.js` files that are applied to `template.hbs/html`. Note: `page-*.html` file lookup **doesn not** fall back to the
16-
parent directories, meaning that page files have to be directly in the `test.ts` directory.
23+
To test page multi-page navigations, you can specify additional `page-*.html` (e.g. `page-0.html`, `page-1.html`) files.
24+
These will also be compiled and initialized with the same `init.js` and `subject.js` files that are applied to
25+
`template.hbs/html`. Note: `page-*.html` file lookup **doesn not** fall back to the parent directories, meaning that
26+
page files have to be directly in the `test.ts` directory.
1727

1828
```
1929
suites/
@@ -33,11 +43,16 @@ suites/
3343

3444
### Helpers
3545

36-
`utils/helpers.ts` contains helpers that could be used in assertions (`test.ts`). These helpers define a convenient and reliable API to interact with Playwright's native API. It's highly recommended to define all common patterns of Playwright usage in helpers.
46+
`utils/helpers.ts` contains helpers that could be used in assertions (`test.ts`). These helpers define a convenient and
47+
reliable API to interact with Playwright's native API. It's highly recommended to define all common patterns of
48+
Playwright usage in helpers.
3749

3850
### Fixtures
3951

40-
[Fixtures](https://playwright.dev/docs/api/class-fixtures) allows us to define the globals and test-specific information in assertion groups (`test.ts` files). In it's current state, `fixtures.ts` contains an extension over the pure version of `test()` function of Playwright. All the tests should import `sentryTest` function from `utils/fixtures.ts` instead of `@playwright/test` to be able to access the extra fixtures.
52+
[Fixtures](https://playwright.dev/docs/api/class-fixtures) allows us to define the globals and test-specific information
53+
in assertion groups (`test.ts` files). In it's current state, `fixtures.ts` contains an extension over the pure version
54+
of `test()` function of Playwright. All the tests should import `sentryTest` function from `utils/fixtures.ts` instead
55+
of `@playwright/test` to be able to access the extra fixtures.
4156

4257
## Running Tests Locally
4358

@@ -47,8 +62,7 @@ Tests can be run locally using the latest version of Chromium with:
4762

4863
To run tests with a different browser such as `firefox` or `webkit`:
4964

50-
`yarn test --project='firefox'`
51-
`yarn test --project='webkit'`
65+
`yarn test --project='firefox'` `yarn test --project='webkit'`
5266

5367
Or to run on all three browsers:
5468

@@ -60,18 +74,27 @@ To filter tests by their title:
6074

6175
You can refer to [Playwright documentation](https://playwright.dev/docs/test-cli) for other CLI options.
6276

63-
You can set env variable `PW_BUNDLE` to set specific build or bundle to test against.
64-
Available options: `esm`, `cjs`, `bundle`, `bundle_min`
77+
You can set env variable `PW_BUNDLE` to set specific build or bundle to test against. Available options: `esm`, `cjs`,
78+
`bundle`, `bundle_min`
6579

6680
### Troubleshooting
6781

68-
Apart from [Playwright-specific issues](https://playwright.dev/docs/troubleshooting), below are common issues that might occur while writing tests for Sentry Browser SDK.
82+
Apart from [Playwright-specific issues](https://playwright.dev/docs/troubleshooting), below are common issues that might
83+
occur while writing tests for Sentry Browser SDK.
6984

7085
- #### Flaky Tests
71-
If a test fails randomly, giving a `Page Closed`, `Target Closed` or a similar error, most of the times, the reason is a race condition between the page action defined in the `subject` and the listeners of the Sentry event / request. It's recommended to firstly check `utils/helpers.ts` whether if that async logic can be replaced by one of the helpers. If not, whether the awaited (or non-awaited on purpose in some cases) Playwright methods can be orchestrated by [`Promise.all`](http://mdn.io/promise.all). Manually-defined waiting logic such as timeouts are not recommended, and should not be required in most of the cases.
86+
87+
If a test fails randomly, giving a `Page Closed`, `Target Closed` or a similar error, most of the times, the reason is
88+
a race condition between the page action defined in the `subject` and the listeners of the Sentry event / request.
89+
It's recommended to firstly check `utils/helpers.ts` whether if that async logic can be replaced by one of the
90+
helpers. If not, whether the awaited (or non-awaited on purpose in some cases) Playwright methods can be orchestrated
91+
by [`Promise.all`](http://mdn.io/promise.all). Manually-defined waiting logic such as timeouts are not recommended,
92+
and should not be required in most of the cases.
7293

7394
- #### Build Errors
74-
Before running, a page for each test case is built under the case folder inside `dist`. If a page build is failed, it's recommended to check:
95+
96+
Before running, a page for each test case is built under the case folder inside `dist`. If a page build is failed,
97+
it's recommended to check:
7598

7699
- If both default `template.hbs` and `init.js` are defined for the test group.
77100
- If a `subject.js` is defined for the test case.

dev-packages/e2e-tests/test-applications/create-remix-app-express-vite-dev/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Welcome to Remix + Vite!
22

3-
📖 See the [Remix docs](https://remix.run/docs) and the [Remix Vite docs](https://remix.run/docs/en/main/future/vite) for details on supported features.
3+
📖 See the [Remix docs](https://remix.run/docs) and the [Remix Vite docs](https://remix.run/docs/en/main/future/vite)
4+
for details on supported features.
45

56
## Development
67

@@ -28,7 +29,8 @@ Now you'll need to pick a host to deploy it to.
2829

2930
### DIY
3031

31-
If you're familiar with deploying Express applications you should be right at home. Just make sure to deploy the output of `npm run build`
32+
If you're familiar with deploying Express applications you should be right at home. Just make sure to deploy the output
33+
of `npm run build`
3234

3335
- `build/server`
3436
- `build/client`

dev-packages/node-integration-tests/README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,37 @@ utils/
1919
|---- server.ts [default Express server configuration]
2020
```
2121

22-
The tests are grouped by their scopes, such as `public-api` or `tracing`. In every group of tests, there are multiple folders containing test scenarios and assertions.
22+
The tests are grouped by their scopes, such as `public-api` or `tracing`. In every group of tests, there are multiple
23+
folders containing test scenarios and assertions.
2324

24-
Tests run on Express servers (a server instance per test). By default, a simple server template inside `utils/defaults/server.ts` is used. Every server instance runs on a different port.
25+
Tests run on Express servers (a server instance per test). By default, a simple server template inside
26+
`utils/defaults/server.ts` is used. Every server instance runs on a different port.
2527

26-
A custom server configuration can be used, supplying a script that exports a valid express server instance as default. `runServer` utility function accepts an optional `serverPath` argument for this purpose.
28+
A custom server configuration can be used, supplying a script that exports a valid express server instance as default.
29+
`runServer` utility function accepts an optional `serverPath` argument for this purpose.
2730

28-
`scenario.ts` contains the initialization logic and the test subject. By default, `{TEST_DIR}/scenario.ts` is used, but `runServer` also accepts an optional `scenarioPath` argument for non-standard usage.
31+
`scenario.ts` contains the initialization logic and the test subject. By default, `{TEST_DIR}/scenario.ts` is used, but
32+
`runServer` also accepts an optional `scenarioPath` argument for non-standard usage.
2933

30-
`test.ts` is required for each test case, and contains the server runner logic, request interceptors for Sentry requests, and assertions. Test server, interceptors and assertions are all run on the same Jest thread.
34+
`test.ts` is required for each test case, and contains the server runner logic, request interceptors for Sentry
35+
requests, and assertions. Test server, interceptors and assertions are all run on the same Jest thread.
3136

3237
### Utilities
3338

3439
`utils/` contains helpers and Sentry-specific assertions that can be used in (`test.ts`).
3540

36-
`TestEnv` class contains methods to create and execute requests on a test server instance. `TestEnv.init()` which starts a test server and returns a `TestEnv` instance must be called by each test. The test server is automatically shut down after each test, if a data collection helper method such as `getEnvelopeRequest` and `getAPIResponse` is used. Tests that do not use those helper methods will need to end the server manually.
41+
`TestEnv` class contains methods to create and execute requests on a test server instance. `TestEnv.init()` which starts
42+
a test server and returns a `TestEnv` instance must be called by each test. The test server is automatically shut down
43+
after each test, if a data collection helper method such as `getEnvelopeRequest` and `getAPIResponse` is used. Tests
44+
that do not use those helper methods will need to end the server manually.
3745

38-
`TestEnv` instance has two public properties: `url` and `server`. The `url` property is the base URL for the server. The `http.Server` instance is used to finish the server eventually.
46+
`TestEnv` instance has two public properties: `url` and `server`. The `url` property is the base URL for the server. The
47+
`http.Server` instance is used to finish the server eventually.
3948

40-
Nock interceptors are internally used to capture envelope requests by `getEnvelopeRequest` and `getMultipleEnvelopeRequest` helpers. After capturing required requests, the interceptors are removed. Nock can manually be used inside the test cases to intercept requests but should be removed before the test ends, as not to cause flakiness.
49+
Nock interceptors are internally used to capture envelope requests by `getEnvelopeRequest` and
50+
`getMultipleEnvelopeRequest` helpers. After capturing required requests, the interceptors are removed. Nock can manually
51+
be used inside the test cases to intercept requests but should be removed before the test ends, as not to cause
52+
flakiness.
4153

4254
## Running Tests Locally
4355

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Overhead performance metrics
22

3-
Evaluates Sentry & Replay impact on website performance by running a web app in Chromium via Playwright and collecting various metrics.
3+
Evaluates Sentry & Replay impact on website performance by running a web app in Chromium via Playwright and collecting
4+
various metrics.
45

5-
The general idea is to run a web app without Sentry, and then run the same app again with Sentry and another one with Sentry+Replay included.
6-
For the three scenarios, we collect some metrics (CPU, memory, vitals) and later compare them and post as a comment in a PR.
7-
Changes in the metrics, compared to previous runs from the main branch, should be evaluated on case-by-case basis when preparing and reviewing the PR.
6+
The general idea is to run a web app without Sentry, and then run the same app again with Sentry and another one with
7+
Sentry+Replay included. For the three scenarios, we collect some metrics (CPU, memory, vitals) and later compare them
8+
and post as a comment in a PR. Changes in the metrics, compared to previous runs from the main branch, should be
9+
evaluated on case-by-case basis when preparing and reviewing the PR.
810

911
## Resources
1012

11-
* https://github.com/addyosmani/puppeteer-webperf
13+
- https://github.com/addyosmani/puppeteer-webperf
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Replay metrics configuration & entrypoints (scripts)
22

3-
* [dev](dev) contains scripts launched during local development
4-
* [ci](ci) contains scripts launched in CI
3+
- [dev](dev) contains scripts launched during local development
4+
- [ci](ci) contains scripts launched in CI
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Chrome DevTools Jank article sample code
22

3-
* Originally coming from [devtools-samples](https://github.com/GoogleChrome/devtools-samples/tree/4818abc9dbcdb954d0eb9b70879f4ea18756451f/jank), licensed under Apache 2.0.
4-
* Linking article: <https://developer.chrome.com/docs/devtools/evaluate-performance/#get-started>
3+
- Originally coming from
4+
[devtools-samples](https://github.com/GoogleChrome/devtools-samples/tree/4818abc9dbcdb954d0eb9b70879f4ea18756451f/jank),
5+
licensed under Apache 2.0.
6+
- Linking article: <https://developer.chrome.com/docs/devtools/evaluate-performance/#get-started>

dev-packages/rollup-utils/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# The `rollup-utils` Package
22

3-
This is a small utility packages for all the Rollup configurations we have in this project. It contains helpers to create standardized configs, custom rollup plugins, and other things that might have to do with the build process like polyfill snippets.
3+
This is a small utility packages for all the Rollup configurations we have in this project. It contains helpers to
4+
create standardized configs, custom rollup plugins, and other things that might have to do with the build process like
5+
polyfill snippets.
46

57
This package will not be published and is only intended to be used inside this repository.

docs/migration/v4-to-v5_v6.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Upgrading from 4.x to 5.x/6.x
22

3-
We recommend upgrading from `4.x` to `6.x` directly. Migrating from `5.x` to `6.x` has no breaking changes to the SDK's API.
3+
We recommend upgrading from `4.x` to `6.x` directly. Migrating from `5.x` to `6.x` has no breaking changes to the SDK's
4+
API.
45

56
In this version upgrade, there are a few breaking changes. This guide should help you update your code accordingly.
67

docs/migration/v6-to-v7.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,3 @@ const levelA = Severity.error;
541541

542542
const levelB: SeverityLevel = "error"
543543
```
544-

docs/v8-new-performance-apis.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@ interface SpanContext {
5555
name: string;
5656
attributes?: SpanAttributes;
5757
op?: string;
58-
// TODO: Not yet implemented, but you should be able to pass a scope to base this off
5958
scope?: Scope;
60-
// TODO: The list below may change a bit...
61-
origin?: SpanOrigin;
62-
source?: SpanSource;
63-
metadata?: Partial<SpanMetadata>;
59+
forceTransaction?: boolean;
6460
}
6561
```
6662

docs/v8-node.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Using `@sentry/node` in v8
2+
3+
With v8, `@sentry/node` has been completely overhauled. It is now powered by [OpenTelemetry](https://opentelemetry.io/)
4+
under the hood.
5+
6+
## What is OpenTelemetry
7+
8+
You do not need to know or understand what OpenTelemetry is in order to use Sentry. We set up OpenTelemetry under the
9+
hood, no knowledge of it is required in order to get started.
10+
11+
If you want, you can use OpenTelemetry-native APIs to start spans, and Sentry will pick up everything automatically.
12+
13+
## Supported Frameworks & Libraries
14+
15+
We support the following Node Frameworks out of the box:
16+
17+
- [Express](#express)
18+
- Fastify
19+
- Koa
20+
- Nest.js
21+
- Hapi
22+
23+
We also support auto instrumentation for the following libraries:
24+
25+
- mysql
26+
- mysql2
27+
- pg
28+
- GraphQL (including Apollo Server)
29+
- mongo
30+
- mongoose
31+
- Prisma
32+
33+
## General Changes to v7
34+
35+
There are some general changes that have been made that apply to any usage of `@sentry/node`.
36+
37+
### `Sentry.init()` has to be called before any other require/import
38+
39+
Due to the way that OpenTelemetry auto instrumentation works, it is required that you initialize Sentry _before_ you
40+
require or import any other package. Any package that is required/imported before Sentry is initialized may not be
41+
correctly auto-instrumented.
42+
43+
```js
44+
// In v7, this was fine:
45+
const Sentry = require('@sentry/node');
46+
const express = require('express');
47+
48+
Sentry.init({
49+
// ...
50+
});
51+
52+
const app = express();
53+
```
54+
55+
```js
56+
// In v8, in order to ensure express is instrumented,
57+
// you have to initialize before you import:
58+
const Sentry = require('@sentry/node');
59+
Sentry.init({
60+
// ...
61+
});
62+
63+
const express = require('express');
64+
const app = express();
65+
```
66+
67+
### Performance Instrumentation is enabled by default
68+
69+
All performance auto-instrumentation will be automatically enabled if the package is found. You do not need to add any
70+
integration yourself, and `autoDiscoverNodePerformanceMonitoringIntegrations()` has also been removed.
71+
72+
### Old Performance APIs are removed
73+
74+
See [New Performance APIs](./v8-new-performance-apis.md) for details.
75+
76+
### ESM Support
77+
78+
For now, ESM support is only experimental. For the time being we only fully support CJS-based Node application - we are
79+
working on this during the v8 alpha/beta cycle.
80+
81+
## Express
82+
83+
The following shows how you can setup Express instrumentation in v8. This will capture performance data & errors for
84+
your Express app.
85+
86+
```js
87+
const Sentry = require('@sentry/node');
88+
89+
Sentry.init({
90+
dsn: '__DSN__',
91+
tracesSampleRate: 1,
92+
});
93+
94+
const express = require('express');
95+
const app = express();
96+
97+
// add routes etc. here
98+
99+
Sentry.setupExpressErrorHandler(app);
100+
// add other error middleware below this, if needed
101+
102+
app.listen(3000);
103+
```

0 commit comments

Comments
 (0)