Skip to content
Open
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
1 change: 1 addition & 0 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
*/
// @ts-expect-error - PromiseLike is a subset of Promise
public async close(timeout?: number): PromiseLike<boolean> {
_INTERNAL_flushLogsBuffer(this);
const result = await this.flush(timeout);
this.getOptions().enabled = false;
this.emit('close');
Expand Down
19 changes: 19 additions & 0 deletions packages/core/test/lib/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
withMonitor,
} from '../../src';
import * as integrationModule from '../../src/integration';
import * as logsInternalModule from '../../src/logs/internal';
import { _INTERNAL_captureLog } from '../../src/logs/internal';
import { _INTERNAL_captureMetric } from '../../src/metrics/internal';
import * as traceModule from '../../src/tracing/trace';
Expand Down Expand Up @@ -2212,6 +2213,24 @@ describe('Client', () => {
expect(getSentCount()).toBe(1);
});

test('close flushes the logs buffer', async () => {
vi.useRealTimers();

const flushLogsSpy = vi
.spyOn(logsInternalModule, '_INTERNAL_flushLogsBuffer')
.mockImplementation(() => undefined);

const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
const client = new TestClient(options);

await client.close();

expect(flushLogsSpy).toHaveBeenCalledTimes(1);
expect(flushLogsSpy).toHaveBeenCalledWith(client);

flushLogsSpy.mockRestore();
});

test('multiple concurrent flush calls should just work', async () => {
vi.useRealTimers();
expect.assertions(3);
Expand Down
Loading