Skip to content

Update feat/next-js branch #3366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5997e04
fix(release health): Only create sessions if the correct methods are …
lobsterkatie Mar 5, 2021
58b2ba1
misc: We're hiring (#3312)
bruno-garcia Mar 5, 2021
a40a0da
fix(ember): keep route hook context when performance-wrapping (#3274)
alexlafroscia Mar 9, 2021
ddda018
fix: Prevent fetch errors loops with invalid fetch implementations (#…
kamilogorek Mar 10, 2021
0abfa10
misc: Clarified description of browser SDK (#3322)
adam000034 Mar 11, 2021
97daa3b
chore(deps): bump elliptic in /packages/node/test/manual/webpack-doma…
dependabot[bot] Mar 11, 2021
02a8c59
chore(deps): bump elliptic from 6.5.3 to 6.5.4 (#3315)
dependabot[bot] Mar 11, 2021
f824c80
fix: Normalized Event before caching. (#3305)
mac89 Mar 11, 2021
a31ac41
misc: 6.2.2 changelog
kamilogorek Mar 11, 2021
547a01e
release: 6.2.2
Mar 11, 2021
57423ee
Merge release/6.2.2 into master
getsentry-bot Mar 11, 2021
cb66fa4
VERCEL_GITHUB_COMMIT_SHA → VERCEL_GIT_COMMIT_SHA (#3337)
Mar 18, 2021
d2a032f
misc: 6.2.3 changelog
Mar 19, 2021
dbb243c
release: 6.2.3
Mar 19, 2021
bcac95d
Merge release/6.2.3 into master
jan-auer Mar 19, 2021
2d6196b
ref: Add fast-path to fetchImpl and cleanup redundant iframe (#3341)
kamilogorek Mar 22, 2021
77b8301
fix: Fallback to empty string if req.baseUrl is empty (#3329)
kamilogorek Mar 22, 2021
3eb9e05
ref(tracing): Clarify naming in BrowserTracing integration (#3338)
lobsterkatie Mar 22, 2021
a6f8dc2
fix: Add SentryRequestType to RateLimitingCategory mapping (#3328)
kamilogorek Mar 23, 2021
defce67
ref(ember): Fix tests to be forward compatible with component changes…
k-fish Mar 29, 2021
5339751
ref: Remove circular dependency in @sentry/node (#3335)
tkalliom Mar 29, 2021
9af3095
ref(ember): Silence deprecation warnings in beta (#3346)
k-fish Mar 29, 2021
a081cdf
fix: Attach mysql tracing to Connection.createQuery instead of Connec…
zchristopoulos Mar 30, 2021
9e9f2a4
misc: 6.2.4 changelog
kamilogorek Mar 30, 2021
3556d73
misc: Update @sentry/react dependencies to fix types issue
kamilogorek Mar 30, 2021
007e62f
misc: Update @sentry/react dependencies to fix types issue vol. 2
kamilogorek Mar 30, 2021
6e6786f
misc: Refresh yarn.lock to lock deps for CI
kamilogorek Mar 30, 2021
40eab2e
release: 6.2.4
Mar 30, 2021
28c540c
Merge release/6.2.4 into master
getsentry-bot Mar 30, 2021
dece89a
fix: Avoid performance.timeOrigin if too skewed (#3356)
wmak Mar 31, 2021
a4f0b45
misc: CHANGELOG for 6.2.5
rhcarvalho Apr 1, 2021
1b59574
release: 6.2.5
Apr 1, 2021
065c239
Merge release/6.2.5 into master
getsentry-bot Apr 1, 2021
ce40962
fix: Provide better descriptions for the performance navigation timin…
dashed Apr 1, 2021
60743c5
Merge branch master into feat/next-js
rhcarvalho Apr 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@

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

## 6.2.5

- [utils] fix: Avoid performance.timeOrigin if too skewed (#3356)

## 6.2.4

- [browser] fix: Add `SentryRequestType` to `RateLimitingCategory` mapping (#3328)
- [browser] ref: Add fast-path to `fetchImpl` and cleanup redundant iframe (#3341)
- [node] fix: Fallback to empty string if `req.baseUrl` is empty (#3329)
- [node] ref: Remove circular dependency in `@sentry/node` (#3335)
- [tracing] fix: Attach mysql tracing to `Connection.createQuery` instead of `Connection.prototype.query` (#3353)
- [tracing] ref: Clarify naming in `BrowserTracing` integration (#3338)
- [ember] ref: Fix tests to be forward compatible with component changes (#3347)
- [ember] ref: Silence deprecation warnings in beta (#3346)

## 6.2.3

- [gatsby] fix: Update Vercel environment variables to match their current system variables (#3337)

## 6.2.2

- [hub] fix: Only create sessions if the correct methods are defined (#3281)
- [core] fix: Don't override SDK metadata (#3304)
- [browser] fix: Prevent fetch errors loops with invalid fetch implementations (#3318)
- [serverless] ref: Add compatible runtime nodejs14.x to building awslambda layer (#3303)
- [ember] fix: Keep route hook context when performance-wrapping (#3274)
- [integrations] fix: Normalized Event before caching. (#3305)

## 6.2.1

- [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)
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<br />
</p>

_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/)_

![Build & Test](https://github.com/getsentry/sentry-javascript/workflows/Build%20&%20Test/badge.svg)
[![codecov](https://codecov.io/gh/getsentry/sentry-javascript/branch/master/graph/badge.svg)](https://codecov.io/gh/getsentry/sentry-javascript)
[![npm version](https://img.shields.io/npm/v/@sentry/core.svg)](https://www.npmjs.com/package/@sentry/core)
Expand Down Expand Up @@ -37,14 +39,14 @@ convenient interface and improved consistency between various JavaScript environ
For each major JavaScript platform, there is a specific high-level SDK that provides all the tools you need in a single
package. Please refer to the README and instructions of those SDKs for more detailed information:

- [`@sentry/browser`](https://github.com/getsentry/sentry-javascript/tree/master/packages/browser): SDK for Browsers,
including integrations for React, Angular, Ember, Vue and Backbone
- [`@sentry/browser`](https://github.com/getsentry/sentry-javascript/tree/master/packages/browser): SDK for Browsers
including integrations for Backbone
- [`@sentry/node`](https://github.com/getsentry/sentry-javascript/tree/master/packages/node): SDK for Node, including
integrations for Express, Koa, Loopback, Sails and Connect
- [`@sentry/angular`](https://github.com/getsentry/sentry-javascript/tree/master/packages/angular): SDK for Angular
- [`@sentry/react`](https://github.com/getsentry/sentry-javascript/tree/master/packages/react): SDK for ReactJS
- [`@sentry/ember`](https://github.com/getsentry/sentry-javascript/tree/master/packages/ember): SDK for Ember
- [`@sentry/vue`](https://github.com/getsentry/sentry-javascript/tree/master/packages/vue): SDK for Vue.js
- [`@sentry/angular`](https://github.com/getsentry/sentry-javascript/tree/master/packages/angular): browser SDK with Angular integration enabled
- [`@sentry/react`](https://github.com/getsentry/sentry-javascript/tree/master/packages/react): browser SDK with React integration enabled
- [`@sentry/ember`](https://github.com/getsentry/sentry-javascript/tree/master/packages/ember): browser SDK with Ember integration enabled
- [`@sentry/vue`](https://github.com/getsentry/sentry-javascript/tree/master/packages/vue): browser SDK with Vue integration enabled
- [`@sentry/gatsby`](https://github.com/getsentry/sentry-javascript/tree/master/packages/gatsby): SDK for Gatsby
- [`@sentry/react-native`](https://github.com/getsentry/sentry-react-native): SDK for React Native with support for native crashes
- [`@sentry/integrations`](https://github.com/getsentry/sentry-javascript/tree/master/packages/integrations): Pluggable
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "3.4.0",
"version": "6.2.1",
"version": "6.2.5",
"packages": "packages/*",
"npmClient": "yarn",
"useWorkspaces": true
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ Registering a Trace Service is a 3-step process.
instrumentation:

```javascript
import { init, routingInstrumentation } from '@sentry/angular';
import { init, instrumentAngularRouting } from '@sentry/angular';
import { Integrations as TracingIntegrations } from '@sentry/tracing';

init({
dsn: '__DSN__',
integrations: [
new TracingIntegrations.BrowserTracing({
tracingOrigins: ['localhost', 'https://yourserver.io/api'],
routingInstrumentation: routingInstrumentation,
routingInstrumentation: instrumentAngularRouting,
}),
],
tracesSampleRate: 1,
Expand Down
10 changes: 5 additions & 5 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/angular",
"version": "6.2.1",
"version": "6.2.5",
"description": "Offical Sentry SDK for Angular",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/angular",
Expand All @@ -21,17 +21,17 @@
"@angular/router": "10.x || 11.x"
},
"dependencies": {
"@sentry/browser": "6.2.1",
"@sentry/types": "6.2.1",
"@sentry/utils": "6.2.1",
"@sentry/browser": "6.2.5",
"@sentry/types": "6.2.5",
"@sentry/utils": "6.2.5",
"rxjs": "^6.6.0",
"tslib": "^1.9.3"
},
"devDependencies": {
"@angular/common": "^10.0.3",
"@angular/core": "^10.0.3",
"@angular/router": "^10.0.3",
"@sentry-internal/eslint-config-sdk": "6.2.1",
"@sentry-internal/eslint-config-sdk": "6.2.5",
"eslint": "7.6.0",
"npm-run-all": "^4.1.2",
"prettier": "1.19.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export { init } from './sdk';
export { createErrorHandler, ErrorHandlerOptions } from './errorhandler';
export {
getActiveTransaction,
routingInstrumentation,
// TODO `instrumentAngularRouting` is just an alias for `routingInstrumentation`; deprecate the latter at some point
instrumentAngularRouting, // new name
routingInstrumentation, // legacy name
TraceClassDecorator,
TraceMethodDecorator,
TraceDirective,
Expand Down
8 changes: 5 additions & 3 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ let stashedStartTransactionOnLocationChange: boolean;
* Creates routing instrumentation for Angular Router.
*/
export function routingInstrumentation(
startTransaction: (context: TransactionContext) => Transaction | undefined,
customStartTransaction: (context: TransactionContext) => Transaction | undefined,
startTransactionOnPageLoad: boolean = true,
startTransactionOnLocationChange: boolean = true,
): void {
instrumentationInitialized = true;
stashedStartTransaction = startTransaction;
stashedStartTransaction = customStartTransaction;
stashedStartTransactionOnLocationChange = startTransactionOnLocationChange;

if (startTransactionOnPageLoad) {
startTransaction({
customStartTransaction({
name: window.location.pathname,
op: 'pageload',
});
}
}

export const instrumentAngularRouting = routingInstrumentation;

/**
* Grabs active transaction off scope
*/
Expand Down
10 changes: 5 additions & 5 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/browser",
"version": "6.2.1",
"version": "6.2.5",
"description": "Official Sentry SDK for browsers",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/browser",
Expand All @@ -16,13 +16,13 @@
"access": "public"
},
"dependencies": {
"@sentry/core": "6.2.1",
"@sentry/types": "6.2.1",
"@sentry/utils": "6.2.1",
"@sentry/core": "6.2.5",
"@sentry/types": "6.2.5",
"@sentry/utils": "6.2.5",
"tslib": "^1.9.3"
},
"devDependencies": {
"@sentry-internal/eslint-config-sdk": "6.2.1",
"@sentry-internal/eslint-config-sdk": "6.2.5",
"@types/eslint": "^7.2.0",
"@types/md5": "2.1.33",
"btoa": "^1.2.1",
Expand Down
30 changes: 19 additions & 11 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,23 @@ function startSessionTracking(): void {

const hub = getCurrentHub();

hub.startSession();
hub.captureSession();

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

hub.startSession();
hub.captureSession();

// We want to create a session for every navigation as well
addInstrumentationHandler({
callback: () => {
hub.startSession();
hub.captureSession();
},
type: 'history',
});
}
}
15 changes: 12 additions & 3 deletions packages/browser/src/transports/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import {
} from '@sentry/types';
import { logger, parseRetryAfterHeader, PromiseBuffer, SentryError } from '@sentry/utils';

const CATEGORY_MAPPING: {
[key in SentryRequestType]: string;
} = {
event: 'error',
transaction: 'transaction',
session: 'session',
};

/** Base Transport class implementation */
export abstract class BaseTransport implements Transport {
/**
Expand Down Expand Up @@ -80,15 +88,16 @@ export abstract class BaseTransport implements Transport {
/**
* Gets the time that given category is disabled until for rate limiting
*/
protected _disabledUntil(category: string): Date {
protected _disabledUntil(requestType: SentryRequestType): Date {
const category = CATEGORY_MAPPING[requestType];
return this._rateLimits[category] || this._rateLimits.all;
}

/**
* Checks if a category is rate limited
*/
protected _isRateLimited(category: string): boolean {
return this._disabledUntil(category) > new Date(Date.now());
protected _isRateLimited(requestType: SentryRequestType): boolean {
return this._disabledUntil(requestType) > new Date(Date.now());
}

/**
Expand Down
87 changes: 82 additions & 5 deletions packages/browser/src/transports/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,91 @@
import { eventToSentryRequest, sessionToSentryRequest } from '@sentry/core';
import { Event, Response, SentryRequest, Session } from '@sentry/types';
import { getGlobalObject, supportsReferrerPolicy, SyncPromise } from '@sentry/utils';
import { Event, Response, SentryRequest, Session, TransportOptions } from '@sentry/types';
import { getGlobalObject, isNativeFetch, logger, supportsReferrerPolicy, SyncPromise } from '@sentry/utils';

import { BaseTransport } from './base';

const global = getGlobalObject<Window>();
type FetchImpl = typeof fetch;

/**
* A special usecase for incorrectly wrapped Fetch APIs in conjunction with ad-blockers.
* Whenever someone wraps the Fetch API and returns the wrong promise chain,
* this chain becomes orphaned and there is no possible way to capture it's rejections
* other than allowing it bubble up to this very handler. eg.
*
* const f = window.fetch;
* window.fetch = function () {
* const p = f.apply(this, arguments);
*
* p.then(function() {
* console.log('hi.');
* });
*
* return p;
* }
*
* `p.then(function () { ... })` is producing a completely separate promise chain,
* however, what's returned is `p` - the result of original `fetch` call.
*
* This mean, that whenever we use the Fetch API to send our own requests, _and_
* some ad-blocker blocks it, this orphaned chain will _always_ reject,
* effectively causing another event to be captured.
* This makes a whole process become an infinite loop, which we need to somehow
* deal with, and break it in one way or another.
*
* To deal with this issue, we are making sure that we _always_ use the real
* browser Fetch API, instead of relying on what `window.fetch` exposes.
* The only downside to this would be missing our own requests as breadcrumbs,
* but because we are already not doing this, it should be just fine.
*
* Possible failed fetch error messages per-browser:
*
* Chrome: Failed to fetch
* Edge: Failed to Fetch
* Firefox: NetworkError when attempting to fetch resource
* Safari: resource blocked by content blocker
*/
function getNativeFetchImplementation(): FetchImpl {
/* eslint-disable @typescript-eslint/unbound-method */

// Fast path to avoid DOM I/O
const global = getGlobalObject<Window>();
if (isNativeFetch(global.fetch)) {
return global.fetch.bind(global);
}

const document = global.document;
let fetchImpl = global.fetch;
// eslint-disable-next-line deprecation/deprecation
if (typeof document?.createElement === `function`) {
try {
const sandbox = document.createElement('iframe');
sandbox.hidden = true;
document.head.appendChild(sandbox);
if (sandbox.contentWindow?.fetch) {
fetchImpl = sandbox.contentWindow.fetch;
}
document.head.removeChild(sandbox);
} catch (e) {
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
}
}

return fetchImpl.bind(global);
/* eslint-enable @typescript-eslint/unbound-method */
}

/** `fetch` based transport */
export class FetchTransport extends BaseTransport {
/**
* Fetch API reference which always points to native browser implementation.
*/
private _fetch: typeof fetch;

constructor(options: TransportOptions, fetchImpl: FetchImpl = getNativeFetchImplementation()) {
super(options);
this._fetch = fetchImpl;
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -54,8 +132,7 @@ export class FetchTransport extends BaseTransport {

return this._buffer.add(
new SyncPromise<Response>((resolve, reject) => {
global
.fetch(sentryRequest.url, options)
this._fetch(sentryRequest.url, options)
.then(response => {
const headers = {
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
Expand Down
Loading