Skip to content

Commit 48c430f

Browse files
committed
Merge branch 'master' into abhi-reset-idletimeout
2 parents 6e35f2e + dee05a6 commit 48c430f

File tree

14 files changed

+249
-184
lines changed

14 files changed

+249
-184
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,39 @@ jobs:
203203
- name: Compute test coverage
204204
uses: codecov/codecov-action@v1
205205

206+
job_nextjs_integration_test:
207+
name: Test @sentry/nextjs on (Node ${{ matrix.node }})
208+
needs: job_build
209+
continue-on-error: true
210+
timeout-minutes: 30
211+
runs-on: ubuntu-latest
212+
strategy:
213+
matrix:
214+
node: [10, 12, 14, 16]
215+
steps:
216+
- name: Check out current commit (${{ github.sha }})
217+
uses: actions/checkout@v2
218+
- name: Set up Node
219+
uses: actions/setup-node@v1
220+
with:
221+
node-version: ${{ matrix.node }}
222+
- name: Check dependency cache
223+
uses: actions/cache@v2
224+
with:
225+
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
226+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
227+
- name: Check build cache
228+
uses: actions/cache@v2
229+
with:
230+
path: ${{ env.CACHED_BUILD_PATHS }}
231+
key: ${{ env.BUILD_CACHE_KEY }}
232+
- name: Run tests
233+
env:
234+
NODE_VERSION: ${{ matrix.node }}
235+
run: |
236+
cd packages/nextjs
237+
yarn test:integration
238+
206239
# Ember tests are separate from the rest because they are the slowest part of the test suite, and making them a
207240
# separate job allows them to run in parallel with the other tests.
208241
job_ember_tests:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"@types/sinon": "^7.0.11",
6464
"chai": "^4.1.2",
6565
"codecov": "^3.6.5",
66+
"deepmerge": "^4.2.2",
6667
"eslint": "7.32.0",
6768
"jest": "^24.9.0",
6869
"karma-browserstack-launcher": "^1.5.1",

packages/browser/test/unit/jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module.exports = {
22
transform: {
33
'^.+\\.ts$': 'ts-jest',
44
},
5+
collectCoverage: true,
6+
coverageDirectory: '../../coverage',
57
moduleFileExtensions: ['js', 'ts'],
68
testEnvironment: 'jsdom',
79
testMatch: ['**/*.test.ts'],

packages/integrations/rollup.config.js

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,45 @@
11
import * as fs from 'fs';
22

3-
import { terser } from 'rollup-plugin-terser';
43
import commonjs from '@rollup/plugin-commonjs';
54

6-
import {
7-
addOnBundleConfig,
8-
baseBundleConfig,
9-
markAsBrowserBuild,
10-
nodeResolvePlugin,
11-
typescriptPluginES5,
12-
} from '../../rollup.config';
13-
14-
const terserInstance = terser({
15-
mangle: {
16-
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
17-
// as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version.
18-
// We need those full names to correctly detect our internal frames for stripping.
19-
// I listed all of them here just for the clarity sake, as they are all used in the frames manipulation process.
20-
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
21-
properties: false,
22-
},
23-
output: {
24-
comments: false,
25-
},
26-
});
27-
28-
const plugins = [
29-
typescriptPluginES5,
30-
// replace `__SENTRY_BROWSER_BUNDLE__` with `true` to enable treeshaking of non-browser code
31-
markAsBrowserBuild,
32-
nodeResolvePlugin,
33-
commonjs(),
34-
];
5+
import { makeBaseBundleConfig, terserPlugin } from '../../rollup.config';
356

367
function allIntegrations() {
378
return fs.readdirSync('./src').filter(file => file != 'index.ts');
389
}
3910

4011
function loadAllIntegrations() {
4112
const builds = [];
42-
[
43-
{
44-
extension: '.js',
45-
plugins,
46-
},
47-
{
48-
extension: '.min.js',
49-
plugins: [...plugins, terserInstance],
50-
},
51-
].forEach(build => {
52-
builds.push(
53-
...allIntegrations().map(file => ({
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({
5433
...baseBundleConfig,
55-
input: `src/${file}`,
5634
output: {
5735
...baseBundleConfig.output,
58-
...addOnBundleConfig.output,
59-
file: `build/${file.replace('.ts', build.extension)}`,
36+
file: `${baseBundleConfig.output.file}${build.extension}`,
6037
},
6138
plugins: build.plugins,
62-
})),
63-
);
39+
});
40+
});
6441
});
42+
6543
return builds;
6644
}
6745

