Skip to content

Commit d765e87

Browse files
committed
feat(cloud-watch-logger): use keepalive option when writing logs
1 parent 12aa1be commit d765e87

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

libs/core/src/lib/logger/cloud-watch-log/cloud-watch-log-api.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ export class CloudWatchLogV2ApiService {
7171
}
7272

7373
async writeLogs(logStreamName: string, logs: LogEvent[]): Promise<void> {
74-
// todo: use beaconApi ?
74+
// we do not use the sendBeacon API since it will fail with cors preflight and would require ugly workarounds
7575
const resp = await fetch(new URL(`${ApiPath.STREAMS}/${logStreamName}/${ApiPath.STREAM_LOGS}`, this.apiUrl), {
7676
method: 'POST',
7777
headers: { [CommonHttpHeader.CONTENT_TYPE]: ContentType.JSON },
7878
body: JSON.stringify({ logEvents: logs } satisfies WriteLogEvents),
79+
keepalive: true, // do not abort request on page unload
7980
})
8081
await this.handleError(resp)
8182
}

0 commit comments

Comments
 (0)