Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions docs/js-client-sdk.loglevel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@eppo/js-client-sdk](./js-client-sdk.md) &gt; [LogLevel](./js-client-sdk.loglevel.md)

## LogLevel type
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New docs auto-generated for the externally exposed method and type for setting the SDK's log level


Valid log levels for the Eppo SDK logger.

**Signature:**

```typescript
export declare type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
```
37 changes: 37 additions & 0 deletions docs/js-client-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ This method should be called once on application startup.
Initializes the Eppo precomputed client with configuration parameters. This method should be called once on application startup.


</td></tr>
<tr><td>

[setLogLevel(level)](./js-client-sdk.setloglevel.md)


</td><td>

Sets the log level for the Eppo SDK logger globally. This affects all logging across the entire SDK, including both EppoJSClient and EppoPrecomputedJSClient instances.


</td></tr>
</tbody></table>

Expand Down Expand Up @@ -228,3 +239,29 @@ This interface is used for cases where precomputed assignments are available fro
</td></tr>
</tbody></table>

## Type Aliases

<table><thead><tr><th>

Type Alias


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[LogLevel](./js-client-sdk.loglevel.md)


</td><td>

Valid log levels for the Eppo SDK logger.


</td></tr>
</tbody></table>

54 changes: 54 additions & 0 deletions docs/js-client-sdk.setloglevel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@eppo/js-client-sdk](./js-client-sdk.md) &gt; [setLogLevel](./js-client-sdk.setloglevel.md)

## setLogLevel() function

Sets the log level for the Eppo SDK logger globally. This affects all logging across the entire SDK, including both EppoJSClient and EppoPrecomputedJSClient instances.

**Signature:**

```typescript
export declare function setLogLevel(level: LogLevel): void;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

level


</td><td>

[LogLevel](./js-client-sdk.loglevel.md)


</td><td>

The log level to set: - 'trace': Most verbose, logs everything - 'debug': Detailed debugging information - 'info': General informational messages - 'warn': Warning messages (default in production) - 'error': Error messages only - 'silent': Disable all logging


</td></tr>
</tbody></table>

**Returns:**

void

6 changes: 6 additions & 0 deletions js-client-sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ export interface IPrecomputedClientConfigSync {
throwOnFailedInitialization?: boolean;
}

// @public
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not supporting 'fatal' in this list?


// Warning: (ae-internal-missing-underscore) The name "NO_OP_EVENT_DISPATCHER" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
Expand All @@ -232,6 +235,9 @@ export function offlinePrecomputedInit(config: IPrecomputedClientConfigSync): Ep
// @public
export function precomputedInit(config: IPrecomputedClientConfig): Promise<EppoPrecomputedClient>;

// @public
export function setLogLevel(level: LogLevel): void;

// (No @packageDocumentation comment for this package)

```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/js-client-sdk",
"version": "3.17.0",
"version": "3.18.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping minor version because of new public method and type

"description": "Eppo SDK for client-side JavaScript applications",
"main": "dist/index.js",
"files": [
Expand Down Expand Up @@ -59,7 +59,7 @@
"webpack-cli": "^6.0.1"
},
"dependencies": {
"@eppo/js-client-sdk-common": "4.15.1",
"@eppo/js-client-sdk-common": "/tmp/packages/js-sdk-common",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will update once js-sdk-common #296 is merged

"@types/chrome": "^0.0.313",
"lz-string": "^1.5.0"
},
Expand Down
12 changes: 9 additions & 3 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1679,9 +1679,15 @@ describe('EppoClient config', () => {
});

expect(client).toBe(EppoPrecomputedJSClient.instance);
td.verify(applicationLogger.error('[Eppo SDK] Invalid precomputed configuration wire'), {
times: 1,
});
td.verify(
applicationLogger.error(
td.matchers.contains({ err: td.matchers.anything() }),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pino API (link) is to have the context object first.

'[Eppo SDK] Invalid precomputed configuration wire',
),
{
times: 1,
},
);
});
});

Expand Down
68 changes: 52 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ import LocalStorageBackedNamedEventQueue from './events/local-storage-backed-nam
import { IClientConfig, IPrecomputedClientConfig } from './i-client-config';
import { sdkName, sdkVersion } from './sdk-data';

/**
* Valid log levels for the Eppo SDK logger.
* @public
*/
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';

