Skip to content

Commit b9e7022

Browse files
authored
Merge branch 'master' into abhi/circular-dep
2 parents 3cf9687 + 145221d commit b9e7022

File tree

6 files changed

+80
-18
lines changed

6 files changed

+80
-18
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import { HttpErrorResponse } from '@angular/common/http';
22
import { ErrorHandler as AngularErrorHandler, Injectable } from '@angular/core';
33
import * as Sentry from '@sentry/browser';
44

5+
// That's the `global.Zone` exposed when the `zone.js` package is used.
6+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7+
declare const Zone: any;
8+
9+
// There're 2 types of Angular applications:
10+
// 1) zone-full (by default)
11+
// 2) zone-less
12+
// The developer can avoid importing the `zone.js` package and tells Angular that
13+
// he is responsible for running the change detection by himself. This is done by
14+
// "nooping" the zone through `CompilerOptions` when bootstrapping the root module.
15+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
16+
const isNgZoneEnabled = typeof Zone !== 'undefined' && !!Zone.current;
17+
518
/**
619
* Options used to configure the behavior of the Angular ErrorHandler.
720
*/
@@ -38,7 +51,16 @@ class SentryErrorHandler implements AngularErrorHandler {
3851
const extractedError = this._extractError(error) || 'Handled unknown error';
3952

4053
// Capture handled exception and send it to Sentry.
41-
const eventId = Sentry.captureException(extractedError);
54+
const eventId = isNgZoneEnabled
55+
? // The `Zone.root.run` basically will capture the exception in the most parent zone.
56+
// The Angular's zone is forked from the `Zone.root`. In this case, `zone.js` won't
57+
// trigger change detection, and `ApplicationRef.tick()` will not be run.
58+
// Caretaker note: we're using `Zone.root` except `NgZone.runOutsideAngular` since this
59+
// will require injecting the `NgZone` facade. That will create a breaking change for
60+
// projects already using the `SentryErrorHandler`.
61+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
62+
Zone.root.run(() => Sentry.captureException(extractedError))
63+
: Sentry.captureException(extractedError);
4264

4365
// When in development mode, log the error to console for immediate feedback.
4466
if (this._options.logErrors) {

packages/angular/src/tracing.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ import { logger, stripUrlQueryAndFragment, timestampWithMs } from '@sentry/utils
66
import { Observable, Subscription } from 'rxjs';
77
import { filter, tap } from 'rxjs/operators';
88

9+
// That's the `global.Zone` exposed when the `zone.js` package is used.
10+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11+
declare const Zone: any;
12+
13+
// There're 2 types of Angular applications:
14+
// 1) zone-full (by default)
15+
// 2) zone-less
16+
// The developer can avoid importing the `zone.js` package and tells Angular that
17+
// he is responsible for running the change detection by himself. This is done by
18+
// "nooping" the zone through `CompilerOptions` when bootstrapping the root module.
19+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
20+
const isNgZoneEnabled = typeof Zone !== 'undefined' && !!Zone.current;
21+
922
let instrumentationInitialized: boolean;
1023
let stashedStartTransaction: (context: TransactionContext) => Transaction | undefined;
1124
let stashedStartTransactionOnLocationChange: boolean;
@@ -93,13 +106,27 @@ export class TraceService implements OnDestroy {
93106
filter(event => event instanceof NavigationEnd),
94107
tap(() => {
95108
if (this._routingSpan) {
96-
this._routingSpan.finish();
97-
delete this._routingSpan;
109+
if (isNgZoneEnabled) {
110+
// The `Zone.root.run` basically will finish the transaction in the most parent zone.
111+
// The Angular's zone is forked from the `Zone.root`. In this case, `zone.js` won't
112+
// trigger change detection, and `ApplicationRef.tick()` will not be run.
113+
// Caretaker note: we're using `Zone.root` except `NgZone.runOutsideAngular` since this
114+
// will require injecting the `NgZone` facade. That will create a breaking change for
115+
// projects already using the `TraceService`.
116+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
117+
Zone.root.run(() => {
118+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119+
this._routingSpan!.finish();
120+
});
121+
} else {
122+
this._routingSpan.finish();
123+
}
124+
this._routingSpan = null;
98125
}
99126
}),
100127
);
101128

102-
private _routingSpan?: Span;
129+
private _routingSpan: Span | null = null;
103130
private _subscription: Subscription = new Subscription();
104131

105132
public constructor(private readonly _router: Router) {
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
### To prepare branch for deploying on Vercel:
1+
# Testing an SDK Branch on Vercel
2+
3+
Follow the instructions below to test a branch of the SDK against a test app deployed to Vercel. This assumes you
4+
already have such an app set up, and modifies both it and the SDK branch such that the dependency installation process
5+
run on Vercel includes cloning the repo, building the current branch of the SDK, and setting the test app's
6+
`@sentry/next` dependency to point to the newly-built local version.
7+
8+
(The clone-build-link step is necessary because you can't point a `package.json` dependency to a sub-folder of a git
9+
repo, only a full repo itself. Since we run a monorepo, this won't work in our case.)
10+
11+
### To prepare your SDK branch for deploying on Vercel
212

313
From `packages/nextjs`, run
414

@@ -7,7 +17,7 @@ From `packages/nextjs`, run
717
This will delete unneeded packages (angular, vue, etc) in order to speed up deployment. It will then commit that change.
818
When your branch is ready to PR, just rebase and drop that commit.
919

10-
### To prepare test app for using current branch:
20+
### To prepare your test app for using current SDK branch
1121

1222
First, make sure the branch you want to test is checked out in your `sentry-javascript` repo, and that all changes you
1323
want to test are pushed to GitHub.
@@ -16,9 +26,10 @@ From `packages/nextjs`, run
1626

1727
`yarn vercel:project <path/to/testapp>`.
1828

19-
This will copy a script into a `.sentry` folder at the root level of your test app,and create a second one. (The first
20-
script is the one you'll run on Vercel. The second is a helper to the first, so that it knows which branch to use.) It
21-
will then commit (but not push) this change.
29+
This will copy the `install-sentry-from-branch.sh` script into a `.sentry` folder at the root level of your test app,
30+
and create a `set-branch-name.sh` script in the same location. (The first script is the one you'll run on Vercel. The
31+
second is called by the first, and just sets an environment variable with the current (SDK) branch name.) It will then
32+
commit (but not push) this change.
2233

2334
Go into your project settings on Vercel and change the install command to
2435

@@ -30,9 +41,12 @@ If you're using bundle analyzer, change the build command to
3041

3142
The bundle visualizations will be available on your deployed site at `/client.html` and `/server.html`.
3243

33-
### To test the SDK:
44+
NOTE: You don't need to change the `@sentry/nextjs` dependency in your project's `package.json` file. That will happen
45+
on the fly each time your app is deployed.
46+
47+
### To test the SDK
3448

35-
Once you have pushed the changes made by `yarn vercel:project` to GitHub, just make changes and push, and Vercel will
36-
always use the latest version of both the SDK and your test app. Pushing changes to your test app will trigger a new
37-
build in Vercel; for changes to the SDK, you'll need to manually redeploy, either by kicking off a new build or simply
38-
choosing 'Redeploy' on your most recent existing build.
49+
Once you have pushed the changes made by `yarn vercel:project` to GitHub, just make changes (either to the SDK or your
50+
test app) and push them. Vercel will always use the latest version of both the SDK and your test app each time it
51+
deploys. Pushing changes to your test app will trigger a new build in Vercel; for changes to the SDK, you'll need to
52+
manually redeploy, either by kicking off a new build or simply choosing 'Redeploy' on your most recent existing build.

packages/nextjs/vercel/make-project-use-current-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ yarn vercel:branch
1919

2020
cd $PROJECT_DIR
2121

22-
# make sure we're dealing with a clean repo
22+
# make sure we're dealing with a clean test app repo
2323
STASHED_CHANGES=$(git status --porcelain)
2424
if [ -n "${STASHED_CHANGES}" ]; then
2525
echo "Found uncommitted changes in your project. Stashing them."

packages/nextjs/vercel/set-up-branch-for-test-app-use.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ NEXTJS_SDK_DIR=$(pwd)
99
# this puts us in the repo root
1010
cd ../..
1111

12-
# make sure we're dealing with a clean repo
12+
# make sure we're dealing with a clean SDK repo
1313
STASHED_CHANGES=$(git status --porcelain)
1414
if [ -n "${STASHED_CHANGES}" ]; then
1515
echo "Found uncommitted changes. Stashing them."

packages/node/src/integrations/console.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ export class Console implements Integration {
1919
* @inheritDoc
2020
*/
2121
public setupOnce(): void {
22-
const consoleModule = require('console');
2322
for (const level of ['debug', 'info', 'warn', 'error', 'log']) {
24-
fill(consoleModule, level, createConsoleWrapper(level));
23+
fill(console, level, createConsoleWrapper(level));
2524
}
2625
}
2726
}

0 commit comments

Comments
 (0)