Skip to content

Commit efd9f73

Browse files
committed
Merge branch 'master' of https://github.com/getsentry/sentry-javascript into onur/node-integration-tests
2 parents dec31e3 + 04e5429 commit efd9f73

File tree

16 files changed

+435
-282
lines changed

16 files changed

+435
-282
lines changed

.size-limit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,10 @@ module.exports = [
5757
gzip: true,
5858
limit: '100 KB',
5959
},
60+
{
61+
name: '@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified)',
62+
path: 'packages/tracing/build/bundle.tracing.es6.min.js',
63+
gzip: true,
64+
limit: '100 KB',
65+
},
6066
];

CHANGELOG.md

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

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

7+
## 6.18.2
8+
9+
If you are using `@sentry-internal/eslint-config-sdk`, please note that this release turns on the [quotes rule](https://eslint.org/docs/rules/quotes) to enforce usage of single quotes.
10+
11+
This release also removes `@sentry/tracing` as a dependency of `@sentry/node`. Please explicitly install and import `@sentry/tracing` if you want to use performance monitoring capabilities. For more details, [see our docs on setting up Node Performance Monitoring](https://docs.sentry.io/platforms/node/performance/).
12+
13+
We also now produce an ES6 version of our [CDN tracing bundle](https://docs.sentry.io/platforms/javascript/install/cdn/#performance-bundle), which can be accessed with `bundle.tracing.es6.min.js`.
14+
15+
- chore(eslint): Turn on quotes rules ([#4671](https://github.com/getsentry/sentry-javascript/pull/4671))
16+
- fix(node): prevent errors thrown on flush from breaking response ([#4667](https://github.com/getsentry/sentry-javascript/pull/4667))
17+
- ref(node): Remove dependency on @sentry/tracing ([#4647](https://github.com/getsentry/sentry-javascript/pull/4647))
18+
- fix(tracing): Make method required in transactionSampling type ([#4657](https://github.com/getsentry/sentry-javascript/pull/4657))
19+
- feat(tracing): Add ES6 tracing bundle ([#4674](https://github.com/getsentry/sentry-javascript/pull/4674))
20+
21+
Work in this release contributed by @Ignigena. Thank you for your contribution!
22+
723
## 6.18.1
824

925
- fix(ember): use _backburner if it exists ([#4603](https://github.com/getsentry/sentry-javascript/pull/4603))

packages/browser/rollup.config.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,17 @@
1-
import { makeBaseBundleConfig, makeLicensePlugin, terserPlugin } from '../../rollup.config';
1+
import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config';
22

33
const builds = [];
44

5-
const licensePlugin = makeLicensePlugin();
6-
75
['es5', 'es6'].forEach(jsVersion => {
86
const baseBundleConfig = makeBaseBundleConfig({
97
input: 'src/index.ts',
108
isAddOn: false,
119
jsVersion,
10+
licenseTitle: '@sentry/browser',
1211
outputFileBase: `build/bundle${jsVersion === 'es6' ? '.es6' : ''}`,
1312
});
1413

15-
builds.push(
16-
...[
17-
{
18-
...baseBundleConfig,
19-
output: {
20-
...baseBundleConfig.output,
21-
file: `${baseBundleConfig.output.file}.js`,
22-
},
23-
plugins: [...baseBundleConfig.plugins, licensePlugin],
24-
},
25-
{
26-
...baseBundleConfig,
27-
output: {
28-
...baseBundleConfig.output,
29-
file: `${baseBundleConfig.output.file}.min.js`,
30-
},
31-
plugins: [...baseBundleConfig.plugins, terserPlugin, licensePlugin],
32-
},
33-
],
34-
);
14+
builds.push(...makeMinificationVariants(baseBundleConfig));
3515
});
3616

3717
export default builds;

packages/browser/src/transports/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export abstract class BaseTransport implements Transport {
226226
}
227227
return true;
228228
} else if (raHeader) {
229-
this._rateLimits.all = new Date(now + parseRetryAfterHeader(now, raHeader));
229+
this._rateLimits.all = new Date(now + parseRetryAfterHeader(raHeader, now));
230230
return true;
231231
}
232232
return false;

packages/integration-tests/utils/generatePlugin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ const BUNDLE_PATHS: Record<string, Record<string, string>> = {
2929
esm: 'esm/index.js',
3030
bundle_es5: 'build/bundle.tracing.js',
3131
bundle_es5_min: 'build/bundle.tracing.min.js',
32-
// `tracing` doesn't have an es6 build yet
33-
bundle_es6: 'build/bundle.tracing.js',
34-
bundle_es6_min: 'build/bundle.tracing.min.js',
32+
bundle_es6: 'build/bundle.tracing.es6.js',
33+
bundle_es6_min: 'build/bundle.tracing.es6.min.js',
3534
},
3635
};
3736

packages/integrations/rollup.config.js

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,25 @@ import * as fs from 'fs';
22

33
import commonjs from '@rollup/plugin-commonjs';
44

5-
import { makeBaseBundleConfig, terserPlugin } from '../../rollup.config';
6-
7-
function allIntegrations() {
8-
return fs.readdirSync('./src').filter(file => file != 'index.ts');
9-
}
10-
11-
function loadAllIntegrations() {
12-
const builds = [];
13-
14-
allIntegrations().forEach(file => {
15-
const baseBundleConfig = makeBaseBundleConfig({
16-
input: `src/${file}`,
17-
isAddOn: true,
18-
jsVersion: 'es5',
19-
outputFileBase: `build/${file.replace('.ts', '')}`,
20-
});
21-
22-
[
23-
{
24-
extension: '.js',
25-
plugins: [...baseBundleConfig.plugins, commonjs()],
26-
},
27-
{
28-
extension: '.min.js',
29-
plugins: [...baseBundleConfig.plugins, commonjs(), terserPlugin],
30-
},
31-
].forEach(build => {
32-
builds.push({
33-
...baseBundleConfig,
34-
output: {
35-
...baseBundleConfig.output,
36-
file: `${baseBundleConfig.output.file}${build.extension}`,
37-
},
38-
plugins: build.plugins,
39-
});
40-
});
5+
import { insertAt, makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config';
6+
7+
const builds = [];
8+
9+
const integrationSourceFiles = fs.readdirSync('./src').filter(file => file != 'index.ts');
10+
11+
integrationSourceFiles.forEach(file => {
12+
const baseBundleConfig = makeBaseBundleConfig({
13+
input: `src/${file}`,
14+
isAddOn: true,
15+
jsVersion: 'es5',
16+
licenseTitle: '@sentry/integrations',
17+
outputFileBase: `build/${file.replace('.ts', '')}`,
4118
});
4219

43-
return builds;
44-
}
20+
// TODO We only need `commonjs` for localforage (used in the offline plugin). Once that's fixed, this can come out.
21+
baseBundleConfig.plugins = insertAt(baseBundleConfig.plugins, -2, commonjs());
22+
23+
builds.push(...makeMinificationVariants(baseBundleConfig));
24+
});
4525

46-
export default loadAllIntegrations();
26+
export default builds;

packages/node/src/transports/base/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export abstract class BaseTransport implements Transport {
181181
}
182182
return true;
183183
} else if (raHeader) {
184-
this._rateLimits.all = new Date(now + parseRetryAfterHeader(now, raHeader));
184+
this._rateLimits.all = new Date(now + parseRetryAfterHeader(raHeader, now));
185185
return true;
186186
}
187187
return false;

packages/tracing/rollup.config.js

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
1-
import { makeBaseBundleConfig, makeLicensePlugin, terserPlugin } from '../../rollup.config';
1+
import { makeBaseBundleConfig, makeMinificationVariants } from '../../rollup.config';
22

3-
const licensePlugin = makeLicensePlugin('@sentry/tracing & @sentry/browser');
3+
const builds = [];
44

5-
const baseBundleConfig = makeBaseBundleConfig({
6-
input: 'src/index.bundle.ts',
7-
isAddOn: false,
8-
jsVersion: 'es5',
9-
outputFileBase: 'build/bundle.tracing',
5+
['es5', 'es6'].forEach(jsVersion => {
6+
const baseBundleConfig = makeBaseBundleConfig({
7+
input: 'src/index.bundle.ts',
8+
isAddOn: false,
9+
jsVersion,
10+
licenseTitle: '@sentry/tracing & @sentry/browser',
11+
outputFileBase: `build/bundle.tracing${jsVersion === 'es6' ? '.es6' : ''}`,
12+
});
13+
14+
builds.push(...makeMinificationVariants(baseBundleConfig));
1015
});
1116

12-
export default [
13-
// ES5 Browser Tracing Bundle
14-
{
15-
...baseBundleConfig,
16-
output: {
17-
...baseBundleConfig.output,
18-
file: `${baseBundleConfig.output.file}.js`,
19-
},
20-
plugins: [...baseBundleConfig.plugins, licensePlugin],
21-
},
22-
{
23-
...baseBundleConfig,
24-
output: {
25-
...baseBundleConfig.output,
26-
file: `${baseBundleConfig.output.file}.min.js`,
27-
},
28-
plugins: [...baseBundleConfig.plugins, terserPlugin, licensePlugin],
29-
},
30-
];
17+
export default builds;

packages/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ export * from './tracing';
2424
export * from './env';
2525
export * from './envelope';
2626
export * from './clientreport';
27+
export * from './ratelimit';

packages/utils/src/misc.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -188,31 +188,6 @@ export function parseSemver(input: string): SemVer {
188188
};
189189
}
190190

191-
const defaultRetryAfter = 60 * 1000; // 60 seconds
192-
193-
/**
194-
* Extracts Retry-After value from the request header or returns default value
195-
* @param now current unix timestamp
196-
* @param header string representation of 'Retry-After' header
197-
*/
198-
export function parseRetryAfterHeader(now: number, header?: string | number | null): number {
199-
if (!header) {
200-
return defaultRetryAfter;
201-
}
202-
203-
const headerDelay = parseInt(`${header}`, 10);
204-
if (!isNaN(headerDelay)) {
205-
return headerDelay * 1000;
206-
}
207-
208-
const headerDate = Date.parse(`${header}`);
209-
if (!isNaN(headerDate)) {
210-
return headerDate - now;
211-
}
212-
213-
return defaultRetryAfter;
214-
}
215-
216191
/**
217192
* This function adds context (pre/post/line) lines to the provided frame
218193
*

packages/utils/src/ratelimit.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Keeping the key broad until we add the new transports
2+
export type RateLimits = Record<string, number>;
3+
4+
export const DEFAULT_RETRY_AFTER = 60 * 1000; // 60 seconds
5+
6+
/**
7+
* Extracts Retry-After value from the request header or returns default value
8+
* @param header string representation of 'Retry-After' header
9+
* @param now current unix timestamp
10+
*
11+
*/
12+
export function parseRetryAfterHeader(header: string, now: number = Date.now()): number {
13+
const headerDelay = parseInt(`${header}`, 10);
14+
if (!isNaN(headerDelay)) {
15+
return headerDelay * 1000;
16+
}
17+
18+
const headerDate = Date.parse(`${header}`);
19+
if (!isNaN(headerDate)) {
20+
return headerDate - now;
21+
}
22+
23+
return DEFAULT_RETRY_AFTER;
24+
}
25+
26+
/**
27+
* Gets the time that given category is disabled until for rate limiting
28+
*/
29+
export function disabledUntil(limits: RateLimits, category: string): number {
30+
return limits[category] || limits.all || 0;
31+
}
32+
33+
/**
34+
* Checks if a category is rate limited
35+
*/
36+
export function isRateLimited(limits: RateLimits, category: string, now: number = Date.now()): boolean {
37+
return disabledUntil(limits, category) > now;
38+
}
39+
40+
/**
41+
* Update ratelimits from incoming headers.
42+
* Returns true if headers contains a non-empty rate limiting header.
43+
*/
44+
export function updateRateLimits(
45+
limits: RateLimits,
46+
headers: Record<string, string | null | undefined>,
47+
now: number = Date.now(),
48+
): RateLimits {
49+
const updatedRateLimits: RateLimits = {
50+
...limits,
51+
};
52+
53+
// "The name is case-insensitive."
54+
// https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
55+
const rateLimitHeader = headers['x-sentry-rate-limits'];
56+
const retryAfterHeader = headers['retry-after'];
57+
58+
if (rateLimitHeader) {
59+
/**
60+
* rate limit headers are of the form
61+
* <header>,<header>,..
62+
* where each <header> is of the form
63+
* <retry_after>: <categories>: <scope>: <reason_code>
64+
* where
65+
* <retry_after> is a delay in seconds
66+
* <categories> is the event type(s) (error, transaction, etc) being rate limited and is of the form
67+
* <category>;<category>;...
68+
* <scope> is what's being limited (org, project, or key) - ignored by SDK
69+
* <reason_code> is an arbitrary string like "org_quota" - ignored by SDK
70+
*/
71+
for (const limit of rateLimitHeader.trim().split(',')) {
72+
const parameters = limit.split(':', 2);
73+
const headerDelay = parseInt(parameters[0], 10);
74+
const delay = (!isNaN(headerDelay) ? headerDelay : 60) * 1000; // 60sec default
75+
if (!parameters[1]) {
76+
updatedRateLimits.all = now + delay;
77+
} else {
78+
for (const category of parameters[1].split(';')) {
79+
updatedRateLimits[category] = now + delay;
80+
}
81+
}
82+
}
83+
} else if (retryAfterHeader) {
84+
updatedRateLimits.all = now + parseRetryAfterHeader(retryAfterHeader, now);
85+
}
86+
87+
return updatedRateLimits;
88+
}

packages/utils/test/misc.test.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
addExceptionMechanism,
66
checkOrSetAlreadyCaught,
77
getEventDescription,
8-
parseRetryAfterHeader,
98
stripUrlQueryAndFragment,
109
} from '../src/misc';
1110

@@ -118,26 +117,6 @@ describe('getEventDescription()', () => {
118117
});
119118
});
120119

121-
describe('parseRetryAfterHeader', () => {
122-
test('no header', () => {
123-
expect(parseRetryAfterHeader(Date.now())).toEqual(60 * 1000);
124-
});
125-
126-
test('incorrect header', () => {
127-
expect(parseRetryAfterHeader(Date.now(), 'x')).toEqual(60 * 1000);
128-
});
129-
130-
test('delay header', () => {
131-
expect(parseRetryAfterHeader(Date.now(), '1337')).toEqual(1337 * 1000);
132-
});
133-
134-
test('date header', () => {
135-
expect(
136-
parseRetryAfterHeader(new Date('Wed, 21 Oct 2015 07:28:00 GMT').getTime(), 'Wed, 21 Oct 2015 07:28:13 GMT'),
137-
).toEqual(13 * 1000);
138-
});
139-
});
140-
141120
describe('addContextToFrame', () => {
142121
const lines = [
143122
'1: a',

0 commit comments

Comments
 (0)