Skip to content

Commit 23e1f90

Browse files
committed
Merge remote-tracking branch 'upstream/7.x' into feat/attachments
2 parents 1398bfc + 1130c1c commit 23e1f90

File tree

32 files changed

+698
-195
lines changed

32 files changed

+698
-195
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -105,45 +105,6 @@ jobs:
105105
# `job_build` can't see `job_install_deps` and what it returned)
106106
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
107107

108-
# This isn't a full `yarn build` using sucrase - it's just the cache from the normal build, with `build/cjs` and
109-
# `build/esm` overwritten by sucrase. This way we don't need to worry about all of the other random stuff which
110-
# packages build, because it will already be there.
111-
job_build_with_sucrase:
112-
name: Sucrase Build
113-
needs: [job_install_deps, job_build]
114-
runs-on: ubuntu-latest
115-
timeout-minutes: 20
116-
steps:
117-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
118-
uses: actions/checkout@v2
119-
with:
120-
ref: ${{ env.HEAD_COMMIT }}
121-
- name: Set up Node
122-
uses: actions/setup-node@v1
123-
- name: Check dependency cache
124-
uses: actions/cache@v2
125-
with:
126-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
127-
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
128-
- name: Check tsc build cache
129-
uses: actions/cache@v2
130-
with:
131-
path: ${{ env.CACHED_BUILD_PATHS }}
132-
key: ${{ env.BUILD_CACHE_KEY }}
133-
- name: Check sucrase build cache
134-
uses: actions/cache@v2
135-
id: cache_built_sucrase_packages
136-
with:
137-
path: ${{ env.CACHED_BUILD_PATHS }}
138-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
139-
- name: Build packages with sucrase
140-
if: steps.cache_built_sucrase_packages.outputs.cache-hit == ''
141-
run: 'yarn build:rollup'
142-
outputs:
143-
# this needs to be passed on, because the `needs` context only looks at direct ancestors (so steps which depend on
144-
# `job_build` can't see `job_install_deps` and what it returned)
145-
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
146-
147108
job_size_check:
148109
name: Size Check
149110
needs: job_build
@@ -295,6 +256,8 @@ jobs:
295256
NODE_VERSION: ${{ matrix.node }}
296257
run: |
297258
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check [email protected]
259+
# TODO remove this when we switch to sucrase
260+
yarn ts-node scripts/sucrase-test-hack.ts
298261
yarn test-ci
299262
- name: Compute test coverage
300263
uses: codecov/codecov-action@v1
@@ -534,7 +497,7 @@ jobs:
534497
535498
job_unit_test_sucrase:
536499
name: Sucrase Test (Node ${{ matrix.node }})
537-
needs: job_build_with_sucrase
500+
needs: job_build
538501
continue-on-error: true
539502
timeout-minutes: 30
540503
runs-on: ubuntu-latest
@@ -554,24 +517,26 @@ jobs:
554517
uses: actions/cache@v2
555518
with:
556519
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
557-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
520+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
558521
- name: Check build cache
559522
uses: actions/cache@v2
560523
with:
561524
path: ${{ env.CACHED_BUILD_PATHS }}
562-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
525+
key: ${{ env.BUILD_CACHE_KEY }}
563526
- name: Run tests
564527
env:
565528
NODE_VERSION: ${{ matrix.node }}
529+
SUCRASE: true
566530
run: |
567-
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check [email protected]
531+
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check [email protected] [email protected] @rollup/[email protected] [email protected] [email protected]
532+
yarn ts-node scripts/sucrase-test-hack.ts
568533
yarn test-ci
569534
- name: Compute test coverage
570535
uses: codecov/codecov-action@v1
571536

