Skip to content

Commit 8ac0001

Browse files
committed
Include logging for format
1 parent d7c39cd commit 8ac0001

10 files changed

+66
-6
lines changed

src/client/eppo-client.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,13 @@ export default class EppoClient {
839839
'FLAG_UNRECOGNIZED_OR_DISABLED',
840840
`Unrecognized or disabled flag: ${flagKey}`,
841841
);
842-
return noneResult(flagKey, subjectKey, subjectAttributes, flagEvaluationDetails);
842+
return noneResult(
843+
flagKey,
844+
subjectKey,
845+
subjectAttributes,
846+
flagEvaluationDetails,
847+
configDetails.configFormat,
848+
);
843849
}
844850

845851
if (!checkTypeMatch(expectedVariationType, flag.variationType)) {
@@ -849,7 +855,13 @@ export default class EppoClient {
849855
'TYPE_MISMATCH',
850856
errorMessage,
851857
);
852-
return noneResult(flagKey, subjectKey, subjectAttributes, flagEvaluationDetails);
858+
return noneResult(
859+
flagKey,
860+
subjectKey,
861+
subjectAttributes,
862+
flagEvaluationDetails,
863+
configDetails.configFormat,
864+
);
853865
}
854866
throw new TypeError(errorMessage);
855867
}
@@ -861,7 +873,13 @@ export default class EppoClient {
861873
'FLAG_UNRECOGNIZED_OR_DISABLED',
862874
`Unrecognized or disabled flag: ${flagKey}`,
863875
);
864-
return noneResult(flagKey, subjectKey, subjectAttributes, flagEvaluationDetails);
876+
return noneResult(
877+
flagKey,
878+
subjectKey,
879+
subjectAttributes,
880+
flagEvaluationDetails,
881+
configDetails.configFormat,
882+
);
865883
}
866884

867885
const result = this.evaluator.evaluateFlag(
@@ -904,6 +922,7 @@ export default class EppoClient {
904922
configFetchedAt: this.flagConfigurationStore.getConfigFetchedAt() ?? '',
905923
configPublishedAt: this.flagConfigurationStore.getConfigPublishedAt() ?? '',
906924
configEnvironment: this.flagConfigurationStore.getEnvironment() ?? { name: '' },
925+
configFormat: this.flagConfigurationStore.getFormat() ?? '',
907926
};
908927
}
909928

src/client/eppo-precomputed-client.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,18 @@ describe('EppoPrecomputedClient E2E test', () => {
613613
);
614614
});
615615
});
616+
617+
it('logs variation assignment with format from precomputed flags response', () => {
618+
const mockLogger = td.object<IAssignmentLogger>();
619+
storage.setEntries({ [precomputedFlagKey]: mockPrecomputedFlag });
620+
const client = new EppoPrecomputedClient(storage);
621+
client.setAssignmentLogger(mockLogger);
622+
623+
client.getStringAssignment(precomputedFlagKey, 'default');
624+
625+
expect(td.explain(mockLogger.logAssignment).callCount).toEqual(1);
626+
const loggedEvent = td.explain(mockLogger.logAssignment).calls[0].args[0];
627+
628+
expect(loggedEvent.format).toEqual('PRECOMPUTED');
629+
});
616630
});

src/client/eppo-precomputed-client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { decodePrecomputedFlag } from '../decoding';
1818
import { FlagEvaluationWithoutDetails } from '../evaluator';
1919
import FetchHttpClient from '../http-client';
20-
import { PrecomputedFlag } from '../interfaces';
20+
import { FormatEnum, PrecomputedFlag } from '../interfaces';
2121
import { getMD5Hash } from '../obfuscation';
2222
import initPoller, { IPoller } from '../poller';
2323
import PrecomputedRequestor from '../precomputed-requestor';
@@ -151,6 +151,7 @@ export default class EppoPrecomputedClient {
151151

152152
const result: FlagEvaluationWithoutDetails = {
153153
flagKey,
154+
format: this.precomputedFlagStore.getFormat() ?? '',
154155
subjectKey: this.precomputedFlagsRequestParameters?.precompute.subjectKey ?? '',
155156
subjectAttributes: this.precomputedFlagsRequestParameters?.precompute.subjectAttributes ?? {},
156157
variation: {
@@ -225,19 +226,21 @@ export default class EppoPrecomputedClient {
225226
eventsToFlush.forEach((event) => {
226227
try {
227228
logFunction(event);
229+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
228230
} catch (error: any) {
229231
logger.error(`[Eppo SDK] Error flushing event to logger: ${error.message}`);
230232
}
231233
});
232234
}
233235

234236
private logAssignment(result: FlagEvaluationWithoutDetails) {
235-
const { flagKey, subjectKey, allocationKey, subjectAttributes, variation } = result;
237+
const { flagKey, subjectKey, allocationKey, subjectAttributes, variation, format } = result;
236238
const event: IAssignmentEvent = {
237239
...(result.extraLogging ?? {}),
238240
allocation: allocationKey ?? null,
239241
experiment: allocationKey ? `${flagKey}-${allocationKey}` : null,
240242
featureFlag: flagKey,
243+
format,
241244
variation: variation?.key ?? null,
242245
subject: subjectKey,
243246
timestamp: new Date().toISOString(),
@@ -272,6 +275,7 @@ export default class EppoPrecomputedClient {
272275
allocationKey: allocationKey ?? '__eppo_no_allocation',
273276
variationKey: variation?.key ?? '__eppo_no_variation',
274277
});
278+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
275279
} catch (error: any) {
276280
logger.error(`[Eppo SDK] Error logging assignment event: ${error.message}`);
277281
}

src/configuration-requestor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default class ConfigurationRequestor {
2424
entries: configResponse.flags,
2525
environment: configResponse.environment,
2626
createdAt: configResponse.createdAt,
27+
format: configResponse.format,
2728
});
2829

2930
const flagsHaveBandits = Object.keys(configResponse.bandits ?? {}).length > 0;
@@ -38,6 +39,7 @@ export default class ConfigurationRequestor {
3839
entries: banditVariations,
3940
environment: configResponse.environment,
4041
createdAt: configResponse.createdAt,
42+
format: configResponse.format,
4143
});
4244

4345
// TODO: different polling intervals for bandit parameters
@@ -51,6 +53,7 @@ export default class ConfigurationRequestor {
5153
entries: banditResponse.bandits,
5254
environment: configResponse.environment,
5355
createdAt: configResponse.createdAt,
56+
format: configResponse.format,
5457
});
5558
}
5659
}

