Skip to content

Commit 57f4d72

Browse files
authored
Set entityId on flag evaluation (#234)
* set entityId on flag evaluation * bump version
1 parent 8cdad5e commit 57f4d72

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "4.13.0",
3+
"version": "4.13.1",
44
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
55
"main": "dist/index.js",
66
"files": [

src/client/eppo-client.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('EppoClient E2E test', () => {
7979
const mockFlag: Flag = {
8080
key: flagKey,
8181
enabled: true,
82+
entityId: 123,
8283
variationType: VariationType.STRING,
8384
variations: { a: variationA, b: variationB },
8485
allocations: [
@@ -195,6 +196,16 @@ describe('EppoClient E2E test', () => {
195196
client.setAssignmentLogger(mockLogger);
196197
expect(td.explain(mockLogger.logAssignment).callCount).toEqual(MAX_EVENT_QUEUE_SIZE);
197198
});
199+
200+
it('should log assignment event with entityId', () => {
201+
const mockLogger = td.object<IAssignmentLogger>();
202+
const client = new EppoClient({ flagConfigurationStore: storage });
203+
client.setAssignmentLogger(mockLogger);
204+
client.getStringAssignment(flagKey, 'subject-to-be-logged', {}, 'default-value');
205+
expect(td.explain(mockLogger.logAssignment).callCount).toEqual(1);
206+
const loggedAssignmentEvent = td.explain(mockLogger.logAssignment).calls[0].args[0];
207+
expect(loggedAssignmentEvent.entityId).toEqual(123);
208+
});
198209
});
199210

200211
describe('check type match', () => {

src/client/eppo-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ export default class EppoClient {
12871287
});
12881288
}
12891289

1290-
private maybeLogAssignment(result: FlagEvaluation & { entityId?: number }) {
1290+
private maybeLogAssignment(result: FlagEvaluation) {
12911291
const {
12921292
flagKey,
12931293
format,

src/client/eppo-precomputed-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export default class EppoPrecomputedClient {
237237
allocationKey: precomputedFlag.allocationKey ?? '',
238238
extraLogging: precomputedFlag.extraLogging ?? {},
239239
doLog: precomputedFlag.doLog,
240+
entityId: null,
240241
};
241242

242243
try {

src/evaluator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface FlagEvaluationWithoutDetails {
3030
extraLogging: Record<string, string>;
3131
// whether to log assignment event
3232
doLog: boolean;
33+
entityId: number | null;
3334
}
3435

3536
export interface FlagEvaluation extends FlagEvaluationWithoutDetails {
@@ -122,6 +123,7 @@ export class Evaluator {
122123
extraLogging: split.extraLogging ?? {},
123124
doLog: allocation.doLog,
124125
flagEvaluationDetails,
126+
entityId: flag.entityId ?? null,
125127
};
126128
}
127129
}
@@ -227,6 +229,7 @@ export function noneResult(
227229
extraLogging: {},
228230
doLog: false,
229231
flagEvaluationDetails,
232+
entityId: null,
230233
};
231234
}
232235

@@ -288,5 +291,6 @@ export function overrideResult(
288291
format: '',
289292
allocationKey: overrideAllocationKey,
290293
extraLogging: {},
294+
entityId: null,
291295
};
292296
}

0 commit comments

Comments
 (0)