Skip to content

Commit 0a83fb3

Browse files
fix correlation context header missing issue
1 parent d7491af commit 0a83fb3

4 files changed

Lines changed: 68 additions & 68 deletions

File tree

package-lock.json

Lines changed: 31 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"vitest": "^4.1.8"
7070
},
7171
"dependencies": {
72-
"@azure/app-configuration": "^1.11.0",
72+
"@azure/app-configuration": "^1.12.0",
73+
"@azure-rest/core-client": "^2.6.0",
7374
"@azure/core-rest-pipeline": "^1.6.0",
7475
"@azure/identity": "^4.2.1",
7576
"@azure/keyvault-secrets": "^4.7.0",

src/requestTracing/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { OperationOptions } from "@azure/core-client";
4+
import { OperationOptions } from "@azure-rest/core-client";
55
import {
66
AppConfigurationClient,
77
ConfigurationSettingId,
@@ -101,7 +101,9 @@ function applyRequestTracing<T extends OperationOptions>(requestTracingOptions:
101101
const actualOptions = { ...operationOptions };
102102
if (requestTracingOptions.enabled) {
103103
actualOptions.requestOptions = {
104-
customHeaders: {
104+
...actualOptions.requestOptions,
105+
headers: {
106+
...actualOptions.requestOptions?.headers,
105107
[CORRELATION_CONTEXT_HEADER_NAME]: createCorrelationContextHeader(requestTracingOptions)
106108
}
107109
};

test/requestTracing.test.ts

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("request tracing", function () {
3434
after(() => {
3535
});
3636

37-
it("should have correct user agent prefix", async () => {
37+
it("should include the provider identifier in the user agent", async () => {
3838
try {
3939
await load(createMockedConnectionString(fakeEndpoint), {
4040
clientOptions,
@@ -44,7 +44,7 @@ describe("request tracing", function () {
4444
});
4545
} catch { /* empty */ }
4646
expect(headerPolicy.headers).not.undefined;
47-
expect(headerPolicy.headers.get("User-Agent")).satisfy((ua: string) => ua.startsWith("javascript-appconfiguration-provider"));
47+
expect(headerPolicy.headers.get("User-Agent")).satisfy((ua: string) => ua.includes("javascript-appconfiguration-provider"));
4848
});
4949

5050
it("should have request type in correlation-context header", async () => {
@@ -204,18 +204,14 @@ describe("request tracing", function () {
204204
});
205205

206206
it("should have filter type in correlation-context header if feature flags use feature filters", async () => {
207-
let correlationContext: string = "";
208-
const listKvCallback = (listOptions) => {
209-
correlationContext = listOptions?.requestOptions?.customHeaders[CORRELATION_CONTEXT_HEADER_NAME] ?? "";
210-
};
211-
212207
mockAppConfigurationClientListConfigurationSettings([[
213208
createMockedFeatureFlag("Alpha_1", { conditions: { client_filters: [ { name: "Microsoft.TimeWindow" } ] } }),
214209
createMockedFeatureFlag("Alpha_2", { conditions: { client_filters: [ { name: "Microsoft.Targeting" } ] } }),
215210
createMockedFeatureFlag("Alpha_3", { conditions: { client_filters: [ { name: "CustomFilter" } ] } })
216-
]], listKvCallback);
211+
]]);
217212

218213
const settings = await load(createMockedConnectionString(fakeEndpoint), {
214+
clientOptions,
219215
featureFlagOptions: {
220216
enabled: true,
221217
selectors: [ {keyFilter: "*"} ],
@@ -226,34 +222,30 @@ describe("request tracing", function () {
226222
}
227223
});
228224

229-
expect(correlationContext).not.undefined;
230-
expect(correlationContext?.includes("RequestType=Startup")).eq(true);
225+
restoreMocks();
231226

232227
await sleepInMs(1_000 + 1_000);
233228
try {
234229
await settings.refresh();
235230
} catch { /* empty */ }
236231
expect(headerPolicy.headers).not.undefined;
232+
const correlationContext = headerPolicy.headers.get(CORRELATION_CONTEXT_HEADER_NAME);
237233
expect(correlationContext).not.undefined;
238-
expect(correlationContext?.includes("RequestType=Watch")).eq(true);
239-
expect(correlationContext?.includes("Filter=CSTM+TIME+TRGT")).eq(true);
234+
expect(correlationContext.includes("RequestType=Watch")).eq(true);
235+
expect(correlationContext.includes("Filter=CSTM+TIME+TRGT")).eq(true);
240236

241237
restoreMocks();
242238
});
243239

244240
it("should have max variants in correlation-context header if feature flags use variants", async () => {
245-
let correlationContext: string = "";
246-
const listKvCallback = (listOptions) => {
247-
correlationContext = listOptions?.requestOptions?.customHeaders[CORRELATION_CONTEXT_HEADER_NAME] ?? "";
248-
};
249-
250241
mockAppConfigurationClientListConfigurationSettings([[
251242
createMockedFeatureFlag("Alpha_1", { variants: [ {name: "a"}, {name: "b"}] }),
252243
createMockedFeatureFlag("Alpha_2", { variants: [ {name: "a"}, {name: "b"}, {name: "c"}] }),
253244
createMockedFeatureFlag("Alpha_3", { variants: [] })
254-
]], listKvCallback);
245+
]]);
255246

256247
const settings = await load(createMockedConnectionString(fakeEndpoint), {
248+
clientOptions,
257249
featureFlagOptions: {
258250
enabled: true,
259251
selectors: [ {keyFilter: "*"} ],
@@ -264,32 +256,28 @@ describe("request tracing", function () {
264256
}
265257
});
266258

267-
expect(correlationContext).not.undefined;
268-
expect(correlationContext?.includes("RequestType=Startup")).eq(true);
259+
restoreMocks();
269260

270261
await sleepInMs(1_000 + 1_000);
271262
try {
272263
await settings.refresh();
273264
} catch { /* empty */ }
274265
expect(headerPolicy.headers).not.undefined;
266+
const correlationContext = headerPolicy.headers.get(CORRELATION_CONTEXT_HEADER_NAME);
275267
expect(correlationContext).not.undefined;
276-
expect(correlationContext?.includes("RequestType=Watch")).eq(true);
277-
expect(correlationContext?.includes("MaxVariants=3")).eq(true);
268+
expect(correlationContext.includes("RequestType=Watch")).eq(true);
269+
expect(correlationContext.includes("MaxVariants=3")).eq(true);
278270

279271
restoreMocks();
280272
});
281273

282274
it("should have telemety tag in correlation-context header if feature flags enable telemetry", async () => {
283-
let correlationContext: string = "";
284-
const listKvCallback = (listOptions) => {
285-
correlationContext = listOptions?.requestOptions?.customHeaders[CORRELATION_CONTEXT_HEADER_NAME] ?? "";
286-
};
287-
288275
mockAppConfigurationClientListConfigurationSettings([[
289276
createMockedFeatureFlag("Alpha_1", { telemetry: {enabled: true} })
290-
]], listKvCallback);
277+
]]);
291278

292279
const settings = await load(createMockedConnectionString(fakeEndpoint), {
280+
clientOptions,
293281
featureFlagOptions: {
294282
enabled: true,
295283
selectors: [ {keyFilter: "*"} ],
@@ -300,33 +288,29 @@ describe("request tracing", function () {
300288
}
301289
});
302290

303-
expect(correlationContext).not.undefined;
304-
expect(correlationContext?.includes("RequestType=Startup")).eq(true);
291+
restoreMocks();
305292

306293
await sleepInMs(1_000 + 1_000);
307294
try {
308295
await settings.refresh();
309296
} catch { /* empty */ }
310297
expect(headerPolicy.headers).not.undefined;
298+
const correlationContext = headerPolicy.headers.get(CORRELATION_CONTEXT_HEADER_NAME);
311299
expect(correlationContext).not.undefined;
312-
expect(correlationContext?.includes("RequestType=Watch")).eq(true);
313-
expect(correlationContext?.includes("FFFeatures=Telemetry")).eq(true);
300+
expect(correlationContext.includes("RequestType=Watch")).eq(true);
301+
expect(correlationContext.includes("FFFeatures=Telemetry")).eq(true);
314302

315303
restoreMocks();
316304
});
317305

318306
it("should have seed tag in correlation-context header if feature flags use allocation seed", async () => {
319-
let correlationContext: string = "";
320-
const listKvCallback = (listOptions) => {
321-
correlationContext = listOptions?.requestOptions?.customHeaders[CORRELATION_CONTEXT_HEADER_NAME] ?? "";
322-
};
323-
324307
mockAppConfigurationClientListConfigurationSettings([[
325308
createMockedFeatureFlag("Alpha_1", { telemetry: {enabled: true} }),
326309
createMockedFeatureFlag("Alpha_2", { allocation: {seed: "123"} })
327-
]], listKvCallback);
310+
]]);
328311

329312
const settings = await load(createMockedConnectionString(fakeEndpoint), {
313+
clientOptions,
330314
featureFlagOptions: {
331315
enabled: true,
332316
selectors: [ {keyFilter: "*"} ],
@@ -337,48 +321,44 @@ describe("request tracing", function () {
337321
}
338322
});
339323

340-
expect(correlationContext).not.undefined;
341-
expect(correlationContext?.includes("RequestType=Startup")).eq(true);
324+
restoreMocks();
342325

343326
await sleepInMs(1_000 + 1_000);
344327
try {
345328
await settings.refresh();
346329
} catch { /* empty */ }
347330
expect(headerPolicy.headers).not.undefined;
331+
const correlationContext = headerPolicy.headers.get(CORRELATION_CONTEXT_HEADER_NAME);
348332
expect(correlationContext).not.undefined;
349-
expect(correlationContext?.includes("RequestType=Watch")).eq(true);
350-
expect(correlationContext?.includes("FFFeatures=Seed+Telemetry")).eq(true);
333+
expect(correlationContext.includes("RequestType=Watch")).eq(true);
334+
expect(correlationContext.includes("FFFeatures=Seed+Telemetry")).eq(true);
351335

352336
restoreMocks();
353337
});
354338

355339
it("should have AI tag in correlation-context header if key values use AI configuration", async () => {
356-
let correlationContext: string = "";
357-
const listKvCallback = (listOptions) => {
358-
correlationContext = listOptions?.requestOptions?.customHeaders[CORRELATION_CONTEXT_HEADER_NAME] ?? "";
359-
};
360-
361340
mockAppConfigurationClientListConfigurationSettings([[
362341
createMockedKeyValue({ contentType: "application/json; profile=\"https://azconfig.io/mime-profiles/ai/chat-completion\"" })
363-
]], listKvCallback);
342+
]]);
364343

365344
const settings = await load(createMockedConnectionString(fakeEndpoint), {
345+
clientOptions,
366346
refreshOptions: {
367347
enabled: true,
368348
refreshIntervalInMs: 1000
369349
}
370350
});
371351

372-
expect(correlationContext).not.undefined;
373-
expect(correlationContext?.includes("RequestType=Startup")).eq(true);
352+
restoreMocks();
374353

375354
await sleepInMs(1000 + 1);
376355
try {
377356
await settings.refresh();
378357
} catch { /* empty */ }
379358
expect(headerPolicy.headers).not.undefined;
359+
const correlationContext = headerPolicy.headers.get(CORRELATION_CONTEXT_HEADER_NAME);
380360
expect(correlationContext).not.undefined;
381-
expect(correlationContext?.includes("Features=AI+AICC")).eq(true);
361+
expect(correlationContext.includes("Features=AI+AICC")).eq(true);
382362

383363
restoreMocks();
384364
});

0 commit comments

Comments
 (0)