Skip to content

Commit ccb937a

Browse files
authored
Fix browser logging issues (#257)
* conform to pino interface * expose set log level * bump version * use updated common
1 parent f7c1619 commit ccb937a

9 files changed

+219
-44
lines changed

docs/js-client-sdk.loglevel.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@eppo/js-client-sdk](./js-client-sdk.md) &gt; [LogLevel](./js-client-sdk.loglevel.md)
4+
5+
## LogLevel type
6+
7+
Valid log levels for the Eppo SDK logger.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export declare type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
13+
```

docs/js-client-sdk.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ This method should be called once on application startup.
164164
Initializes the Eppo precomputed client with configuration parameters. This method should be called once on application startup.
165165

166166

167+
</td></tr>
168+
<tr><td>
169+
170+
[setLogLevel(level)](./js-client-sdk.setloglevel.md)
171+
172+
173+
</td><td>
174+
175+
Sets the log level for the Eppo SDK logger globally. This affects all logging across the entire SDK, including both EppoJSClient and EppoPrecomputedJSClient instances.
176+
177+
167178
</td></tr>
168179
</tbody></table>
169180

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

242+
## Type Aliases
243+
244+
<table><thead><tr><th>
245+
246+
Type Alias
247+
248+
249+
</th><th>
250+
251+
Description
252+
253+
254+
</th></tr></thead>
255+
<tbody><tr><td>
256+
257+
[LogLevel](./js-client-sdk.loglevel.md)
258+
259+
260+
</td><td>
261+
262+
Valid log levels for the Eppo SDK logger.
263+
264+
265+
</td></tr>
266+
</tbody></table>
267+

docs/js-client-sdk.setloglevel.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@eppo/js-client-sdk](./js-client-sdk.md) &gt; [setLogLevel](./js-client-sdk.setloglevel.md)
4+
5+
## setLogLevel() function
6+
7+
Sets the log level for the Eppo SDK logger globally. This affects all logging across the entire SDK, including both EppoJSClient and EppoPrecomputedJSClient instances.
8+
9+
**Signature:**
10+
11+
```typescript
12+
export declare function setLogLevel(level: LogLevel): void;
13+
```
14+
15+
## Parameters
16+
17+
<table><thead><tr><th>
18+
19+
Parameter
20+
21+
22+
</th><th>
23+
24+
Type
25+
26+
27+
</th><th>
28+
29+
Description
30+
31+
32+
</th></tr></thead>
33+
<tbody><tr><td>
34+
35+
level
36+
37+
38+
</td><td>
39+
40+
[LogLevel](./js-client-sdk.loglevel.md)
41+
42+
43+
</td><td>
44+
45+
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
46+
47+
48+
</td></tr>
49+
</tbody></table>
50+
51+
**Returns:**
52+
53+
void
54+

js-client-sdk.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ export interface IPrecomputedClientConfigSync {
216216
throwOnFailedInitialization?: boolean;
217217
}
218218

219+
// @public
220+
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
221+
219222
// Warning: (ae-internal-missing-underscore) The name "NO_OP_EVENT_DISPATCHER" should be prefixed with an underscore because the declaration is marked as @internal
220223
//
221224
// @internal (undocumented)
@@ -232,6 +235,9 @@ export function offlinePrecomputedInit(config: IPrecomputedClientConfigSync): Ep
232235
// @public
233236
export function precomputedInit(config: IPrecomputedClientConfig): Promise<EppoPrecomputedClient>;
234237

238+
// @public
239+
export function setLogLevel(level: LogLevel): void;
240+
235241
// (No @packageDocumentation comment for this package)
236242

237243
```

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk",
3-
"version": "3.17.0",
3+
"version": "3.18.0",
44
"description": "Eppo SDK for client-side JavaScript applications",
55
"main": "dist/index.js",
66
"files": [
@@ -59,7 +59,7 @@
5959
"webpack-cli": "^6.0.1"
6060
},
6161
"dependencies": {
62-
"@eppo/js-client-sdk-common": "4.15.1",
62+
"@eppo/js-client-sdk-common": "4.15.3",
6363
"@types/chrome": "^0.0.313",
6464
"lz-string": "^1.5.0"
6565
},

