Skip to content

Commit ea28cc3

Browse files
ibbykhazanchiOpenCodeBuildcodex
authored
[wrangler] Add observability query string redaction (#15379)
Co-authored-by: OpenCode <noreply@opencode.ai> Co-authored-by: Build <noreply@cloudflare.com> Co-authored-by: OpenAI <noreply@openai.com>
1 parent 1809c5e commit ea28cc3

14 files changed

Lines changed: 91 additions & 5 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@cloudflare/config": minor
3+
"@cloudflare/deploy-helpers": patch
4+
"@cloudflare/workers-utils": minor
5+
"wrangler": minor
6+
---
7+
8+
Add query string redaction to Workers observability configuration
9+
10+
Set `observability.redact_query_string` in `wrangler.json` or `observability.redactQueryString` in the experimental `cloudflare.config.ts` format to remove query strings from request URLs in logs and traces.

‎packages/config/src/__tests__/convert.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe("convertToWranglerConfig", () => {
5757
observability: {
5858
enabled: true,
5959
headSamplingRate: 0.5,
60+
redactQueryString: true,
6061
logs: {
6162
enabled: true,
6263
headSamplingRate: 0.25,
@@ -75,6 +76,7 @@ describe("convertToWranglerConfig", () => {
7576
expect(result.observability).toEqual({
7677
enabled: true,
7778
head_sampling_rate: 0.5,
79+
redact_query_string: true,
7880
logs: {
7981
enabled: true,
8082
head_sampling_rate: 0.25,

‎packages/config/src/__tests__/schema.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,34 @@ describe("InputWorkerSchema", () => {
463463
}
464464
});
465465

466+
it("accepts camelCase query string redaction configuration", ({
467+
expect,
468+
}) => {
469+
const result = InputWorkerSchema.safeParse({
470+
...baseConfig,
471+
observability: {
472+
enabled: true,
473+
redactQueryString: true,
474+
},
475+
});
476+
477+
expect(result.success).toBe(true);
478+
});
479+
480+
it("rejects snake_case query string redaction configuration", ({
481+
expect,
482+
}) => {
483+
const result = InputWorkerSchema.safeParse({
484+
...baseConfig,
485+
observability: {
486+
enabled: true,
487+
redact_query_string: true,
488+
},
489+
});
490+
491+
expect(result.success).toBe(false);
492+
});
493+
466494
it("rejects unknown keys inside a trigger", ({ expect }) => {
467495
const result = InputWorkerSchema.safeParse({
468496
...baseConfig,

‎packages/config/src/convert.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ function convertObservability(
132132
if (observability.headSamplingRate !== undefined) {
133133
out.head_sampling_rate = observability.headSamplingRate;
134134
}
135+
if (observability.redactQueryString !== undefined) {
136+
out.redact_query_string = observability.redactQueryString;
137+
}
135138
if (observability.logs !== undefined) {
136139
const logs: NonNullable<NonNullable<RawConfig["observability"]>["logs"]> =
137140
{};

‎packages/config/src/schema.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ const LimitsSchema = z.strictObject({
426426
const ObservabilitySchema = z.strictObject({
427427
enabled: z.boolean().optional(),
428428
headSamplingRate: z.number().optional(),
429+
redactQueryString: z.boolean().optional(),
429430
logs: z
430431
.strictObject({
431432
enabled: z.boolean().optional(),

‎packages/config/src/types.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ export interface WorkerConfig {
296296
enabled?: boolean;
297297
/** The sampling rate. */
298298
headSamplingRate?: number;
299+
/**
300+
* Whether query strings are removed from request URLs in logs and traces.
301+
*
302+
* @default false
303+
*/
304+
redactQueryString?: boolean;
299305
logs?: {
300306
enabled?: boolean;
301307
/** The sampling rate. */

‎packages/deploy-helpers/src/deploy/helpers/config-diffs.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ function normalizeObservability(
286286
const fullObservabilityDefaults = {
287287
enabled,
288288
head_sampling_rate: 1,
289+
redact_query_string: false,
289290
logs: {
290291
enabled,
291292
head_sampling_rate: 1,

‎packages/workers-utils/src/config/environment.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,12 @@ export interface Observability {
18541854
enabled?: boolean;
18551855
/** The sampling rate */
18561856
head_sampling_rate?: number;
1857+
/**
1858+
* Whether query strings are removed from request URLs in logs and traces.
1859+
*
1860+
* @default false
1861+
*/
1862+
redact_query_string?: boolean;
18571863
logs?: {
18581864
enabled?: boolean;
18591865
/** The sampling rate */

‎packages/workers-utils/src/config/validation.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6800,6 +6800,15 @@ const validateObservability: ValidatorFn = (diagnostics, field, value) => {
68006800
"number"
68016801
) && isValid;
68026802

6803+
isValid =
6804+
validateOptionalProperty(
6805+
diagnostics,
6806+
field,
6807+
"redact_query_string",
6808+
val.redact_query_string,
6809+
"boolean"
6810+
) && isValid;
6811+
68036812
isValid =
68046813
validateOptionalProperty(diagnostics, field, "logs", val.logs, "object") &&
68056814
isValid;
@@ -6817,6 +6826,7 @@ const validateObservability: ValidatorFn = (diagnostics, field, value) => {
68176826
validateAdditionalProperties(diagnostics, field, Object.keys(val), [
68186827
"enabled",
68196828
"head_sampling_rate",
6829+
"redact_query_string",
68206830
"logs",
68216831
"traces",
68226832
]) && isValid;

‎packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11642,6 +11642,7 @@ describe("normalizeAndValidateConfig()", () => {
1164211642
observability: {
1164311643
notEnabled: "true",
1164411644
head_sampling_rate: true,
11645+
redact_query_string: "true",
1164511646
},
1164611647
} as unknown as RawConfig,
1164711648
undefined,
@@ -11659,7 +11660,8 @@ describe("normalizeAndValidateConfig()", () => {
1165911660
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1166011661
"Processing wrangler configuration:
1166111662
- "observability.enabled" or "observability.logs.enabled" or "observability.traces.enabled" is required.
11662-
- Expected "observability.head_sampling_rate" to be of type number but got true."
11663+
- Expected "observability.head_sampling_rate" to be of type number but got true.
11664+
- Expected "observability.redact_query_string" to be of type boolean but got "true"."
1166311665
`);
1166411666
});
1166511667

@@ -11685,6 +11687,7 @@ describe("normalizeAndValidateConfig()", () => {
1168511687
observability: {
1168611688
enabled: true,
1168711689
head_sampling_rate: 1,
11690+
redact_query_string: true,
1168811691
logs: {
1168911692
enabled: true,
1169011693
head_sampling_rate: 1,

0 commit comments

Comments
 (0)