packages/nextjs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
6464
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
6565
"pack": "npm pack",
66-
"test": "run-s test:unit test:integration",
66+
"test": "run-s test:unit",
67+
"test:all": "run-s test:unit test:integration",
6768
"test:unit": "jest",
6869
"test:integration": "test/run-integration-tests.sh",
6970
"test:watch": "jest --watch",

packages/node/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"dependencies": {
1919
"@sentry/core": "6.18.1",
2020
"@sentry/hub": "6.18.1",
21-
"@sentry/tracing": "6.18.1",
2221
"@sentry/types": "6.18.1",
2322
"@sentry/utils": "6.18.1",
2423
"cookie": "^0.4.1",

packages/node/src/handlers.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
/* eslint-disable max-lines */
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33
import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core';
4-
import { extractTraceparentData, Span } from '@sentry/tracing';
5-
import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types';
6-
import { isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils';
4+
import { Event, ExtractedNodeRequestData, Span, Transaction } from '@sentry/types';
5+
import {
6+
extractTraceparentData,
7+
isPlainObject,
8+
isString,
9+
logger,
10+
normalize,
11+
stripUrlQueryAndFragment,
12+
} from '@sentry/utils';
713
import * as cookie from 'cookie';
814
import * as domain from 'domain';
915
import * as http from 'http';

packages/tracing/rollup.config.js

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,30 @@
1-
import {
2-
baseBundleConfig,
3-
makeLicensePlugin,
4-
markAsBrowserBuild,
5-
nodeResolvePlugin,
6-
terserPlugin,
7-
typescriptPluginES5,
8-
} from '../../rollup.config';
1+
import { makeBaseBundleConfig, makeLicensePlugin, terserPlugin } from '../../rollup.config';
92

103
const licensePlugin = makeLicensePlugin('@sentry/tracing & @sentry/browser');
114

12-
const plugins = [
13-
typescriptPluginES5,
14-
// replace `__SENTRY_BROWSER_BUNDLE__` with `true` to enable treeshaking of non-browser code
15-
markAsBrowserBuild,
16-
nodeResolvePlugin,
17-
licensePlugin,
18-
];
19-
20-
const bundleConfig = {
21-
...baseBundleConfig,
22-
input: 'src/index.ts',
23-
output: {
24-
...baseBundleConfig.output,
25-
format: 'iife',
26-
name: 'Sentry',
27-
},
28-
context: 'window',
29-
plugins,
30-
};
5+
const baseBundleConfig = makeBaseBundleConfig({
6+
input: 'src/index.bundle.ts',
7+
isAddOn: false,
8+
jsVersion: 'es5',
9+
outputFileBase: 'build/bundle.tracing',
10+
});
3111

3212
export default [
3313
// ES5 Browser Tracing Bundle
3414
{
35-
...bundleConfig,
36-
input: 'src/index.bundle.ts',
15+
...baseBundleConfig,
3716
output: {
38-
...bundleConfig.output,
39-
file: 'build/bundle.tracing.js',
17+
...baseBundleConfig.output,
18+
file: `${baseBundleConfig.output.file}.js`,
4019
},
41-
plugins: bundleConfig.plugins,
20+
plugins: [...baseBundleConfig.plugins, licensePlugin],
4221
},
4322
{
44-
...bundleConfig,
45-
input: 'src/index.bundle.ts',
23+
...baseBundleConfig,
4624
output: {
47-
...bundleConfig.output,
48-
file: 'build/bundle.tracing.min.js',
25+
...baseBundleConfig.output,
26+
file: `${baseBundleConfig.output.file}.min.js`,
4927
},
50-
// Uglify has to be at the end of compilation, BUT before the license banner
51-
plugins: bundleConfig.plugins.slice(0, -1).concat(terserPlugin).concat(bundleConfig.plugins.slice(-1)),
28+
plugins: [...baseBundleConfig.plugins, terserPlugin, licensePlugin],
5229
},
5330
];

packages/tracing/src/utils.ts

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { getCurrentHub, Hub } from '@sentry/hub';
2-
import { Options, TraceparentData, Transaction } from '@sentry/types';
2+
import { Options, Transaction } from '@sentry/types';
33

4-
export const TRACEPARENT_REGEXP = new RegExp(
5-
'^[ \\t]*' + // whitespace
6-
'([0-9a-f]{32})?' + // trace_id
7-
'-?([0-9a-f]{16})?' + // span_id
8-
'-?([01])?' + // sampled
9-
'[ \\t]*$', // whitespace
10-
);
4+
/**
5+
* The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used
6+
* to be declared in this file. It was later moved into `@sentry/utils` as part of a
7+
* move to remove `@sentry/tracing` dependencies from `@sentry/node` (`extractTraceparentData`
8+
* is the only tracing function used by `@sentry/node`).
9+
*
10+
* These exports are kept here for backwards compatability's sake.
11+
*
12+
* TODO(v7): Reorganize these exports
13+
*
14+
* See https://github.com/getsentry/sentry-javascript/issues/4642 for more details.
15+
*/
16+
export { TRACEPARENT_REGEXP, extractTraceparentData } from '@sentry/utils';
1117

1218
/**
1319
* Determines if tracing is currently enabled.
@@ -20,31 +26,6 @@ export function hasTracingEnabled(maybeOptions?: Options | undefined): boolean {
2026
return !!options && ('tracesSampleRate' in options || 'tracesSampler' in options);
2127
}
2228

23-
/**
24-
* Extract transaction context data from a `sentry-trace` header.
25-
*
26-
* @param traceparent Traceparent string
27-
*
28-
* @returns Object containing data from the header, or undefined if traceparent string is malformed
29-
*/
30-
export function extractTraceparentData(traceparent: string): TraceparentData | undefined {
31-
const matches = traceparent.match(TRACEPARENT_REGEXP);
32-
if (matches) {
33-
let parentSampled: boolean | undefined;
34-
if (matches[3] === '1') {
35-
parentSampled = true;
36-
} else if (matches[3] === '0') {
37-
parentSampled = false;
38-
}
39-
return {
40-
traceId: matches[1],
41-
parentSampled,
42-
parentSpanId: matches[2],
43-
};
44-
}
45-
return undefined;
46-
}
47-
4829
/** Grabs active transaction off scope, if any */
4930
export function getActiveTransaction<T extends Transaction>(maybeHub?: Hub): T | undefined {
5031
const hub = maybeHub || getCurrentHub();

packages/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export * from './string';
2020
export * from './supports';
2121
export * from './syncpromise';
2222
export * from './time';
23+
export * from './tracing';
2324
export * from './env';
2425
export * from './envelope';
2526
export * from './clientreport';

packages/utils/src/tracing.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { TraceparentData } from '@sentry/types';
2+
3+
export const TRACEPARENT_REGEXP = new RegExp(
4+
'^[ \\t]*' + // whitespace
5+
'([0-9a-f]{32})?' + // trace_id
6+
'-?([0-9a-f]{16})?' + // span_id
7+
'-?([01])?' + // sampled
8+
'[ \\t]*$', // whitespace
9+
);
10+
11+
/**
12+
* Extract transaction context data from a `sentry-trace` header.
13+
*
14+
* @param traceparent Traceparent string
15+
*
16+
* @returns Object containing data from the header, or undefined if traceparent string is malformed
17+
*/
18+
export function extractTraceparentData(traceparent: string): TraceparentData | undefined {
19+
const matches = traceparent.match(TRACEPARENT_REGEXP);
20+
if (matches) {
21+
let parentSampled: boolean | undefined;
22+
if (matches[3] === '1') {
23+
parentSampled = true;
24+
} else if (matches[3] === '0') {
25+
parentSampled = false;
26+
}
27+
return {
28+
traceId: matches[1],
29+
parentSampled,
30+
parentSpanId: matches[2],
31+
};
32+
}
33+
return undefined;
34+
}

0 commit comments

Comments
 (0)