Skip to content

Commit 1e102d1

Browse files
committed
flush
1 parent d564b18 commit 1e102d1

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

packages/core/src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
445445
*/
446446
// @ts-expect-error - PromiseLike is a subset of Promise
447447
public async close(timeout?: number): PromiseLike<boolean> {
448+
_INTERNAL_flushLogsBuffer(this);
448449
const result = await this.flush(timeout);
449450
this.getOptions().enabled = false;
450451
this.emit('close');

packages/core/test/lib/client.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
withMonitor,
1414
} from '../../src';
1515
import * as integrationModule from '../../src/integration';
16+
import * as logsInternalModule from '../../src/logs/internal';
1617
import { _INTERNAL_captureLog } from '../../src/logs/internal';
1718
import { _INTERNAL_captureMetric } from '../../src/metrics/internal';
1819
import * as traceModule from '../../src/tracing/trace';
@@ -2212,6 +2213,22 @@ describe('Client', () => {
22122213
expect(getSentCount()).toBe(1);
22132214
});
22142215

2216+
test('close flushes the logs buffer', async () => {
2217+
vi.useRealTimers();
2218+
2219+
const flushLogsSpy = vi.spyOn(logsInternalModule, '_INTERNAL_flushLogsBuffer').mockImplementation(() => undefined);
2220+
2221+
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
2222+
const client = new TestClient(options);
2223+
2224+
await client.close();
2225+
2226+
expect(flushLogsSpy).toHaveBeenCalledTimes(1);
2227+
expect(flushLogsSpy).toHaveBeenCalledWith(client);
2228+
2229+
flushLogsSpy.mockRestore();
2230+
});
2231+
22152232
test('multiple concurrent flush calls should just work', async () => {
22162233
vi.useRealTimers();
22172234
expect.assertions(3);

0 commit comments

Comments
 (0)