Skip to content

Commit

Permalink
feat(datadog-transport-common): do not enable exit hooks if sendImmed…
Browse files Browse the repository at this point in the history
…iate is enabled (#2)
  • Loading branch information
theogravity authored Apr 7, 2024
1 parent 2151bf3 commit e58bb90
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
15 changes: 15 additions & 0 deletions .changeset/nervous-mugs-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"electron-log-transport-datadog": major
"pino-datadog-transport": major
"datadog-transport-common": minor
---

The core logic for `electron-log-transport-datadog` and `pino-datadog-transport`
has been split into the `datadog-transport-common` package.

- The `p-retry` and `exit-hook` libs are now updated to current
- If `sendImmediate` is enabled, we will no longer enable the exit hook to send
off any pending logs (since sending is immediate)

The changes should be transparent, but we're releasing these
packages under a new major version just in case.
38 changes: 20 additions & 18 deletions packages/datadog-transport-common/src/DataDogTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,29 @@ export class DataDogTransport {
* Sets up a hook to send any remaining logs on application exit
*/
private setupExitHook() {
if (this.config.onDebug) {
this.config.onDebug("Configuring exit hook");
}
if (!this.config.sendImmediate) {
if (this.config.onDebug) {
this.config.onDebug("Configuring exit hook");
}

exitHook(() => {
if (this.logStorage.getLogCount() > 0) {
if (this.config.onDebug) {
this.config.onDebug("Shutdown detected. Attempting to send remaining logs to Datadog");
}
if (this.timer) {
clearInterval(this.timer);
}
exitHook(() => {
if (this.logStorage.getLogCount() > 0) {
if (this.config.onDebug) {
this.config.onDebug("Shutdown detected. Attempting to send remaining logs to Datadog");
}
if (this.timer) {
clearInterval(this.timer);
}

const currentBucket = this.logStorage.currentBucket;
const currentBucket = this.logStorage.currentBucket;

this.sendLogs({
logsToSend: this.logStorage.finishLogBatch(),
bucketName: currentBucket,
});
}
});
this.sendLogs({
logsToSend: this.logStorage.finishLogBatch(),
bucketName: currentBucket,
});
}
});
}
}

/**
Expand Down

0 comments on commit e58bb90

Please sign in to comment.