Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/node-sdk-emit-evaluation-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reflag/node-sdk": patch
---

Honor `emitEvaluationEvents: false` by suppressing evaluation `check` and `check-config` events emitted during flag access.
19 changes: 17 additions & 2 deletions packages/node-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class ReflagClient {
flagsFallbackProviderContext: FlagsFallbackProviderContext;
flagOverrides: FlagOverridesFn;
offline: boolean;
emitEvaluationEvents: boolean;
configFile?: string;
flagsFetchRetries: number;
fetchTimeoutMs: number;
Expand Down Expand Up @@ -357,6 +358,11 @@ export class ReflagClient {
typeof options.configFile === "string",
"configFile must be a string",
);
ok(
options.emitEvaluationEvents === undefined ||
typeof options.emitEvaluationEvents === "boolean",
"emitEvaluationEvents must be a boolean",
);

ok(
options.flagsFetchRetries === undefined ||
Expand Down Expand Up @@ -486,6 +492,7 @@ export class ReflagClient {

this._config = {
offline,
emitEvaluationEvents: config.emitEvaluationEvents ?? true,
apiBaseUrl: (config.apiBaseUrl ?? config.host) || API_BASE_URL,
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -1532,7 +1539,11 @@ export class ReflagClient {

return {
get isEnabled() {
if (enableTracking && enableChecks) {
if (
enableTracking &&
enableChecks &&
client._config.emitEvaluationEvents
) {
client._warnMissingFlagContextFields(context, flag);

void client
Expand All @@ -1555,7 +1566,11 @@ export class ReflagClient {
return flag.isEnabled ?? false;
},
get config() {
if (enableTracking && enableChecks) {
if (
enableTracking &&
enableChecks &&
client._config.emitEvaluationEvents
) {
client._warnMissingFlagContextFields(context, flag);

void client
Expand Down
31 changes: 31 additions & 0 deletions packages/node-sdk/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,37 @@
]);
});

it("does not emit evaluation events when emitEvaluationEvents is false", async () => {
const client = new ReflagClient({

Check warning on line 1641 in packages/node-sdk/test/client.test.ts

View workflow job for this annotation

GitHub Actions / Build & Test

eslint(no-shadow)

'client' is already declared in the upper scope.
...validOptions,
emitEvaluationEvents: false,
});
const context = {
company,
user,
other: otherContext,
};

await client.initialize();
const flag = client.getFlag(context, "flag1");

expect(flag.isEnabled).toBe(true);
expect(flag.config).toEqual({
key: "config-1",
payload: {
something: "else",
},
});

Check warning on line 1660 in packages/node-sdk/test/client.test.ts

View workflow job for this annotation

GitHub Actions / Build & Test

eslint(no-shadow)

'client' is already declared in the upper scope.

await client.flush();

const evaluationEvents = httpClient.post.mock.calls
.flatMap((call) => call[2])
.filter((event) => event.type === "feature-flag-event");

Check warning on line 1666 in packages/node-sdk/test/client.test.ts

View workflow job for this annotation

GitHub Actions / Build & Test

eslint(no-shadow)

'event' is already declared in the upper scope.

expect(evaluationEvents).toStrictEqual([]);
});

it("sends events for unknown flags", async () => {
const context: Context = {
company,
Expand All @@ -1651,7 +1682,7 @@
// trigger `check` event
expect(flag.isEnabled).toBe(false);
await flag.track();
await client.flush();

Check warning on line 1685 in packages/node-sdk/test/client.test.ts

View workflow job for this annotation

GitHub Actions / Build & Test

eslint(no-shadow)

'event' is already declared in the upper scope.

const checkEvents = httpClient.post.mock.calls
.flatMap((call) => call[2])
Expand Down
Loading