Skip to content

Commit f41d137

Browse files
authored
Sles 2151 fix race condition flush (#643)
* fix recreating of promises * warn if metrics will be lost due to race condition and fail * preserve old behavior of adding global tags with api and extension, not dogstatsd * format * use dostatsd if the extension is running but no timestamp is set in metric * avoid other changes, add only the fix * typo
1 parent e782bde commit f41d137

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/metrics/listener.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ export class MetricsListener {
156156
}
157157
// Only create the processor to submit metrics to the API when a user provides a valid timestamp as
158158
// Dogstatsd does not support timestamps for distributions.
159-
this.currentProcessor = this.createProcessor(this.config, this.apiKey);
159+
if (this.currentProcessor === undefined) {
160+
this.currentProcessor = this.createProcessor(this.config, this.apiKey);
161+
}
160162
// Add global tags to metrics sent to the API
161163
if (this.globalTags !== undefined && this.globalTags.length > 0) {
162164
tags = [...tags, ...this.globalTags];

src/metrics/processor.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import promiseRetry from "promise-retry";
22

3-
import { logError, Timer } from "../utils";
3+
import { logError, logWarning, Timer } from "../utils";
44
import { Client } from "./api";
55
import { Batcher } from "./batcher";
66
import { Metric } from "./model";
@@ -77,6 +77,12 @@ export class Processor {
7777
} catch {
7878
// Failed to send metrics, keep the old batch alive if retrying is enabled
7979
if (this.shouldRetryOnFail) {
80+
const metricsReceivedWhileSending = this.batcher.toAPIMetrics();
81+
if (metricsReceivedWhileSending.length > 0) {
82+
logWarning(
83+
`Failed to send metrics to Datadog, retrying at next interval. ${metricsReceivedWhileSending.length} metrics received will be lost`,
84+
);
85+
}
8086
this.batcher = oldBatcher;
8187
}
8288
}

0 commit comments

Comments
 (0)