Skip to content

Commit dbc7dfe

Browse files
committed
test: Fix telemetry test to capture all envelopes
1 parent 7e76d7c commit dbc7dfe

13 files changed

Lines changed: 42 additions & 12 deletions

File tree

packages/bundler-plugin-core/src/sentry/transports.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type {
1212
TransportRequest,
1313
TransportRequestExecutor,
1414
} from "@sentry/types";
15+
import { join } from "node:path";
16+
import { appendFileSync, mkdirSync } from "node:fs";
1517

1618
// Estimated maximum size for reasonable standalone event
1719
const GZIP_THRESHOLD = 1024 * 32;
@@ -105,6 +107,7 @@ export function makeOptionallyEnabledNodeTransport(
105107
): (options: BaseTransportOptions) => Transport {
106108
return (nodeTransportOptions) => {
107109
const nodeTransport = makeNodeTransport(nodeTransportOptions);
110+
108111
return {
109112
flush: (timeout) => nodeTransport.flush(timeout),
110113
send: async (request) => {
@@ -120,10 +123,9 @@ export function makeOptionallyEnabledNodeTransport(
120123

121124
if (await shouldSendTelemetry) {
122125
if (process.env["SENTRY_TEST_OUT_DIR"]) {
123-
// eslint-disable-next-line @typescript-eslint/unbound-method
124-
const { join } = await import("node:path");
125-
const { appendFileSync } = await import("node:fs");
126-
const path = join(process.env["SENTRY_TEST_OUT_DIR"], "sentry-telemetry.json");
126+
const outDir = process.env["SENTRY_TEST_OUT_DIR"];
127+
mkdirSync(outDir, { recursive: true });
128+
const path = join(outDir, "sentry-telemetry.json");
127129
appendFileSync(path, JSON.stringify(request) + ",\n");
128130
return { statusCode: 200 };
129131
}

packages/integration-tests-next/fixtures/esbuild/telemetry.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
55
runBundler();
66
expect(readOutputFiles()).toMatchInlineSnapshot(`
77
{
8-
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
8+
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":true,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"ok","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
9+
[{"event_id":"UUID","sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"},"trace":{"environment":"production","release":"PLUGIN_VERSION","public_key":"UUID","trace_id":"UUID","sample_rate":"1","transaction":"Sentry Bundler Plugin execution","sampled":"true"}},[[{"type":"transaction"},{"contexts":{"trace":{"span_id":"SHORT_UUID","trace_id":"UUID","data":{"sentry.origin":"manual","sentry.source":"custom","sentry.sample_rate":1},"origin":"manual"},"runtime":{"name":"node","version":"NODE_VERSION"}},"spans":[],"start_timestamp":START_TIMESTAMP,"timestamp":TIMESTAMP,"transaction":"Sentry Bundler Plugin execution","type":"transaction","transaction_info":{"source":"custom"},"platform":"PLATFORM","event_id":"UUID","environment":"production","release":"PLUGIN_VERSION","tags":{"upload-legacy-sourcemaps":false,"module-metadata":false,"inject-build-information":false,"set-commits":"auto","finalize-release":true,"deploy-options":false,"custom-error-handler":false,"sourcemaps-assets":false,"delete-after-upload":false,"sourcemaps-disabled":false,"react-annotate":false,"node":"NODE_VERSION","platform":"PLATFORM","meta-framework":"none","application-key-set":false,"ci":true,"project":"undefined","bundler":"esbuild","bundler-major-version":"28"},"sdk":{"name":"sentry.javascript.node","version":"8.30.0","integrations":[],"packages":[{"name":"npm:@sentry/node","version":"8.30.0"}]}}]]],
10+
[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
911
",
1012
"telemetry.js": "(() => {
1113
// _sentry-injection-stub

packages/integration-tests-next/fixtures/rolldown/telemetry.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
1717
console.log("hello world");
1818
//#endregion
1919
",
20-
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
20+
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":true,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"ok","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
21+
[{"event_id":"UUID","sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"},"trace":{"environment":"production","release":"PLUGIN_VERSION","public_key":"UUID","trace_id":"UUID","sample_rate":"1","transaction":"Sentry Bundler Plugin execution","sampled":"true"}},[[{"type":"transaction"},{"contexts":{"trace":{"span_id":"SHORT_UUID","trace_id":"UUID","data":{"sentry.origin":"manual","sentry.source":"custom","sentry.sample_rate":1},"origin":"manual"},"runtime":{"name":"node","version":"NODE_VERSION"}},"spans":[],"start_timestamp":START_TIMESTAMP,"timestamp":TIMESTAMP,"transaction":"Sentry Bundler Plugin execution","type":"transaction","transaction_info":{"source":"custom"},"platform":"PLATFORM","event_id":"UUID","environment":"production","release":"PLUGIN_VERSION","tags":{"upload-legacy-sourcemaps":false,"module-metadata":false,"inject-build-information":false,"set-commits":"auto","finalize-release":true,"deploy-options":false,"custom-error-handler":false,"sourcemaps-assets":false,"delete-after-upload":false,"sourcemaps-disabled":false,"react-annotate":false,"node":"NODE_VERSION","platform":"PLATFORM","meta-framework":"none","application-key-set":false,"ci":true,"project":"undefined","bundler":"rollup","bundler-major-version":"3"},"sdk":{"name":"sentry.javascript.node","version":"8.30.0","integrations":[],"packages":[{"name":"npm:@sentry/node","version":"8.30.0"}]}}]]],
22+
[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
2123
",
2224
}
2325
`);

packages/integration-tests-next/fixtures/rollup3/telemetry.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
88
"basic.js": "// eslint-disable-next-line no-console
99
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world");
1010
",
11-
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
11+
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":true,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"ok","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
12+
[{"event_id":"UUID","sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"},"trace":{"environment":"production","release":"PLUGIN_VERSION","public_key":"UUID","trace_id":"UUID","sample_rate":"1","transaction":"Sentry Bundler Plugin execution","sampled":"true"}},[[{"type":"transaction"},{"contexts":{"trace":{"span_id":"SHORT_UUID","trace_id":"UUID","data":{"sentry.origin":"manual","sentry.source":"custom","sentry.sample_rate":1},"origin":"manual"},"runtime":{"name":"node","version":"NODE_VERSION"}},"spans":[],"start_timestamp":START_TIMESTAMP,"timestamp":TIMESTAMP,"transaction":"Sentry Bundler Plugin execution","type":"transaction","transaction_info":{"source":"custom"},"platform":"PLATFORM","event_id":"UUID","environment":"production","release":"PLUGIN_VERSION","tags":{"upload-legacy-sourcemaps":false,"module-metadata":false,"inject-build-information":false,"set-commits":"auto","finalize-release":true,"deploy-options":false,"custom-error-handler":false,"sourcemaps-assets":false,"delete-after-upload":false,"sourcemaps-disabled":false,"react-annotate":false,"node":"NODE_VERSION","platform":"PLATFORM","meta-framework":"none","application-key-set":false,"ci":true,"project":"undefined","bundler":"rollup","bundler-major-version":"3"},"sdk":{"name":"sentry.javascript.node","version":"8.30.0","integrations":[],"packages":[{"name":"npm:@sentry/node","version":"8.30.0"}]}}]]],
13+
[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
1214
",
1315
}
1416
`);

packages/integration-tests-next/fixtures/rollup4/telemetry.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
88
"basic.js": "// eslint-disable-next-line no-console
99
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"CURRENT_SHA"};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000",e._sentryDebugIdIdentifier="sentry-dbid-00000000-0000-0000-0000-000000000000");}catch(e){}}();console.log("hello world");
1010
",
11-
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
11+
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":true,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"ok","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
12+
[{"event_id":"UUID","sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"},"trace":{"environment":"production","release":"PLUGIN_VERSION","public_key":"UUID","trace_id":"UUID","sample_rate":"1","transaction":"Sentry Bundler Plugin execution","sampled":"true"}},[[{"type":"transaction"},{"contexts":{"trace":{"span_id":"SHORT_UUID","trace_id":"UUID","data":{"sentry.origin":"manual","sentry.source":"custom","sentry.sample_rate":1},"origin":"manual"},"runtime":{"name":"node","version":"NODE_VERSION"}},"spans":[],"start_timestamp":START_TIMESTAMP,"timestamp":TIMESTAMP,"transaction":"Sentry Bundler Plugin execution","type":"transaction","transaction_info":{"source":"custom"},"platform":"PLATFORM","event_id":"UUID","environment":"production","release":"PLUGIN_VERSION","tags":{"upload-legacy-sourcemaps":false,"module-metadata":false,"inject-build-information":false,"set-commits":"auto","finalize-release":true,"deploy-options":false,"custom-error-handler":false,"sourcemaps-assets":false,"delete-after-upload":false,"sourcemaps-disabled":false,"react-annotate":false,"node":"NODE_VERSION","platform":"PLATFORM","meta-framework":"none","application-key-set":false,"ci":true,"project":"undefined","bundler":"rollup","bundler-major-version":"4"},"sdk":{"name":"sentry.javascript.node","version":"8.30.0","integrations":[],"packages":[{"name":"npm:@sentry/node","version":"8.30.0"}]}}]]],
13+
[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
1214
",
1315
}
1416
`);

packages/integration-tests-next/fixtures/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ export function readAllFiles(
7272
"TIMESTAMP"
7373
)
7474
.replace(/[a-f0-9]{32}/g, "UUID")
75+
.replace(/"[a-f0-9]{16}"/g, '"SHORT_UUID"')
76+
.replaceAll(process.version, "NODE_VERSION")
77+
.replace(/"ci":false/g, '"ci":true')
78+
.replace(/"platform":".+?"/g, '"platform":"PLATFORM"')
7579
.replace(/"duration":[\d.]+/g, '"duration":DURATION')
80+
.replace(/"start_timestamp":[\d.]+/g, '"start_timestamp":START_TIMESTAMP')
81+
.replace(/"timestamp":[\d.]+/g, '"timestamp":TIMESTAMP')
7682
.replace(/"release":"[\d.]+"/g, '"release":"PLUGIN_VERSION"');
7783
} else {
7884
// Normalize Windows line endings for cross-platform snapshots

packages/integration-tests-next/fixtures/vite4/telemetry.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export default defineConfig({
1212
entryFileNames: "[name].js",
1313
},
1414
},
15+
// We already delete the directory and don't want our telemetry file to be deleted
16+
emptyOutDir: false,
1517
},
1618
plugins: [sentryVitePlugin(sentryConfig)],
1719
});

packages/integration-tests-next/fixtures/vite4/telemetry.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
1616
})();
1717
console.log("hello world");
1818
",
19-
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
19+
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":true,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"ok","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
20+
[{"event_id":"UUID","sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"},"trace":{"environment":"production","release":"PLUGIN_VERSION","public_key":"UUID","trace_id":"UUID","sample_rate":"1","transaction":"Sentry Bundler Plugin execution","sampled":"true"}},[[{"type":"transaction"},{"contexts":{"trace":{"span_id":"SHORT_UUID","trace_id":"UUID","data":{"sentry.origin":"manual","sentry.source":"custom","sentry.sample_rate":1},"origin":"manual"},"runtime":{"name":"node","version":"NODE_VERSION"}},"spans":[],"start_timestamp":START_TIMESTAMP,"timestamp":TIMESTAMP,"transaction":"Sentry Bundler Plugin execution","type":"transaction","transaction_info":{"source":"custom"},"platform":"PLATFORM","event_id":"UUID","environment":"production","release":"PLUGIN_VERSION","tags":{"upload-legacy-sourcemaps":false,"module-metadata":false,"inject-build-information":false,"set-commits":"auto","finalize-release":true,"deploy-options":false,"custom-error-handler":false,"sourcemaps-assets":false,"delete-after-upload":false,"sourcemaps-disabled":false,"react-annotate":false,"node":"NODE_VERSION","platform":"PLATFORM","meta-framework":"none","application-key-set":false,"ci":true,"project":"undefined","bundler":"vite","bundler-major-version":"4"},"sdk":{"name":"sentry.javascript.node","version":"8.30.0","integrations":[],"packages":[{"name":"npm:@sentry/node","version":"8.30.0"}]}}]]],
21+
[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
2022
",
2123
}
2224
`);

packages/integration-tests-next/fixtures/vite7/telemetry.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export default defineConfig({
1212
entryFileNames: "[name].js",
1313
},
1414
},
15+
// We already delete the directory and don't want our telemetry file to be deleted
16+
emptyOutDir: false,
1517
},
1618
plugins: [sentryVitePlugin(sentryConfig)],
1719
});

packages/integration-tests-next/fixtures/vite7/telemetry.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
1616
})();
1717
console.log("hello world");
1818
",
19-
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
19+
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":true,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"ok","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
20+
[{"event_id":"UUID","sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"},"trace":{"environment":"production","release":"PLUGIN_VERSION","public_key":"UUID","trace_id":"UUID","sample_rate":"1","transaction":"Sentry Bundler Plugin execution","sampled":"true"}},[[{"type":"transaction"},{"contexts":{"trace":{"span_id":"SHORT_UUID","trace_id":"UUID","data":{"sentry.origin":"manual","sentry.source":"custom","sentry.sample_rate":1},"origin":"manual"},"runtime":{"name":"node","version":"NODE_VERSION"}},"spans":[],"start_timestamp":START_TIMESTAMP,"timestamp":TIMESTAMP,"transaction":"Sentry Bundler Plugin execution","type":"transaction","transaction_info":{"source":"custom"},"platform":"PLATFORM","event_id":"UUID","environment":"production","release":"PLUGIN_VERSION","tags":{"upload-legacy-sourcemaps":false,"module-metadata":false,"inject-build-information":false,"set-commits":"auto","finalize-release":true,"deploy-options":false,"custom-error-handler":false,"sourcemaps-assets":false,"delete-after-upload":false,"sourcemaps-disabled":false,"react-annotate":false,"node":"NODE_VERSION","platform":"PLATFORM","meta-framework":"none","application-key-set":false,"ci":true,"project":"undefined","bundler":"vite","bundler-major-version":"7"},"sdk":{"name":"sentry.javascript.node","version":"8.30.0","integrations":[],"packages":[{"name":"npm:@sentry/node","version":"8.30.0"}]}}]]],
21+
[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
2022
",
2123
}
2224
`);

0 commit comments

Comments
 (0)