Skip to content

Commit 5225630

Browse files
update
1 parent 4bc26de commit 5225630

File tree

2 files changed

+33
-46
lines changed

2 files changed

+33
-46
lines changed

src/requestTracing/FeatureFlagTracingOptions.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,44 +52,27 @@ export class FeatureFlagTracingOptions {
5252
}
5353

5454
createFeatureFiltersString(): string {
55-
if (!this.usesAnyFeatureFilter()) {
56-
return "";
57-
}
58-
59-
let result: string = "";
55+
const tags: string[] = [];
6056
if (this.usesCustomFilter) {
61-
result += CUSTOM_FILTER_KEY;
57+
tags.push(CUSTOM_FILTER_KEY);
6258
}
6359
if (this.usesTimeWindowFilter) {
64-
if (result !== "") {
65-
result += DELIMITER;
66-
}
67-
result += TIME_WINDOW_FILTER_KEY;
60+
tags.push(TIME_WINDOW_FILTER_KEY);
6861
}
6962
if (this.usesTargetingFilter) {
70-
if (result !== "") {
71-
result += DELIMITER;
72-
}
73-
result += TARGETING_FILTER_KEY;
63+
tags.push(TARGETING_FILTER_KEY);
7464
}
75-
return result;
65+
return tags.join(DELIMITER);
7666
}
7767

7868
createFeaturesString(): string {
79-
if (!this.usesAnyTracingFeature()) {
80-
return "";
81-
}
82-
83-
let result: string = "";
69+
const tags: string[] = [];
8470
if (this.usesSeed) {
85-
result += FF_SEED_USED_TAG;
71+
tags.push(FF_SEED_USED_TAG);
8672
}
8773
if (this.usesTelemetry) {
88-
if (result !== "") {
89-
result += DELIMITER;
90-
}
91-
result += FF_TELEMETRY_USED_TAG;
74+
tags.push(FF_TELEMETRY_USED_TAG);
9275
}
93-
return result;
76+
return tags.join(DELIMITER);
9477
}
9578
}

src/requestTracing/utils.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,13 @@ export function createCorrelationContextHeader(requestTracingOptions: RequestTra
130130
keyValues.set(FM_VERSION_KEY, requestTracingOptions.fmVersion);
131131
}
132132

133-
// Compact tags: Features=LB+AI+AICC...
134-
if (appConfigOptions?.loadBalancingEnabled || requestTracingOptions.aiConfigurationTracing?.usesAnyTracingFeature()) {
135-
const tags: string[] = [];
136-
if (appConfigOptions?.loadBalancingEnabled) {
137-
tags.push(LOAD_BALANCE_CONFIGURED_TAG);
138-
}
139-
if (requestTracingOptions.aiConfigurationTracing?.usesAIConfiguration) {
140-
tags.push(AI_CONFIGURATION_TAG);
141-
}
142-
if (requestTracingOptions.aiConfigurationTracing?.usesAIChatCompletionConfiguration) {
143-
tags.push(AI_CHAT_COMPLETION_CONFIGURATION_TAG);
144-
}
145-
146-
if (tags.length > 0) {
147-
keyValues.set(FEATURES_KEY, tags.join(DELIMITER));
148-
}
149-
}
133+
// Use compact tags for new tracing features: Features=LB+AI+AICC...
134+
keyValues.set(FEATURES_KEY, usesAnyTracingFeature(requestTracingOptions) ? createFeaturesString(requestTracingOptions) : undefined);
150135

151136
const contextParts: string[] = [];
152-
for (const [k, v] of keyValues) {
153-
if (v !== undefined) {
154-
contextParts.push(`${k}=${v}`);
137+
for (const [key, value] of keyValues) {
138+
if (value !== undefined) {
139+
contextParts.push(`${key}=${value}`);
155140
}
156141
}
157142
for (const tag of tags) {
@@ -167,6 +152,25 @@ export function requestTracingEnabled(): boolean {
167152
return !disabled;
168153
}
169154

155+
function usesAnyTracingFeature(requestTracingOptions: RequestTracingOptions): boolean {
156+
return (requestTracingOptions.appConfigOptions?.loadBalancingEnabled ?? false) ||
157+
(requestTracingOptions.aiConfigurationTracing?.usesAnyTracingFeature() ?? false);
158+
}
159+
160+
function createFeaturesString(requestTracingOptions: RequestTracingOptions): string {
161+
const tags: string[] = [];
162+
if (requestTracingOptions.appConfigOptions?.loadBalancingEnabled) {
163+
tags.push(LOAD_BALANCE_CONFIGURED_TAG);
164+
}
165+
if (requestTracingOptions.aiConfigurationTracing?.usesAIConfiguration) {
166+
tags.push(AI_CONFIGURATION_TAG);
167+
}
168+
if (requestTracingOptions.aiConfigurationTracing?.usesAIChatCompletionConfiguration) {
169+
tags.push(AI_CHAT_COMPLETION_CONFIGURATION_TAG);
170+
}
171+
return tags.join(DELIMITER);
172+
}
173+
170174
function getEnvironmentVariable(name: string) {
171175
// Make it compatible with non-Node.js runtime
172176
if (typeof process !== "undefined" && typeof process?.env === "object") {

0 commit comments

Comments
 (0)