572537
job_nextjs_integration_test_sucrase:
573538
name: Sucrase Test @sentry/nextjs on (Node ${{ matrix.node }})
574-
needs: job_build_with_sucrase
539+
needs: job_build
575540
continue-on-error: true
576541
timeout-minutes: 30
577542
runs-on: ubuntu-latest
@@ -591,24 +556,25 @@ jobs:
591556
uses: actions/cache@v2
592557
with:
593558
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
594-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
559+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
595560
- name: Check build cache
596561
uses: actions/cache@v2
597562
with:
598563
path: ${{ env.CACHED_BUILD_PATHS }}
599-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
564+
key: ${{ env.BUILD_CACHE_KEY }}
600565
- name: Run tests
601566
env:
602567
NODE_VERSION: ${{ matrix.node }}
603568
run: |
569+
yarn ts-node scripts/sucrase-test-hack.ts
604570
cd packages/nextjs
605571
yarn test:integration
606572
607573
# Ember tests are separate from the rest because they are the slowest part of the test suite, and making them a
608574
# separate job allows them to run in parallel with the other tests.
609575
job_ember_tests_sucrase:
610576
name: Sucrase Test @sentry/ember
611-
needs: job_build_with_sucrase
577+
needs: job_build
612578
continue-on-error: true
613579
timeout-minutes: 30
614580
runs-on: ubuntu-latest
@@ -634,20 +600,22 @@ jobs:
634600
uses: actions/cache@v2
635601
with:
636602
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
637-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
603+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
638604
- name: Check build cache
639605
uses: actions/cache@v2
640606
with:
641607
path: ${{ env.CACHED_BUILD_PATHS }}
642-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
608+
key: ${{ env.BUILD_CACHE_KEY }}
643609
- name: Run Ember tests
644-
run: yarn test --scope=@sentry/ember
610+
run: |
611+
yarn ts-node scripts/sucrase-test-hack.ts
612+
yarn test --scope=@sentry/ember
645613
- name: Compute test coverage
646614
uses: codecov/codecov-action@v1
647615

648616
job_browser_playwright_tests_sucrase:
649617
name: Sucrase Playwright - ${{ (matrix.tracing_only && 'Browser + Tracing') || 'Browser' }} (${{ matrix.bundle }})
650-
needs: job_build_with_sucrase
618+
needs: job_build
651619
runs-on: ubuntu-latest
652620
strategy:
653621
matrix:
@@ -677,24 +645,25 @@ jobs:
677645
uses: actions/cache@v2
678646
with:
679647
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
680-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
648+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
681649
- name: Check build cache
682650
uses: actions/cache@v2
683651
with:
684652
path: ${{ env.CACHED_BUILD_PATHS }}
685-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
653+
key: ${{ env.BUILD_CACHE_KEY }}
686654
- name: Run Playwright tests
687655
env:
688656
PW_BUNDLE: ${{ matrix.bundle }}
689657
PW_TRACING_ONLY: ${{ matrix.tracing_only }}
690658
run: |
659+
yarn ts-node scripts/sucrase-test-hack.ts
691660
cd packages/integration-tests
692661
yarn run playwright install-deps webkit
693662
yarn test:ci
694663
695664
job_browser_integration_tests_sucrase:
696665
name: Sucrase Old Browser Integration Tests (${{ matrix.browser }})
697-
needs: job_build_with_sucrase
666+
needs: job_build
698667
runs-on: ubuntu-latest
699668
timeout-minutes: 10
700669
continue-on-error: true
@@ -715,23 +684,24 @@ jobs:
715684
uses: actions/cache@v2
716685
with:
717686
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
718-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
687+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
719688
- name: Check build cache
720689
uses: actions/cache@v2
721690
with:
722691
path: ${{ env.CACHED_BUILD_PATHS }}
723-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
692+
key: ${{ env.BUILD_CACHE_KEY }}
724693
- name: Run integration tests
725694
env:
726695
KARMA_BROWSER: ${{ matrix.browser }}
727696
run: |
697+
yarn ts-node scripts/sucrase-test-hack.ts
728698
cd packages/browser
729699
[[ $KARMA_BROWSER == WebkitHeadless ]] && yarn run playwright install-deps webkit
730700
yarn test:integration
731701
732702
job_browser_build_tests_sucrase:
733703
name: Sucrase Browser Build Tests
734-
needs: job_build_with_sucrase
704+
needs: job_build
735705
runs-on: ubuntu-latest
736706
timeout-minutes: 5
737707
continue-on-error: true
@@ -748,14 +718,15 @@ jobs:
748718
uses: actions/cache@v2
749719
with:
750720
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
751-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
721+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
752722
- name: Check build cache
753723
uses: actions/cache@v2
754724
with:
755725
path: ${{ env.CACHED_BUILD_PATHS }}
756-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
726+
key: ${{ env.BUILD_CACHE_KEY }}
757727
- name: Run browser build tests
758728
run: |
729+
yarn ts-node scripts/sucrase-test-hack.ts
759730
cd packages/browser
760731
yarn test:package
761732
- name: Run utils build tests
@@ -765,7 +736,7 @@ jobs:
765736
766737
job_node_integration_tests_sucrase:
767738
name: Sucrase Node SDK Integration Tests (${{ matrix.node }})
768-
needs: job_build_with_sucrase
739+
needs: job_build
769740
runs-on: ubuntu-latest
770741
timeout-minutes: 10
771742
continue-on-error: true
@@ -785,15 +756,16 @@ jobs:
785756
uses: actions/cache@v2
786757
with:
787758
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
788-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
759+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
789760
- name: Check build cache
790761
uses: actions/cache@v2
791762
with:
792763
path: ${{ env.CACHED_BUILD_PATHS }}
793-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
764+
key: ${{ env.BUILD_CACHE_KEY }}
794765
- name: Run integration tests
795766
env:
796767
NODE_VERSION: ${{ matrix.node }}
797768
run: |
769+
yarn ts-node scripts/sucrase-test-hack.ts
798770
cd packages/node-integration-tests
799771
yarn test

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"rimraf": "^3.0.2",
8686
"rollup": "^2.67.1",
8787
"rollup-plugin-license": "^2.6.1",
88+
"rollup-plugin-re": "^1.0.7",
8889
"rollup-plugin-terser": "^7.0.2",
8990
"rollup-plugin-typescript2": "^0.31.2",
9091
"sinon": "^7.3.2",

