File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313 withMonitor ,
1414} from '../../src' ;
1515import * as integrationModule from '../../src/integration' ;
16+ import * as logsInternalModule from '../../src/logs/internal' ;
1617import { _INTERNAL_captureLog } from '../../src/logs/internal' ;
1718import { _INTERNAL_captureMetric } from '../../src/metrics/internal' ;
1819import * 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 ) ;
You can’t perform that action at this time.
0 commit comments