diff --git a/packages/server/src/client/internal/open-feature-client.ts b/packages/server/src/client/internal/open-feature-client.ts index 663e1bb3f..bd9a4e5a4 100644 --- a/packages/server/src/client/internal/open-feature-client.ts +++ b/packages/server/src/client/internal/open-feature-client.ts @@ -226,7 +226,7 @@ export class OpenFeatureClient implements Client { return this.evaluate(flagKey, this._provider.resolveObjectEvaluation, defaultValue, 'object', context, options); } - track(occurrenceKey: string, context: EvaluationContext, occurrenceDetails: TrackingEventDetails): void { + track(occurrenceKey: string, context: EvaluationContext = {}, occurrenceDetails: TrackingEventDetails = {}): void { try { this.shortCircuitIfNotReady(); diff --git a/packages/server/test/client.spec.ts b/packages/server/test/client.spec.ts index 69dc41fa5..b1db27412 100644 --- a/packages/server/test/client.spec.ts +++ b/packages/server/test/client.spec.ts @@ -859,6 +859,18 @@ describe('OpenFeatureClient', () => { }).not.toThrow(); }); + it('provide empty tracking details to provider if not supplied in call', async () => { + await OpenFeature.setProviderAndWait({ ...MOCK_PROVIDER }); + const client = OpenFeature.getClient(); + client.track(eventName); + + expect(MOCK_PROVIDER.track).toHaveBeenCalledWith( + eventName, + expect.any(Object), + expect.any(Object), + ); + }); + it('should call provider with correct context', async () => { await OpenFeature.setProviderAndWait({ ...MOCK_PROVIDER }); OpenFeature.setContext({ [globalContextKey]: globalContextValue }); diff --git a/packages/shared/src/provider/provider.ts b/packages/shared/src/provider/provider.ts index e964f1b8e..74ae8606f 100644 --- a/packages/shared/src/provider/provider.ts +++ b/packages/shared/src/provider/provider.ts @@ -133,5 +133,5 @@ export interface CommonProvider(flagKey, this._provider.resolveObjectEvaluation, defaultValue, 'object', options); } - track(occurrenceKey: string, occurrenceDetails: TrackingEventDetails): void { + track(occurrenceKey: string, occurrenceDetails: TrackingEventDetails = {}): void { try { this.shortCircuitIfNotReady(); diff --git a/packages/web/test/client.spec.ts b/packages/web/test/client.spec.ts index 381dd9b25..c67b593ab 100644 --- a/packages/web/test/client.spec.ts +++ b/packages/web/test/client.spec.ts @@ -655,6 +655,18 @@ describe('OpenFeatureClient', () => { }).not.toThrow(); }); + it('provide empty tracking details to provider if not supplied in call', async () => { + await OpenFeature.setProviderAndWait({ ...MOCK_PROVIDER }); + const client = OpenFeature.getClient(); + client.track(eventName); + + expect(MOCK_PROVIDER.track).toHaveBeenCalledWith( + eventName, + expect.any(Object), + expect.any(Object), + ); + }); + it('should no-op and not throw if provider throws', async () => { await OpenFeature.setProviderAndWait({ ...MOCK_PROVIDER,