/**
* Configuration interface for synchronous client initialization.
* @public
Expand Down Expand Up @@ -424,12 +430,12 @@ export class EppoJSClient extends EppoClient {

return ConfigLoaderStatus.COMPLETED;
})
.catch((e) => {
.catch((err) => {
applicationLogger.warn(
{ err },
'Eppo SDK encountered an error initializing from the configuration store',
e,
);
initFromConfigStoreError = e;
initFromConfigStoreError = err;
return ConfigLoaderStatus.FAILED;
})
.then((status) => {
Expand Down Expand Up @@ -457,10 +463,13 @@ export class EppoJSClient extends EppoClient {
return ConfigLoaderStatus.DID_NOT_PRODUCE;
}
})
.catch((e) => {
applicationLogger.warn('Eppo SDK encountered an error initializing from fetching', e);
.catch((err) => {
applicationLogger.warn(
{ err },
'Eppo SDK encountered an error initializing from fetching',
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
initFromFetchError = e;
initFromFetchError = err;
return ConfigLoaderStatus.FAILED;
})
.then((status) => {
Expand Down Expand Up @@ -501,7 +510,7 @@ export class EppoJSClient extends EppoClient {
? initFromConfigStoreError
: new Error('Eppo SDK: No configuration source produced a valid configuration');
}
applicationLogger.debug('Initialization source', initializationSource);
applicationLogger.debug(`Initialization source: ${initializationSource}`);
} catch (error: unknown) {
initializationError = error instanceof Error ? error : new Error(String(error));
}
Expand Down Expand Up @@ -544,7 +553,10 @@ export class EppoJSClient extends EppoClient {
memoryOnlyConfigurationStore
.setEntries(config.flagsConfiguration)
.catch((err) =>
applicationLogger.warn('Error setting flags for memory-only configuration store', err),
applicationLogger.warn(
{ err },
'Error setting flags for memory-only configuration store',
),
);
this.setFlagConfigurationStore(memoryOnlyConfigurationStore);

Expand Down Expand Up @@ -591,12 +603,13 @@ export class EppoJSClient extends EppoClient {
forceMemoryOnly: true,
});
this.useCustomAssignmentCache(assignmentCache);
} catch (error) {
} catch (err) {
applicationLogger.warn(
{ err },
'Eppo SDK encountered an error initializing, assignment calls will return the default value and not be logged',
);
if (throwOnFailedInitialization) {
throw error;
throw err;
}
}

Expand Down Expand Up @@ -893,12 +906,12 @@ export function offlinePrecomputedInit(
try {
configurationWire = JSON.parse(config.precomputedConfiguration);
if (!configurationWire.precomputed) throw new Error();
} catch (error) {
} catch (err) {
const errorMessage = 'Invalid precomputed configuration wire';
if (throwOnFailedInitialization) {
throw new Error(errorMessage);
}
applicationLogger.error(`[Eppo SDK] ${errorMessage}`);
applicationLogger.error({ err }, `[Eppo SDK] ${errorMessage}`);
return EppoPrecomputedJSClient.instance;
}
const { subjectKey, subjectAttributes, response } = configurationWire.precomputed;
Expand All @@ -909,15 +922,18 @@ export function offlinePrecomputedInit(
memoryOnlyPrecomputedStore
.setEntries(parsedResponse.flags)
.catch((err) =>
applicationLogger.warn('Error setting precomputed assignments for memory-only store', err),
applicationLogger.warn(
{ err },
'Error setting precomputed assignments for memory-only store',
),
);
memoryOnlyPrecomputedStore.salt = parsedResponse.salt;

const memoryOnlyPrecomputedBanditStore = precomputedBanditStoreFactory();
memoryOnlyPrecomputedBanditStore
.setEntries(parsedResponse.bandits)
.catch((err) =>
applicationLogger.warn('Error setting precomputed bandits for memory-only store', err),
applicationLogger.warn({ err }, 'Error setting precomputed bandits for memory-only store'),
);
memoryOnlyPrecomputedBanditStore.salt = parsedResponse.salt;

Expand Down Expand Up @@ -963,12 +979,13 @@ export function offlinePrecomputedInit(
EppoPrecomputedJSClient.instance.setBanditLogger(config.banditLogger);
}
EppoPrecomputedJSClient.instance.useCustomAssignmentCache(assignmentCache);
} catch (error) {
} catch (err) {
applicationLogger.warn(
{ err },
'[Eppo SDK] Encountered an error initializing precomputed client, assignment calls will return the default value and not be logged',
);
if (throwOnFailedInitialization) {
throw error;
throw err;
}
}

Expand All @@ -994,6 +1011,25 @@ export function getPrecomputedInstance(): EppoPrecomputedClient {
return EppoPrecomputedJSClient.instance;
}

/**
* Sets the log level for the Eppo SDK logger globally.
* This affects all logging across the entire SDK, including both
* EppoJSClient and EppoPrecomputedJSClient instances.
*
* @param level - The log level to set:
* - 'trace': Most verbose, logs everything
* - 'debug': Detailed debugging information
* - 'info': General informational messages
* - 'warn': Warning messages (default in production)
* - 'error': Error messages only
* - 'silent': Disable all logging
*
* @public
*/
export function setLogLevel(level: LogLevel): void {
applicationLogger.level = level;
}

function newEventDispatcher(
sdkKey: string,
config: IClientConfig['eventTracking'] = {},
Expand Down
4 changes: 2 additions & 2 deletions src/isolatable-hybrid.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class IsolatableHybridConfigurationStore<T> extends HybridConfigurationSt
try {
// always update persistent store
await this.persistentStore.setEntries(entries);
} catch (e) {
applicationLogger.warn(`Failed to setEntries on persistent store: ${e}`);
} catch (err) {
applicationLogger.warn({ err }, `Failed to setEntries on persistent store`);
}
}

Expand Down
Loading
Loading