Skip to content
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

fix(spotlight): Stop tracing Sidecar network request in JS #3559

Merged
merged 23 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fa2b6e9
feat(integrations): Add Spotlight integration with auto dev server ho…
krystofwoldrich Jan 25, 2024
cbe8171
fix envelope overwrite
krystofwoldrich Jan 25, 2024
8a02b59
add new connection error message
krystofwoldrich Jan 25, 2024
6c231e6
fix(debugsymbolicator): Don't trace debug symbolicator source context…
krystofwoldrich Jan 25, 2024
93f0257
add changelog
krystofwoldrich Jan 25, 2024
5429005
fix lint and add tests
krystofwoldrich Jan 25, 2024
da8c265
add spotlight changelog
krystofwoldrich Jan 26, 2024
955b399
Update CHANGELOG.md
krystofwoldrich Jan 26, 2024
4424579
add tests and easy to setup options
krystofwoldrich Jan 27, 2024
38adefe
Merge remote-tracking branch 'origin/kw-add-spotlight' into kw-add-sp…
krystofwoldrich Jan 27, 2024
0c2640c
Merge remote-tracking branch 'origin/main' into kw-add-spotlight
krystofwoldrich Jan 27, 2024
3c47915
Merge branch 'kw-add-spotlight' into kw-fix-debug-symbolicator-source…
krystofwoldrich Jan 27, 2024
7afb1da
fix(spotlight): Stop tracing Sidecar network request in JS
krystofwoldrich Jan 27, 2024
6c7a7bd
Use __sentry_original__ to create stealth xhr
krystofwoldrich Jan 29, 2024
74d2f4e
Merge branch 'kw-fix-debug-symbolicator-source-context' into kw-remov…
krystofwoldrich Jan 29, 2024
bd3de2f
Merge remote-tracking branch 'origin/main' into kw-fix-debug-symbolic…
krystofwoldrich Jan 29, 2024
2d320ff
Merge branch 'kw-fix-debug-symbolicator-source-context' into kw-remov…
krystofwoldrich Jan 29, 2024
798e640
fix test
krystofwoldrich Jan 29, 2024
095bed0
if xhr not available return null
krystofwoldrich Jan 31, 2024
0587152
Merge remote-tracking branch 'origin/main' into kw-fix-debug-symbolic…
krystofwoldrich Jan 31, 2024
b4de105
Merge branch 'kw-fix-debug-symbolicator-source-context' into kw-remov…
krystofwoldrich Jan 31, 2024
7a1eca2
fix nullable xhr
krystofwoldrich Jan 31, 2024
7472781
Merge remote-tracking branch 'origin/main' into kw-remove-spotlight-n…
krystofwoldrich Jan 31, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Prevent pod install crash when visionos is not present ([#3548](https://github.com/getsentry/sentry-react-native/pull/3548))
- Fetch Organization slug from `@sentry/react-native/expo` config when uploading artifacts ([#3557](https://github.com/getsentry/sentry-react-native/pull/3557))
- Remove 404 Http Client Errors reports for Metro Dev Server Requests ([#3553](https://github.com/getsentry/sentry-react-native/pull/3553))
- Stop tracing Spotlight Sidecar network request in JS ([#3559](https://github.com/getsentry/sentry-react-native/pull/3559))

## 5.17.0

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
collectCoverage: true,
preset: 'react-native',
setupFilesAfterEnv: ['jest-extended/all', '<rootDir>/test/mockConsole.ts', '<rootDir>/test/mockFetch.ts'],
setupFilesAfterEnv: ['jest-extended/all', '<rootDir>/test/mockConsole.ts'],
globals: {
__DEV__: true,
'ts-jest': {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"devDependencies": {
"@babel/core": "^7.23.5",
"@expo/metro-config": "0.16.0",
"@mswjs/interceptors": "^0.25.15",
"@sentry-internal/eslint-config-sdk": "7.81.1",
"@sentry-internal/eslint-plugin-sdk": "7.81.1",
"@sentry-internal/typescript": "7.80.0",
Expand All @@ -87,6 +88,7 @@
"@types/react": "^18.2.14",
"@types/uglify-js": "^3.17.2",
"@types/uuid": "^9.0.4",
"@types/xmlhttprequest": "^1.8.2",
"babel-jest": "^29.6.2",
"downlevel-dts": "^0.11.0",
"eslint": "^7.6.0",
Expand All @@ -96,7 +98,6 @@
"expo-module-scripts": "^3.1.0",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"jest-fetch-mock": "^3.0.3",
"jest-extended": "^4.0.2",
"madge": "^6.1.0",
"metro": "0.76",
Expand All @@ -108,7 +109,8 @@
"ts-jest": "^29.1.1",
"typescript": "4.9.5",
"uglify-js": "^3.17.4",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"xmlhttprequest": "^1.8.0"
},
"rnpm": {
"commands": {},
Expand Down
39 changes: 26 additions & 13 deletions src/js/integrations/spotlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logger, serializeEnvelope } from '@sentry/utils';

import { makeUtf8TextEncoder } from '../transports/TextEncoder';
import { ReactNativeLibraries } from '../utils/rnlibraries';
import { createStealthXhr, XHR_READYSTATE_DONE } from '../utils/xhr';

type SpotlightReactNativeIntegrationOptions = {
/**
Expand Down Expand Up @@ -56,19 +57,31 @@ function sendEnvelopesToSidecar(client: Client, sidecarUrl: string): void {

spotlightEnvelope[1] = envelopeItems as Envelope[1];

fetch(sidecarUrl, {
method: 'POST',
body: serializeEnvelope(spotlightEnvelope, makeUtf8TextEncoder()),
headers: {
'Content-Type': 'application/x-sentry-envelope',
},
mode: 'cors',
}).catch(err => {
logger.error(
"[Spotlight] Sentry SDK can't connect to Spotlight is it running? See https://spotlightjs.com to download it.",
err,
);
});
const xhr = createStealthXhr();
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
if (!xhr) {
logger.error('[Spotlight] Sentry SDK can not create XHR object');
return;
}

xhr.open('POST', sidecarUrl, true);
xhr.setRequestHeader('Content-Type', 'application/x-sentry-envelope');

xhr.onreadystatechange = function () {
if (xhr.readyState === XHR_READYSTATE_DONE) {
const status = xhr.status;
if (status === 0 || (status >= 200 && status < 400)) {
// The request has been completed successfully
} else {
// Handle the error
logger.error(
"[Spotlight] Sentry SDK can't connect to Spotlight is it running? See https://spotlightjs.com to download it.",
new Error(xhr.statusText),
);
}
}
};

xhr.send(serializeEnvelope(spotlightEnvelope, makeUtf8TextEncoder()));
});
}

Expand Down
23 changes: 19 additions & 4 deletions test/integrations/spotlight.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import type { HttpRequestEventMap } from '@mswjs/interceptors';
import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest';
import type { Envelope, Hub } from '@sentry/types';
import fetchMock from 'jest-fetch-mock';
import { XMLHttpRequest } from 'xmlhttprequest';

import { Spotlight } from '../../src/js/integrations/spotlight';

globalThis.XMLHttpRequest = XMLHttpRequest;
const requestListener = jest.fn<void, HttpRequestEventMap['request']>();
const interceptor = new XMLHttpRequestInterceptor();
interceptor.on('request', requestListener);

describe('spotlight', () => {
beforeAll(async () => {
interceptor.apply();
});

afterEach(() => {
jest.resetAllMocks();
});

it('should not change the original envelope', () => {
const mockHub = createMockHub();

Expand All @@ -24,8 +39,7 @@ describe('spotlight', () => {
expect(originalEnvelopeReference).toEqual(createMockEnvelope());
});

it('should remove image attachments from spotlight envelope', () => {
fetchMock.mockOnce();
it('should remove image attachments from spotlight envelope', async () => {
const mockHub = createMockHub();

const spotlight = Spotlight();
Expand All @@ -40,8 +54,9 @@ describe('spotlight', () => {

spotlightBeforeEnvelope?.(createMockEnvelope());

const [{ request }] = requestListener.mock.calls[0];
expect(spotlightBeforeEnvelope).toBeDefined();
expect(fetchMock.mock.lastCall?.[1]?.body?.toString().includes('image/png')).toBe(false);
expect((await request.text()).includes('image/png')).toBe(false);
});
});

Expand Down
2 changes: 0 additions & 2 deletions test/mockFetch.ts

This file was deleted.

70 changes: 56 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3258,6 +3258,18 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@mswjs/interceptors@^0.25.15":
version "0.25.15"
resolved "https://registry.yarnpkg.com/@mswjs/interceptors/-/interceptors-0.25.15.tgz#183c5761d3c20e07ac49a206df39a5b6df9e8242"
integrity sha512-s4jdyxmq1eeftfDXJ7MUiK/jlvYaU8Sr75+42hHCVBrYez0k51RHbMitKIKdmsF92Q6gwhp8Sm1MmvdA9llpcg==
dependencies:
"@open-draft/deferred-promise" "^2.2.0"
"@open-draft/logger" "^0.3.0"
"@open-draft/until" "^2.0.0"
is-node-process "^1.2.0"
outvariant "^1.2.1"
strict-event-emitter "^0.5.1"

"@nicolo-ribaudo/[email protected]":
version "2.1.8-no-fsevents.3"
resolved "https://registry.yarnpkg.com/@nicolo-ribaudo/chokidar-2/-/chokidar-2-2.1.8-no-fsevents.3.tgz#323d72dd25103d0c4fbdce89dadf574a787b1f9b"
Expand Down Expand Up @@ -3300,6 +3312,24 @@
mkdirp "^1.0.4"
rimraf "^3.0.2"

"@open-draft/deferred-promise@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@open-draft/deferred-promise/-/deferred-promise-2.2.0.tgz#4a822d10f6f0e316be4d67b4d4f8c9a124b073bd"
integrity sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==

"@open-draft/logger@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@open-draft/logger/-/logger-0.3.0.tgz#2b3ab1242b360aa0adb28b85f5d7da1c133a0954"
integrity sha512-X2g45fzhxH238HKO4xbSr7+wBS8Fvw6ixhTDuvLd5mqh6bJJCFAPwU9mPDxbcrRtfxv4u5IHCEH77BmxvXmmxQ==
dependencies:
is-node-process "^1.2.0"
outvariant "^1.4.0"

"@open-draft/until@^2.0.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@open-draft/until/-/until-2.1.0.tgz#0acf32f470af2ceaf47f095cdecd40d68666efda"
integrity sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==

"@pkgr/utils@^2.3.1":
version "2.4.2"
resolved "https://registry.yarnpkg.com/@pkgr/utils/-/utils-2.4.2.tgz#9e638bbe9a6a6f165580dc943f138fd3309a2cbc"
Expand Down Expand Up @@ -4254,6 +4284,11 @@
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.4.tgz#e884a59338da907bda8d2ed03e01c5c49d036f1c"
integrity sha512-zAuJWQflfx6dYJM62vna+Sn5aeSWhh3OB+wfUEACNcqUSc0AGc5JKl+ycL1vrH7frGTXhJchYjE1Hak8L819dA==

"@types/xmlhttprequest@^1.8.2":
version "1.8.2"
resolved "https://registry.yarnpkg.com/@types/xmlhttprequest/-/xmlhttprequest-1.8.2.tgz#0061fccb7a55b349d23f2381660ba2b124b8d197"
integrity sha512-PfIzIb4tiva9bL40mOmeAe23T3QkJS2AfZ+vqgJWEJ2bxn5KUnDkikizu6TVaZRzQeThOeAn/Zh4PMkfFwEMtg==

"@types/yargs-parser@*":
version "15.0.0"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d"
Expand Down Expand Up @@ -5908,7 +5943,7 @@ cosmiconfig@^5.0.5, cosmiconfig@^5.1.0:
js-yaml "^3.13.1"
parse-json "^4.0.0"

cross-fetch@^3.0.4, cross-fetch@^3.1.5:
cross-fetch@^3.1.5:
version "3.1.8"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.8.tgz#0327eba65fd68a7d119f8fb2bf9334a1a7956f82"
integrity sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==
Expand Down Expand Up @@ -8542,6 +8577,11 @@ is-negative-zero@^2.0.2:
resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.2.tgz#7bf6f03a28003b8b3965de3ac26f664d765f3150"
integrity sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==

is-node-process@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/is-node-process/-/is-node-process-1.2.0.tgz#ea02a1b90ddb3934a19aea414e88edef7e11d134"
integrity sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw==

is-number-object@^1.0.4:
version "1.0.7"
resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.7.tgz#59d50ada4c45251784e9904f5246c742f07a42fc"
Expand Down Expand Up @@ -9020,14 +9060,6 @@ jest-extended@^4.0.2:
jest-diff "^29.0.0"
jest-get-type "^29.0.0"

jest-fetch-mock@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-3.0.3.tgz#31749c456ae27b8919d69824f1c2bd85fe0a1f3b"
integrity sha512-Ux1nWprtLrdrH4XwE7O7InRY6psIi3GOsqNESJgMJ+M5cv4A8Lh7SN9d2V2kKRZ8ebAfcd1LNyZguAOb6JiDqw==
dependencies:
cross-fetch "^3.0.4"
promise-polyfill "^8.1.3"

jest-get-type@^29.0.0, jest-get-type@^29.6.3:
version "29.6.3"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-29.6.3.tgz#36f499fdcea197c1045a127319c0481723908fd1"
Expand Down Expand Up @@ -11141,6 +11173,11 @@ osenv@^0.1.5:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

outvariant@^1.2.1, outvariant@^1.4.0:
version "1.4.2"
resolved "https://registry.yarnpkg.com/outvariant/-/outvariant-1.4.2.tgz#f54f19240eeb7f15b28263d5147405752d8e2066"
integrity sha512-Ou3dJ6bA/UJ5GVHxah4LnqDwZRwAmWxrG3wtrHrbGnP4RnLCtA64A4F+ae7Y8ww660JaddSoArUR5HjipWSHAQ==

p-finally@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
Expand Down Expand Up @@ -11570,11 +11607,6 @@ promise-inflight@^1.0.1:
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
integrity sha512-6zWPyEOFaQBJYcGMHBKTKJ3u6TBsnMFOIZSa6ce1e/ZrrsOlnHRHbabMjLiBYKp+n44X9eUI6VUPaukCXHuG4g==

promise-polyfill@^8.1.3:
version "8.3.0"
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.3.0.tgz#9284810268138d103807b11f4e23d5e945a4db63"
integrity sha512-H5oELycFml5yto/atYqmjyigJoAo3+OXwolYiH7OfQuYlAqhxNvTfiNMbV9hsC6Yp83yE5r2KTVmtrG6R9i6Pg==

promise@^7.1.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
Expand Down Expand Up @@ -12732,6 +12764,11 @@ stream-to-array@^2.3.0:
dependencies:
any-promise "^1.1.0"

strict-event-emitter@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz#1602ece81c51574ca39c6815e09f1a3e8550bd93"
integrity sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==

string-length@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-4.0.2.tgz#a8a8dc7bd5c1a82b9b3c8b87e125f66871b6e57a"
Expand Down Expand Up @@ -14069,6 +14106,11 @@ xmlchars@^2.2.0:
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"
integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==

xmlhttprequest@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc"
integrity sha512-58Im/U0mlVBLM38NdZjHyhuMtCqa61469k2YP/AaPbvCoV9aQGUpbJBj1QRm2ytRiVQBD/fsw7L2bJGDVQswBA==

xtend@~4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
Expand Down
Loading