Skip to content

Commit

Permalink
feat: move logger into evaluateFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
nickybondarenko committed Nov 27, 2024
1 parent b872cb2 commit 9d2b009
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export interface ConfidenceOptions {

// @public
export interface Configuration {
// (undocumented)
readonly clientSecret: string;
readonly environment: 'client' | 'backend';
// Warning: (ae-forgotten-export) The symbol "EventSenderEngine" needs to be exported by the entry point index.d.ts
//
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/Confidence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Confidence', () => {

beforeEach(() => {
confidence = new Confidence({
clientSecret: 'secret',
timeout: 10,
environment: 'client',
logger: {},
Expand Down
15 changes: 9 additions & 6 deletions packages/sdk/src/Confidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export class Confidence implements EventSender, Trackable, FlagResolver {
value: defaultValue,
};
} else {
this.showLoggerLink(path, this.getContext());
evaluation = this.currentFlags.evaluate(path, defaultValue);
}
if (!this.currentFlags || !Value.equal(this.currentFlags.context, this.getContext())) {
Expand All @@ -313,13 +314,15 @@ export class Confidence implements EventSender, Trackable, FlagResolver {
getFlag(path: string, defaultValue: number): Promise<number>;
getFlag<T extends Value>(path: string, defaultValue: T): Promise<T>;
async getFlag<T extends Value>(path: string, defaultValue: any): Promise<T> {
const clientKey = this.config.clientSecret;
const flag = (await this.evaluateFlag(path, defaultValue)).value;
const context = this._context;
this.config.logger.debug?.(
`Resolve debug: https://app.confidence.spotify.com/flags/resolver-test?client-key=${clientKey}&flag=flags/${flag}&context=${context}`,
return (await this.evaluateFlag(path, defaultValue)).value;
}

private showLoggerLink(flag: string, context: Context) {
this.config.logger.info?.(
`Resolve debug: https://app.confidence.spotify.com/flags/resolver-test?client-key=${
this.config.clientSecret
}&flag=flags/${flag}&context=${JSON.stringify(context)}`,
);
return flag;
}

/**
Expand Down

0 comments on commit 9d2b009

Please sign in to comment.