Skip to content

Commit 60743c5

Browse files
committed
Merge branch master into feat/next-js
2 parents 61e401d + ce40962 commit 60743c5

Some content is hidden

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

57 files changed

+3782
-4129
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@
44

55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

7+
## 6.2.5
8+
9+
- [utils] fix: Avoid performance.timeOrigin if too skewed (#3356)
10+
11+
## 6.2.4
12+
13+
- [browser] fix: Add `SentryRequestType` to `RateLimitingCategory` mapping (#3328)
14+
- [browser] ref: Add fast-path to `fetchImpl` and cleanup redundant iframe (#3341)
15+
- [node] fix: Fallback to empty string if `req.baseUrl` is empty (#3329)
16+
- [node] ref: Remove circular dependency in `@sentry/node` (#3335)
17+
- [tracing] fix: Attach mysql tracing to `Connection.createQuery` instead of `Connection.prototype.query` (#3353)
18+
- [tracing] ref: Clarify naming in `BrowserTracing` integration (#3338)
19+
- [ember] ref: Fix tests to be forward compatible with component changes (#3347)
20+
- [ember] ref: Silence deprecation warnings in beta (#3346)
21+
22+
## 6.2.3
23+
24+
- [gatsby] fix: Update Vercel environment variables to match their current system variables (#3337)
25+
26+
## 6.2.2
27+
28+
- [hub] fix: Only create sessions if the correct methods are defined (#3281)
29+
- [core] fix: Don't override SDK metadata (#3304)
30+
- [browser] fix: Prevent fetch errors loops with invalid fetch implementations (#3318)
31+
- [serverless] ref: Add compatible runtime nodejs14.x to building awslambda layer (#3303)
32+
- [ember] fix: Keep route hook context when performance-wrapping (#3274)
33+
- [integrations] fix: Normalized Event before caching. (#3305)
34+
735
## 6.2.1
836

937
- [core] fix: Moves SDK metadata-setting into the `NodeClient/BrowserClient` to protect it from being overwritten by other classes extending `BaseClient` like @sentry/serverless (#3279)

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<br />
66
</p>
77

8+
_Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoying technology. If you want to join us [<kbd>**Check out our open positions**</kbd>](https://sentry.io/careers/)_
9+
810
![Build & Test](https://github.com/getsentry/sentry-javascript/workflows/Build%20&%20Test/badge.svg)
911
[![codecov](https://codecov.io/gh/getsentry/sentry-javascript/branch/master/graph/badge.svg)](https://codecov.io/gh/getsentry/sentry-javascript)
1012
[![npm version](https://img.shields.io/npm/v/@sentry/core.svg)](https://www.npmjs.com/package/@sentry/core)
@@ -37,14 +39,14 @@ convenient interface and improved consistency between various JavaScript environ
3739
For each major JavaScript platform, there is a specific high-level SDK that provides all the tools you need in a single
3840
package. Please refer to the README and instructions of those SDKs for more detailed information:
3941

40-
- [`@sentry/browser`](https://github.com/getsentry/sentry-javascript/tree/master/packages/browser): SDK for Browsers,
41-
including integrations for React, Angular, Ember, Vue and Backbone
42+
- [`@sentry/browser`](https://github.com/getsentry/sentry-javascript/tree/master/packages/browser): SDK for Browsers
43+
including integrations for Backbone
4244
- [`@sentry/node`](https://github.com/getsentry/sentry-javascript/tree/master/packages/node): SDK for Node, including
4345
integrations for Express, Koa, Loopback, Sails and Connect
44-
- [`@sentry/angular`](https://github.com/getsentry/sentry-javascript/tree/master/packages/angular): SDK for Angular
45-
- [`@sentry/react`](https://github.com/getsentry/sentry-javascript/tree/master/packages/react): SDK for ReactJS
46-
- [`@sentry/ember`](https://github.com/getsentry/sentry-javascript/tree/master/packages/ember): SDK for Ember
47-
- [`@sentry/vue`](https://github.com/getsentry/sentry-javascript/tree/master/packages/vue): SDK for Vue.js
46+
- [`@sentry/angular`](https://github.com/getsentry/sentry-javascript/tree/master/packages/angular): browser SDK with Angular integration enabled
47+
- [`@sentry/react`](https://github.com/getsentry/sentry-javascript/tree/master/packages/react): browser SDK with React integration enabled
48+
- [`@sentry/ember`](https://github.com/getsentry/sentry-javascript/tree/master/packages/ember): browser SDK with Ember integration enabled
49+
- [`@sentry/vue`](https://github.com/getsentry/sentry-javascript/tree/master/packages/vue): browser SDK with Vue integration enabled
4850
- [`@sentry/gatsby`](https://github.com/getsentry/sentry-javascript/tree/master/packages/gatsby): SDK for Gatsby
4951
- [`@sentry/react-native`](https://github.com/getsentry/sentry-react-native): SDK for React Native with support for native crashes
5052
- [`@sentry/integrations`](https://github.com/getsentry/sentry-javascript/tree/master/packages/integrations): Pluggable

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lerna": "3.4.0",
3-
"version": "6.2.1",
3+
"version": "6.2.5",
44
"packages": "packages/*",
55
"npmClient": "yarn",
66
"useWorkspaces": true

packages/angular/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ Registering a Trace Service is a 3-step process.
8282
instrumentation:
8383

8484
```javascript
85-
import { init, routingInstrumentation } from '@sentry/angular';
85+
import { init, instrumentAngularRouting } from '@sentry/angular';
8686
import { Integrations as TracingIntegrations } from '@sentry/tracing';
8787

8888
init({
8989
dsn: '__DSN__',
9090
integrations: [
9191
new TracingIntegrations.BrowserTracing({
9292
tracingOrigins: ['localhost', 'https://yourserver.io/api'],
93-
routingInstrumentation: routingInstrumentation,
93+
routingInstrumentation: instrumentAngularRouting,
9494
}),
9595
],
9696
tracesSampleRate: 1,

packages/angular/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/angular",
3-
"version": "6.2.1",
3+
"version": "6.2.5",
44
"description": "Offical Sentry SDK for Angular",
55
"repository": "git://github.com/getsentry/sentry-javascript.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/angular",
@@ -21,17 +21,17 @@
2121
"@angular/router": "10.x || 11.x"
2222
},
2323
"dependencies": {
24-
"@sentry/browser": "6.2.1",
25-
"@sentry/types": "6.2.1",
26-
"@sentry/utils": "6.2.1",
24+
"@sentry/browser": "6.2.5",
25+
"@sentry/types": "6.2.5",
26+
"@sentry/utils": "6.2.5",
2727
"rxjs": "^6.6.0",
2828
"tslib": "^1.9.3"
2929
},
3030
"devDependencies": {
3131
"@angular/common": "^10.0.3",
3232
"@angular/core": "^10.0.3",
3333
"@angular/router": "^10.0.3",
34-
"@sentry-internal/eslint-config-sdk": "6.2.1",
34+
"@sentry-internal/eslint-config-sdk": "6.2.5",
3535
"eslint": "7.6.0",
3636
"npm-run-all": "^4.1.2",
3737
"prettier": "1.19.0",

packages/angular/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export { init } from './sdk';
44
export { createErrorHandler, ErrorHandlerOptions } from './errorhandler';
55
export {
66
getActiveTransaction,
7-
routingInstrumentation,
7+
// TODO `instrumentAngularRouting` is just an alias for `routingInstrumentation`; deprecate the latter at some point
8+
instrumentAngularRouting, // new name
9+
routingInstrumentation, // legacy name
810
TraceClassDecorator,
911
TraceMethodDecorator,
1012
TraceDirective,

packages/angular/src/tracing.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@ let stashedStartTransactionOnLocationChange: boolean;
1414
* Creates routing instrumentation for Angular Router.
1515
*/
1616
export function routingInstrumentation(
17-
startTransaction: (context: TransactionContext) => Transaction | undefined,
17+
customStartTransaction: (context: TransactionContext) => Transaction | undefined,
1818
startTransactionOnPageLoad: boolean = true,
1919
startTransactionOnLocationChange: boolean = true,
2020
): void {
2121
instrumentationInitialized = true;
22-
stashedStartTransaction = startTransaction;
22+
stashedStartTransaction = customStartTransaction;
2323
stashedStartTransactionOnLocationChange = startTransactionOnLocationChange;
2424

2525
if (startTransactionOnPageLoad) {
26-
startTransaction({
26+
customStartTransaction({
2727
name: window.location.pathname,
2828
op: 'pageload',
2929
});
3030
}
3131
}
3232

33+
export const instrumentAngularRouting = routingInstrumentation;
34+
3335
/**
3436
* Grabs active transaction off scope
3537
*/

packages/browser/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/browser",
3-
"version": "6.2.1",
3+
"version": "6.2.5",
44
"description": "Official Sentry SDK for browsers",
55
"repository": "git://github.com/getsentry/sentry-javascript.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/browser",
@@ -16,13 +16,13 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19-
"@sentry/core": "6.2.1",
20-
"@sentry/types": "6.2.1",
21-
"@sentry/utils": "6.2.1",
19+
"@sentry/core": "6.2.5",
20+
"@sentry/types": "6.2.5",
21+
"@sentry/utils": "6.2.5",
2222
"tslib": "^1.9.3"
2323
},
2424
"devDependencies": {
25-
"@sentry-internal/eslint-config-sdk": "6.2.1",
25+
"@sentry-internal/eslint-config-sdk": "6.2.5",
2626
"@types/eslint": "^7.2.0",
2727
"@types/md5": "2.1.33",
2828
"btoa": "^1.2.1",

packages/browser/src/sdk.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,23 @@ function startSessionTracking(): void {
189189

190190
const hub = getCurrentHub();
191191

192-
hub.startSession();
193-
hub.captureSession();
194-
195-
// We want to create a session for every navigation as well
196-
addInstrumentationHandler({
197-
callback: () => {
198-
hub.startSession();
199-
hub.captureSession();
200-
},
201-
type: 'history',
202-
});
192+
if ('startSession' in hub) {
193+
// The only way for this to be false is for there to be a version mismatch between @sentry/browser (>= 6.0.0) and
194+
// @sentry/hub (< 5.27.0). In the simple case, there won't ever be such a mismatch, because the two packages are
195+
// pinned at the same version in package.json, but there are edge cases where it's possible'. See
196+
// https://github.com/getsentry/sentry-javascript/issues/3234 and
197+
// https://github.com/getsentry/sentry-javascript/issues/3207.
198+
199+
hub.startSession();
200+
hub.captureSession();
201+
202+
// We want to create a session for every navigation as well
203+
addInstrumentationHandler({
204+
callback: () => {
205+
hub.startSession();
206+
hub.captureSession();
207+
},
208+
type: 'history',
209+
});
210+
}
203211
}

packages/browser/src/transports/base.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import {
99
} from '@sentry/types';
1010
import { logger, parseRetryAfterHeader, PromiseBuffer, SentryError } from '@sentry/utils';
1111

12+
const CATEGORY_MAPPING: {
13+
[key in SentryRequestType]: string;
14+
} = {
15+
event: 'error',
16+
transaction: 'transaction',
17+
session: 'session',
18+
};
19+
1220
/** Base Transport class implementation */
1321
export abstract class BaseTransport implements Transport {
1422
/**
@@ -80,15 +88,16 @@ export abstract class BaseTransport implements Transport {
8088
/**
8189
* Gets the time that given category is disabled until for rate limiting
8290
*/
83-
protected _disabledUntil(category: string): Date {
91+
protected _disabledUntil(requestType: SentryRequestType): Date {
92+
const category = CATEGORY_MAPPING[requestType];
8493
return this._rateLimits[category] || this._rateLimits.all;
8594
}
8695

8796
/**
8897
* Checks if a category is rate limited
8998
*/
90-
protected _isRateLimited(category: string): boolean {
91-
return this._disabledUntil(category) > new Date(Date.now());
99+
protected _isRateLimited(requestType: SentryRequestType): boolean {
100+
return this._disabledUntil(requestType) > new Date(Date.now());
92101
}
93102

94103
/**

packages/browser/src/transports/fetch.ts

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,91 @@
11
import { eventToSentryRequest, sessionToSentryRequest } from '@sentry/core';
2-
import { Event, Response, SentryRequest, Session } from '@sentry/types';
3-
import { getGlobalObject, supportsReferrerPolicy, SyncPromise } from '@sentry/utils';
2+
import { Event, Response, SentryRequest, Session, TransportOptions } from '@sentry/types';
3+
import { getGlobalObject, isNativeFetch, logger, supportsReferrerPolicy, SyncPromise } from '@sentry/utils';
44

55
import { BaseTransport } from './base';
66

7-
const global = getGlobalObject<Window>();
7+
type FetchImpl = typeof fetch;
8+
9+
/**
10+
* A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
11+
* Whenever someone wraps the Fetch API and returns the wrong promise chain,
12+
* this chain becomes orphaned and there is no possible way to capture it's rejections
13+
* other than allowing it bubble up to this very handler. eg.
14+
*
15+
* const f = window.fetch;
16+
* window.fetch = function () {
17+
* const p = f.apply(this, arguments);
18+
*
19+
* p.then(function() {
20+
* console.log('hi.');
21+
* });
22+
*
23+
* return p;
24+
* }
25+
*
26+
* `p.then(function () { ... })` is producing a completely separate promise chain,
27+
* however, what's returned is `p` - the result of original `fetch` call.
28+
*
29+
* This mean, that whenever we use the Fetch API to send our own requests, _and_
30+
* some ad-blocker blocks it, this orphaned chain will _always_ reject,
31+
* effectively causing another event to be captured.
32+
* This makes a whole process become an infinite loop, which we need to somehow
33+
* deal with, and break it in one way or another.
34+
*
35+
* To deal with this issue, we are making sure that we _always_ use the real
36+
* browser Fetch API, instead of relying on what `window.fetch` exposes.
37+
* The only downside to this would be missing our own requests as breadcrumbs,
38+
* but because we are already not doing this, it should be just fine.
39+
*
40+
* Possible failed fetch error messages per-browser:
41+
*
42+
* Chrome: Failed to fetch
43+
* Edge: Failed to Fetch
44+
* Firefox: NetworkError when attempting to fetch resource
45+
* Safari: resource blocked by content blocker
46+
*/
47+
function getNativeFetchImplementation(): FetchImpl {
48+
/* eslint-disable @typescript-eslint/unbound-method */
49+
50+
// Fast path to avoid DOM I/O
51+
const global = getGlobalObject<Window>();
52+
if (isNativeFetch(global.fetch)) {
53+
return global.fetch.bind(global);
54+
}
55+
56+
const document = global.document;
57+
let fetchImpl = global.fetch;
58+
// eslint-disable-next-line deprecation/deprecation
59+
if (typeof document?.createElement === `function`) {
60+
try {
61+
const sandbox = document.createElement('iframe');
62+
sandbox.hidden = true;
63+
document.head.appendChild(sandbox);
64+
if (sandbox.contentWindow?.fetch) {
65+
fetchImpl = sandbox.contentWindow.fetch;
66+
}
67+
document.head.removeChild(sandbox);
68+
} catch (e) {
69+
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
70+
}
71+
}
72+
73+
return fetchImpl.bind(global);
74+
/* eslint-enable @typescript-eslint/unbound-method */
75+
}
876

977
/** `fetch` based transport */
1078
export class FetchTransport extends BaseTransport {
79+
/**
80+
* Fetch API reference which always points to native browser implementation.
81+
*/
82+
private _fetch: typeof fetch;
83+
84+
constructor(options: TransportOptions, fetchImpl: FetchImpl = getNativeFetchImplementation()) {
85+
super(options);
86+
this._fetch = fetchImpl;
87+
}
88+
1189
/**
1290
* @inheritDoc
1391
*/
@@ -54,8 +132,7 @@ export class FetchTransport extends BaseTransport {
54132

55133
return this._buffer.add(
56134
new SyncPromise<Response>((resolve, reject) => {
57-
global
58-
.fetch(sentryRequest.url, options)
135+
this._fetch(sentryRequest.url, options)
59136
.then(response => {
60137
const headers = {
61138
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),

0 commit comments

Comments
 (0)