Skip to content

fix(browser): Ensure logs are flushed when sendClientReports=false #16351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Changes from all 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
30 changes: 15 additions & 15 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,41 +85,41 @@ export class BrowserClient extends Client<BrowserClientOptions> {

super(opts);

// eslint-disable-next-line @typescript-eslint/no-this-alias
const client = this;
const { sendDefaultPii, _experiments } = client._options;
const { sendDefaultPii, sendClientReports, _experiments } = this._options;
const enableLogs = _experiments?.enableLogs;

if (opts.sendClientReports && WINDOW.document) {
if (WINDOW.document && (sendClientReports || enableLogs)) {
WINDOW.document.addEventListener('visibilitychange', () => {
if (WINDOW.document.visibilityState === 'hidden') {
this._flushOutcomes();
if (sendClientReports) {
this._flushOutcomes();
}
if (enableLogs) {
_INTERNAL_flushLogsBuffer(client);
_INTERNAL_flushLogsBuffer(this);
}
}
});
}

if (enableLogs) {
client.on('flush', () => {
_INTERNAL_flushLogsBuffer(client);
this.on('flush', () => {
_INTERNAL_flushLogsBuffer(this);
});

client.on('afterCaptureLog', () => {
if (client._logFlushIdleTimeout) {
clearTimeout(client._logFlushIdleTimeout);
this.on('afterCaptureLog', () => {
if (this._logFlushIdleTimeout) {
clearTimeout(this._logFlushIdleTimeout);
}

client._logFlushIdleTimeout = setTimeout(() => {
_INTERNAL_flushLogsBuffer(client);
this._logFlushIdleTimeout = setTimeout(() => {
_INTERNAL_flushLogsBuffer(this);
}, DEFAULT_FLUSH_INTERVAL);
});
}

if (sendDefaultPii) {
client.on('postprocessEvent', addAutoIpAddressToUser);
client.on('beforeSendSession', addAutoIpAddressToSession);
this.on('postprocessEvent', addAutoIpAddressToUser);
this.on('beforeSendSession', addAutoIpAddressToSession);
}
}

Expand Down
Loading