packages/browser/src/client.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
1+
import { BaseClient, getEnvelopeEndpointWithUrlEncodedAuth, Scope, SDK_VERSION } from '@sentry/core';
22
import { AttachmentItem, ClientOptions, Event, EventHint, Options, Severity, SeverityLevel } from '@sentry/types';
3+
import { createClientReportEnvelope, dsnToString, getGlobalObject, logger, serializeEnvelope } from '@sentry/utils';
34

45
import { eventFromException, eventFromMessage } from './eventbuilder';
6+
import { IS_DEBUG_BUILD } from './flags';
57
import { Breadcrumbs } from './integrations';
8+
import { sendReport } from './transports/utils';
9+
10+
const globalObject = getGlobalObject<Window>();
611

712
export interface BaseBrowserOptions {
813
/**
@@ -56,7 +61,16 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
5661
],
5762
version: SDK_VERSION,
5863
};
64+
5965
super(options);
66+
67+
if (options.sendClientReports && globalObject.document) {
68+
globalObject.document.addEventListener('visibilitychange', () => {
69+
if (globalObject.document.visibilityState === 'hidden') {
70+
this._flushOutcomes();
71+
}
72+
});
73+
}
6074
}
6175

6276
/**
@@ -96,4 +110,32 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
96110
}
97111
super._sendEvent(event, attachments);
98112
}
113+
114+
/**
115+
* Sends client reports as an envelope.
116+
*/
117+
private _flushOutcomes(): void {
118+
const outcomes = this._clearOutcomes();
119+
120+
if (outcomes.length === 0) {
121+
IS_DEBUG_BUILD && logger.log('No outcomes to send');
122+
return;
123+
}
124+
125+
if (!this._dsn) {
126+
IS_DEBUG_BUILD && logger.log('No dsn provided, will not send outcomes');
127+
return;
128+
}
129+
130+
IS_DEBUG_BUILD && logger.log('Sending outcomes:', outcomes);
131+
132+
const url = getEnvelopeEndpointWithUrlEncodedAuth(this._dsn, this._options.tunnel);
133+
const envelope = createClientReportEnvelope(outcomes, this._options.tunnel && dsnToString(this._dsn));
134+
135+
try {
136+
sendReport(url, serializeEnvelope(envelope));
137+
} catch (e) {
138+
IS_DEBUG_BUILD && logger.error(e);
139+
}
140+
}
99141
}

packages/browser/src/transports/utils.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,15 @@ export function getNativeFetchImplementation(): FetchImpl {
8686
* @param url report endpoint
8787
* @param body report payload
8888
*/
89-
export function sendReport(url: string, body: string): void {
89+
export function sendReport(url: string, body: string | Uint8Array): void {
9090
const isRealNavigator = Object.prototype.toString.call(global && global.navigator) === '[object Navigator]';
9191
const hasSendBeacon = isRealNavigator && typeof global.navigator.sendBeacon === 'function';
9292

9393
if (hasSendBeacon) {
9494
// Prevent illegal invocations - https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
9595
const sendBeacon = global.navigator.sendBeacon.bind(global.navigator);
96-
return sendBeacon(url, body);
97-
}
98-
99-
if (supportsFetch()) {
96+
sendBeacon(url, body);
97+
} else if (supportsFetch()) {
10098
const fetch = getNativeFetchImplementation();
10199
fetch(url, {
102100
body,

0 commit comments

Comments
 (0)