Skip to content

Commit 69889a3

Browse files
committed
conditionally add headers
1 parent a0aefde commit 69889a3

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

packages/bundler-plugin-core/src/build-plugin-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function createCliInstance(options: NormalizedOptions): SentryCli {
117117
url: options.url,
118118
vcsRemote: options.release.vcsRemote,
119119
headers: {
120-
...getTraceData(),
120+
...(options.telemetry ? getTraceData() : {}),
121121
...options.headers,
122122
},
123123
});

packages/bundler-plugin-core/test/build-plugin-manager.test.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ import { globFiles } from "../src/glob";
77
import { prepareBundleForDebugIdUpload } from "../src/debug-id-upload";
88
import { describe, it, expect, afterEach, beforeEach, vi, MockedFunction } from "vitest";
99

10-
const { mockCliExecute, mockCliUploadSourceMaps, mockCliNewDeploy } = vi.hoisted(() => ({
11-
mockCliExecute: vi.fn(),
12-
mockCliUploadSourceMaps: vi.fn(),
13-
mockCliNewDeploy: vi.fn(),
14-
}));
10+
const { mockCliExecute, mockCliUploadSourceMaps, mockCliNewDeploy, mockCliConstructor } = vi.hoisted(
11+
() => ({
12+
mockCliExecute: vi.fn(),
13+
mockCliUploadSourceMaps: vi.fn(),
14+
mockCliNewDeploy: vi.fn(),
15+
mockCliConstructor: vi.fn(),
16+
})
17+
);
1518

1619
vi.mock("@sentry/cli", () => ({
1720
default: class {
21+
constructor(...args: unknown[]) {
22+
mockCliConstructor(...args);
23+
}
1824
execute = mockCliExecute;
1925
releases = {
2026
uploadSourceMaps: mockCliUploadSourceMaps,
@@ -640,6 +646,41 @@ describe("createSentryBuildPluginManager", () => {
640646
});
641647
});
642648

649+
describe("telemetry option", () => {
650+
it("should not pass sentry-trace or baggage headers to CLI when telemetry is false", async () => {
651+
mockCliExecute.mockResolvedValue(undefined);
652+
653+
const buildPluginManager = createSentryBuildPluginManager(
654+
{
655+
authToken: "test-token",
656+
org: "test-org",
657+
project: "test-project",
658+
telemetry: false,
659+
},
660+
{
661+
buildTool: "webpack",
662+
loggerPrefix: "[sentry-webpack-plugin]",
663+
}
664+
);
665+
666+
// Trigger a CLI operation so createCliInstance is called
667+
await buildPluginManager.injectDebugIds(["/path/to/bundle"]);
668+
669+
// Find the CLI constructor call that was made by createCliInstance (not the one from allowedToSendTelemetry)
670+
const cliConstructorCalls = mockCliConstructor.mock.calls;
671+
expect(cliConstructorCalls.length).toBeGreaterThan(0);
672+
673+
// Check that none of the CLI instances were created with sentry-trace or baggage headers
674+
for (const call of cliConstructorCalls) {
675+
const options = call[1] as { headers?: Record<string, string> };
676+
if (options?.headers) {
677+
expect(options.headers).not.toHaveProperty("sentry-trace");
678+
expect(options.headers).not.toHaveProperty("baggage");
679+
}
680+
}
681+
});
682+
});
683+
643684
describe("createRelease deploy deduplication", () => {
644685
beforeEach(() => {
645686
vi.clearAllMocks();

0 commit comments

Comments
 (0)