Skip to content

Commit

Permalink
fix: add safe access to loggerProvider in session replay plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyang1520 committed Feb 6, 2025
1 parent 4282675 commit 73f88f0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/plugin-session-replay-browser/src/session-replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SessionReplayPlugin implements EnrichmentPlugin {

async setup(config: BrowserConfig) {
try {
config.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);
config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);

this.config = config;

Expand Down Expand Up @@ -66,7 +66,7 @@ export class SessionReplayPlugin implements EnrichmentPlugin {
experimental: this.options.experimental,
}).promise;
} catch (error) {
config.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);
config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);
}
}

Expand Down Expand Up @@ -109,7 +109,7 @@ export class SessionReplayPlugin implements EnrichmentPlugin {

return Promise.resolve(event);
} catch (error) {
this.config.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);
this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);
return Promise.resolve(event);
}
}
Expand All @@ -123,7 +123,7 @@ export class SessionReplayPlugin implements EnrichmentPlugin {
// @ts-ignore
this.config = null;
} catch (error) {
this.config.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);
this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);
}
}

Expand Down

0 comments on commit 73f88f0

Please sign in to comment.