src/index.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,9 +1679,15 @@ describe('EppoClient config', () => {
16791679
});
16801680

16811681
expect(client).toBe(EppoPrecomputedJSClient.instance);
1682-
td.verify(applicationLogger.error('[Eppo SDK] Invalid precomputed configuration wire'), {
1683-
times: 1,
1684-
});
1682+
td.verify(
1683+
applicationLogger.error(
1684+
td.matchers.contains({ err: td.matchers.anything() }),
1685+
'[Eppo SDK] Invalid precomputed configuration wire',
1686+
),
1687+
{
1688+
times: 1,
1689+
},
1690+
);
16851691
});
16861692
});
16871693

src/index.ts

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ import LocalStorageBackedNamedEventQueue from './events/local-storage-backed-nam
4848
import { IClientConfig, IPrecomputedClientConfig } from './i-client-config';
4949
import { sdkName, sdkVersion } from './sdk-data';
5050

51+
/**
52+
* Valid log levels for the Eppo SDK logger.
53+
* @public
54+
*/
55+
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
56+
5157
/**
5258
* Configuration interface for synchronous client initialization.
5359
* @public
@@ -424,12 +430,12 @@ export class EppoJSClient extends EppoClient {
424430

425431
return ConfigLoaderStatus.COMPLETED;
426432
})
427-
.catch((e) => {
433+
.catch((err) => {
428434
applicationLogger.warn(
435+
{ err },
429436
'Eppo SDK encountered an error initializing from the configuration store',
430-
e,
431437
);
432-
initFromConfigStoreError = e;
438+
initFromConfigStoreError = err;
433439
return ConfigLoaderStatus.FAILED;
434440
})
435441
.then((status) => {
@@ -457,10 +463,13 @@ export class EppoJSClient extends EppoClient {
457463
return ConfigLoaderStatus.DID_NOT_PRODUCE;
458464
}
459465
})
460-
.catch((e) => {
461-
applicationLogger.warn('Eppo SDK encountered an error initializing from fetching', e);
466+
.catch((err) => {
467+
applicationLogger.warn(
468+
{ err },
469+
'Eppo SDK encountered an error initializing from fetching',
470+
);
462471
// eslint-disable-next-line @typescript-eslint/no-unused-vars
463-
initFromFetchError = e;
472+
initFromFetchError = err;
464473
return ConfigLoaderStatus.FAILED;
465474
})
466475
.then((status) => {
@@ -501,7 +510,7 @@ export class EppoJSClient extends EppoClient {
501510
? initFromConfigStoreError
502511
: new Error('Eppo SDK: No configuration source produced a valid configuration');
503512
}
504-
applicationLogger.debug('Initialization source', initializationSource);
513+
applicationLogger.debug(`Initialization source: ${initializationSource}`);
505514
} catch (error: unknown) {
506515
initializationError = error instanceof Error ? error : new Error(String(error));
507516
}
@@ -544,7 +553,10 @@ export class EppoJSClient extends EppoClient {
544553
memoryOnlyConfigurationStore
545554
.setEntries(config.flagsConfiguration)
546555
.catch((err) =>
547-
applicationLogger.warn('Error setting flags for memory-only configuration store', err),
556+
applicationLogger.warn(
557+
{ err },
558+
'Error setting flags for memory-only configuration store',
559+
),
548560
);
549561
this.setFlagConfigurationStore(memoryOnlyConfigurationStore);
550562

@@ -591,12 +603,13 @@ export class EppoJSClient extends EppoClient {
591603
forceMemoryOnly: true,
592604
});
593605
this.useCustomAssignmentCache(assignmentCache);
594-
} catch (error) {
606+
} catch (err) {
595607
applicationLogger.warn(
608+
{ err },
596609
'Eppo SDK encountered an error initializing, assignment calls will return the default value and not be logged',
597610
);
598611
if (throwOnFailedInitialization) {
599-
throw error;
612+
throw err;
600613
}
601614
}
602615

@@ -893,12 +906,12 @@ export function offlinePrecomputedInit(
893906
try {
894907
configurationWire = JSON.parse(config.precomputedConfiguration);
895908
if (!configurationWire.precomputed) throw new Error();
896-
} catch (error) {
909+
} catch (err) {
897910
const errorMessage = 'Invalid precomputed configuration wire';
898911
if (throwOnFailedInitialization) {
899912
throw new Error(errorMessage);
900913
}
901-
applicationLogger.error(`[Eppo SDK] ${errorMessage}`);
914+
applicationLogger.error({ err }, `[Eppo SDK] ${errorMessage}`);
902915
return EppoPrecomputedJSClient.instance;
903916
}
904917
const { subjectKey, subjectAttributes, response } = configurationWire.precomputed;
@@ -909,15 +922,18 @@ export function offlinePrecomputedInit(
909922
memoryOnlyPrecomputedStore
910923
.setEntries(parsedResponse.flags)
911924
.catch((err) =>
912-
applicationLogger.warn('Error setting precomputed assignments for memory-only store', err),
925+
applicationLogger.warn(
926+
{ err },
927+
'Error setting precomputed assignments for memory-only store',
928+
),
913929
);
914930
memoryOnlyPrecomputedStore.salt = parsedResponse.salt;
915931

916932
const memoryOnlyPrecomputedBanditStore = precomputedBanditStoreFactory();
917933
memoryOnlyPrecomputedBanditStore
918934
.setEntries(parsedResponse.bandits)
919935
.catch((err) =>
920-
applicationLogger.warn('Error setting precomputed bandits for memory-only store', err),
936+
applicationLogger.warn({ err }, 'Error setting precomputed bandits for memory-only store'),
921937
);
922938
memoryOnlyPrecomputedBanditStore.salt = parsedResponse.salt;
923939

@@ -963,12 +979,13 @@ export function offlinePrecomputedInit(
963979
EppoPrecomputedJSClient.instance.setBanditLogger(config.banditLogger);
964980
}
965981
EppoPrecomputedJSClient.instance.useCustomAssignmentCache(assignmentCache);
966-
} catch (error) {
982+
} catch (err) {
967983
applicationLogger.warn(
984+
{ err },
968985
'[Eppo SDK] Encountered an error initializing precomputed client, assignment calls will return the default value and not be logged',
969986
);
970987
if (throwOnFailedInitialization) {
971-
throw error;
988+
throw err;
972989
}
973990
}
974991

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

1014+
/**
1015+
* Sets the log level for the Eppo SDK logger globally.
1016+
* This affects all logging across the entire SDK, including both
1017+
* EppoJSClient and EppoPrecomputedJSClient instances.
1018+
*
1019+
* @param level - The log level to set:
1020+
* - 'trace': Most verbose, logs everything
1021+
* - 'debug': Detailed debugging information
1022+
* - 'info': General informational messages
1023+
* - 'warn': Warning messages (default in production)
1024+
* - 'error': Error messages only
1025+
* - 'silent': Disable all logging
1026+
*
1027+
* @public
1028+
*/
1029+
export function setLogLevel(level: LogLevel): void {
1030+
applicationLogger.level = level;
1031+
}
1032+
9971033
function newEventDispatcher(
9981034
sdkKey: string,
9991035
config: IClientConfig['eventTracking'] = {},

src/isolatable-hybrid.store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class IsolatableHybridConfigurationStore<T> extends HybridConfigurationSt
2929
try {
3030
// always update persistent store
3131
await this.persistentStore.setEntries(entries);
32-
} catch (e) {
33-
applicationLogger.warn(`Failed to setEntries on persistent store: ${e}`);
32+
} catch (err) {
33+
applicationLogger.warn({ err }, `Failed to setEntries on persistent store`);
3434
}
3535
}
3636

0 commit comments

Comments
 (0)