src/configuration-store/configuration-store-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export async function hydrateConfigurationStore<T extends Entry>(
1616
entries: Record<string, T>;
1717
environment: Environment;
1818
createdAt: string;
19+
format: string;
1920
},
2021
): Promise<void> {
2122
if (configurationStore) {
@@ -24,6 +25,7 @@ export async function hydrateConfigurationStore<T extends Entry>(
2425
configurationStore.setEnvironment(response.environment);
2526
configurationStore.setConfigFetchedAt(new Date().toISOString());
2627
configurationStore.setConfigPublishedAt(response.createdAt);
28+
configurationStore.setFormat(response.format);
2729
}
2830
}
2931
}

src/configuration-store/configuration-store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export interface IConfigurationStore<T> {
3636
setConfigFetchedAt(configFetchedAt: string): void;
3737
getConfigPublishedAt(): string | null;
3838
setConfigPublishedAt(configPublishedAt: string): void;
39+
getFormat(): string | null;
40+
setFormat(format: string): void;
3941
}
4042

4143
export interface ISyncStore<T> {

src/configuration-store/memory.store.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class MemoryOnlyConfigurationStore<T> implements IConfigurationStore<T> {
3434
private configFetchedAt: string | null = null;
3535
private configPublishedAt: string | null = null;
3636
private environment: Environment | null = null;
37-
37+
private format: string | null = null;
3838
init(): Promise<void> {
3939
this.initialized = true;
4040
return Promise.resolve();
@@ -89,4 +89,12 @@ export class MemoryOnlyConfigurationStore<T> implements IConfigurationStore<T> {
8989
public setConfigPublishedAt(configPublishedAt: string): void {
9090
this.configPublishedAt = configPublishedAt;
9191
}
92+
93+
public getFormat(): string | null {
94+
return this.format;
95+
}
96+
97+
public setFormat(format: string): void {
98+
this.format = format;
99+
}
92100
}

src/evaluator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Attributes } from './types';
2222

2323
export interface FlagEvaluationWithoutDetails {
2424
flagKey: string;
25+
format: string;
2526
subjectKey: string;
2627
subjectAttributes: Attributes;
2728
allocationKey: string | null;
@@ -65,6 +66,7 @@ export class Evaluator {
6566
'FLAG_UNRECOGNIZED_OR_DISABLED',
6667
`Unrecognized or disabled flag: ${flag.key}`,
6768
),
69+
configDetails.configFormat,
6870
);
6971
}
7072

@@ -111,6 +113,7 @@ export class Evaluator {
111113
.build(flagEvaluationCode, flagEvaluationDescription);
112114
return {
113115
flagKey: flag.key,
116+
format: configDetails.configFormat,
114117
subjectKey,
115118
subjectAttributes,
116119
allocationKey: allocation.key,
@@ -135,6 +138,7 @@ export class Evaluator {
135138
'DEFAULT_ALLOCATION_NULL',
136139
'No allocations matched. Falling back to "Default Allocation", serving NULL',
137140
),
141+
configDetails.configFormat,
138142
);
139143
} catch (err: any) {
140144
const flagEvaluationDetails = flagEvaluationDetailsBuilder.gracefulBuild(
@@ -206,9 +210,11 @@ export function noneResult(
206210
subjectKey: string,
207211
subjectAttributes: Attributes,
208212
flagEvaluationDetails: IFlagEvaluationDetails,
213+
format: string,
209214
): FlagEvaluation {
210215
return {
211216
flagKey,
217+
format,
212218
subjectKey,
213219
subjectAttributes,
214220
allocationKey: null,

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface ConfigDetails {
4646
configFetchedAt: string;
4747
configPublishedAt: string;
4848
configEnvironment: Environment;
49+
configFormat: string;
4950
}
5051

5152
export interface Flag {

src/precomputed-requestor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class PrecomputedFlagRequestor {
2020
entries: precomputedResponse.flags,
2121
environment: precomputedResponse.environment,
2222
createdAt: precomputedResponse.createdAt,
23+
format: precomputedResponse.format,
2324
});
2425
}
2526
}

0 commit comments

Comments
 (0)