Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,17 @@ describe('CliRepl', () => {
expect(apiEvents[0].properties.count).to.equal(1);
});

it('includes a statement about flushed telemetry in the log', async() => {
await cliRepl.start(await testServer.connectionString(), {});
const { logFilePath } = cliRepl.logWriter;
input.write('db.hello()\n');
input.write('exit\n');
await waitBus(cliRepl.bus, 'mongosh:closed');
const flushEntry = (await readReplLogfile(logFilePath)).find(entry => entry.id === 1_000_000_045);
expect(flushEntry.attr.flushError).to.equal(null);
expect(flushEntry.attr.flushDuration).to.be.a('number');
});

context('with a 5.0+ server', () => {
skipIfServerVersion(testServer, '<= 4.4');

Expand Down
16 changes: 14 additions & 2 deletions packages/cli-repl/src/cli-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,25 @@ class CliRepl {
}
this.closing = true;
const analytics = this.analytics;
let flushError: string | null = null;
let flushDuration: number | null = null;
if (analytics) {
const flushStart = Date.now();
try {
await promisify(analytics.flush.bind(analytics))();
} catch { /* ignore */ }
} catch (err: any) {
flushError = err.message;
} finally {
flushDuration = Date.now() - flushStart;
}
}
this.mongocryptdManager.close();
await this.logWriter?.flush?.();
// eslint-disable-next-line chai-friendly/no-unused-expressions
this.logWriter?.info('MONGOSH', mongoLogId(1_000_000_045), 'analytics', 'Flushed outstanding data', {
flushError,
flushDuration
});
await this.logWriter?.flush();
this.bus.emit('mongosh:closed');
}

Expand Down
2 changes: 2 additions & 0 deletions packages/logging/src/setup-logger-and-telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,6 @@ export function setupLoggerAndTelemetry(
error: ev.error.message
});
});

// NB: mongoLogId(1_000_000_045) is used in cli-repl itself
}