Skip to content

Commit 97614c9

Browse files
authored
fix(core): Conditionally add tracing headers (#907)
Our trace data was added unconditionally here.
1 parent a0aefde commit 97614c9

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-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: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ 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 } =
11+
vi.hoisted(() => ({
12+
mockCliExecute: vi.fn(),
13+
mockCliUploadSourceMaps: vi.fn(),
14+
mockCliNewDeploy: vi.fn(),
15+
mockCliConstructor: vi.fn(),
16+
}));
1517

1618
vi.mock("@sentry/cli", () => ({
1719
default: class {
20+
constructor(...args: unknown[]) {
21+
mockCliConstructor(...args);
22+
}
1823
execute = mockCliExecute;
1924
releases = {
2025
uploadSourceMaps: mockCliUploadSourceMaps,
@@ -640,6 +645,41 @@ describe("createSentryBuildPluginManager", () => {
640645
});
641646
});
642647

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

0 commit comments

Comments
 (0)