diff --git a/.changeset/chilled-apes-repeat.md b/.changeset/chilled-apes-repeat.md new file mode 100644 index 000000000000..4f15f093c5fe --- /dev/null +++ b/.changeset/chilled-apes-repeat.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +fix: synchronize observability settings during `wrangler versions deploy` + +When running `wrangler versions deploy`, Wrangler will now update `observability` settings in addition to `logpush` and `tail_consumers`. Unlike `wrangler deploy`, it will not disable observability when `observability` is undefined in `wrangler.toml`. diff --git a/packages/wrangler/src/__tests__/versions/versions.deploy.test.ts b/packages/wrangler/src/__tests__/versions/versions.deploy.test.ts index c4b385f057d6..63e6d1f90235 100644 --- a/packages/wrangler/src/__tests__/versions/versions.deploy.test.ts +++ b/packages/wrangler/src/__tests__/versions/versions.deploy.test.ts @@ -704,17 +704,78 @@ describe("versions deploy", () => { │ │ Synced non-versioned settings: │ logpush: true + │ observability: │ tail_consumers: │ ╰ SUCCESS Deployed test-name version 00000000-0000-0000-0000-000000000000 at 100% (TIMINGS)" `); + }); + + test("with observability disabled in wrangler.toml", async () => { + writeWranglerToml({ + observability: { + enabled: false, + }, + }); - expect(normalizeOutput(std.out)).toContain("logpush: true"); + const result = runWrangler( + "versions deploy 10000000-0000-0000-0000-000000000000 --yes --experimental-gradual-rollouts" + ); + + await expect(result).resolves.toBeUndefined(); + + expect(normalizeOutput(std.out)).toMatchInlineSnapshot(` + "╭ Deploy Worker Versions by splitting traffic between multiple versions + │ + ├ Fetching latest deployment + │ + ├ Your current deployment has 2 version(s): + │ + │ (10%) 00000000-0000-0000-0000-000000000000 + │ Created: TIMESTAMP + │ Tag: - + │ Message: - + │ + │ (90%) 00000000-0000-0000-0000-000000000000 + │ Created: TIMESTAMP + │ Tag: - + │ Message: - + │ + ├ Fetching deployable versions + │ + ├ Which version(s) do you want to deploy? + ├ 1 Worker Version(s) selected + │ + ├ Worker Version 1: 00000000-0000-0000-0000-000000000000 + │ Created: TIMESTAMP + │ Tag: - + │ Message: - + │ + ├ What percentage of traffic should Worker Version 1 receive? + ├ 100% of traffic + ├ + ├ Add a deployment message (skipped) + │ + ├ Deploying 1 version(s) + │ + ├ Syncing non-versioned settings + │ + │ Synced non-versioned settings: + │ logpush: + │ observability: enabled: false + │ tail_consumers: + │ + ╰ SUCCESS Deployed test-name version 00000000-0000-0000-0000-000000000000 at 100% (TIMINGS)" + `); }); - test("with logpush and tail_consumers in wrangler.toml", async () => { + test("with logpush, tail_consumers, and observability in wrangler.toml", async () => { writeWranglerToml({ logpush: false, + observability: { + enabled: true, + head_sampling_rate: 0.5, + }, tail_consumers: [ { service: "worker-1" }, { service: "worker-2", environment: "preview" }, @@ -766,6 +827,8 @@ describe("versions deploy", () => { │ │ Synced non-versioned settings: │ logpush: false + │ observability: enabled: true + │ head_sampling_rate: 0.5 │ tail_consumers: worker-1 │ worker-2 (preview) │ worker-3 (staging) diff --git a/packages/wrangler/src/versions/deploy.ts b/packages/wrangler/src/versions/deploy.ts index bad07d6edfdd..5f195141f5fa 100644 --- a/packages/wrangler/src/versions/deploy.ts +++ b/packages/wrangler/src/versions/deploy.ts @@ -558,11 +558,12 @@ async function promptPercentages( async function maybePatchSettings( accountId: string, workerName: string, - config: Pick + config: Pick ) { const maybeUndefinedSettings = { logpush: config.logpush, tail_consumers: config.tail_consumers, + observability: config.observability, // TODO reconcile with how regular deploy handles empty state }; const definedSettings = Object.fromEntries( Object.entries(maybeUndefinedSettings).filter( @@ -587,9 +588,22 @@ async function maybePatchSettings( }, }); + const observability: Record = {}; + if (patchedSettings.observability) { + observability["enabled"] = String(patchedSettings.observability.enabled); + if (patchedSettings.observability.head_sampling_rate) { + observability["head_sampling_rate"] = String( + patchedSettings.observability.head_sampling_rate + ); + } + } const formattedSettings = formatLabelledValues( { logpush: String(patchedSettings.logpush ?? ""), + observability: + Object.keys(observability).length > 0 + ? formatLabelledValues(observability) + : "", tail_consumers: patchedSettings.tail_consumers ?.map((tc) =>