From e0e53b6f0f8bb92b97d0d30f2768742e602312b4 Mon Sep 17 00:00:00 2001 From: Olivier G Date: Wed, 26 Oct 2022 11:49:06 +0200 Subject: [PATCH] Add `timestamp` arguments to `Increment` and `Decrement` methods Remove `params` for tags for `IDogStatsd.Decrement` --- src/StatsdClient/DogStatsdService.cs | 16 +++++++++------- src/StatsdClient/Dogstatsd.cs | 10 ++++++---- src/StatsdClient/IDogStatsd.cs | 8 +++++--- src/StatsdClient/MetricsSender.cs | 4 ++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/StatsdClient/DogStatsdService.cs b/src/StatsdClient/DogStatsdService.cs index 5b6c97d..307d819 100644 --- a/src/StatsdClient/DogStatsdService.cs +++ b/src/StatsdClient/DogStatsdService.cs @@ -106,9 +106,10 @@ public void Counter(string statName, double value, double sampleRate = 1.0, stri /// The amount of increment. /// Percentage of metric to be sent. /// Array of tags to be added to the data. - public void Increment(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null) + /// BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation. + public void Increment(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null) { - _metricsSender?.SendMetric(MetricType.Count, statName, value, sampleRate, tags); + _metricsSender?.SendMetric(MetricType.Count, statName, value, sampleRate, tags, timestamp); } /// @@ -118,9 +119,10 @@ public void Increment(string statName, int value = 1, double sampleRate = 1.0, s /// The amount of decrement. /// Percentage of metric to be sent. /// Array of tags to be added to the data. - public void Decrement(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null) + /// BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation. + public void Decrement(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null) { - _metricsSender?.SendMetric(MetricType.Count, statName, -value, sampleRate, tags); + _metricsSender?.SendMetric(MetricType.Count, statName, -value, sampleRate, tags, timestamp); } /// @@ -145,7 +147,7 @@ public void Gauge(string statName, double value, double sampleRate = 1.0, string /// Array of tags to be added to the data. public void Histogram(string statName, double value, double sampleRate = 1.0, string[] tags = null) { - _metricsSender?.SendMetric(MetricType.Histogram, statName, value, sampleRate, tags); + _metricsSender?.SendMetric(MetricType.Histogram, statName, value, sampleRate, tags, null); } /// @@ -157,7 +159,7 @@ public void Histogram(string statName, double value, double sampleRate = 1.0, st /// Array of tags to be added to the data. public void Distribution(string statName, double value, double sampleRate = 1.0, string[] tags = null) { - _metricsSender?.SendMetric(MetricType.Distribution, statName, value, sampleRate, tags); + _metricsSender?.SendMetric(MetricType.Distribution, statName, value, sampleRate, tags, null); } /// @@ -195,7 +197,7 @@ public void Set(string statName, string value, double sampleRate = 1.0, string[] /// Array of tags to be added to the data. public void Timer(string statName, double value, double sampleRate = 1.0, string[] tags = null) { - _metricsSender?.SendMetric(MetricType.Timing, statName, value, sampleRate, tags); + _metricsSender?.SendMetric(MetricType.Timing, statName, value, sampleRate, tags, null); } /// diff --git a/src/StatsdClient/Dogstatsd.cs b/src/StatsdClient/Dogstatsd.cs index 66399a6..9cabfc2 100644 --- a/src/StatsdClient/Dogstatsd.cs +++ b/src/StatsdClient/Dogstatsd.cs @@ -105,8 +105,9 @@ public static void Counter(string statName, double value, double sampleRate = 1. /// The amount of increment. /// Percentage of metric to be sent. /// Array of tags to be added to the data. - public static void Increment(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null) => - _dogStatsdService.Increment(statName: statName, value: value, sampleRate: sampleRate, tags: tags); + /// BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation. + public static void Increment(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null) => + _dogStatsdService.Increment(statName: statName, value: value, sampleRate: sampleRate, tags: tags, timestamp: timestamp); /// /// Decrements the specified counter. @@ -115,8 +116,9 @@ public static void Increment(string statName, int value = 1, double sampleRate = /// The amount of decrement. /// Percentage of metric to be sent. /// Array of tags to be added to the data. - public static void Decrement(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null) => - _dogStatsdService.Decrement(statName: statName, value: value, sampleRate: sampleRate, tags: tags); + /// BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation. + public static void Decrement(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null) => + _dogStatsdService.Decrement(statName: statName, value: value, sampleRate: sampleRate, tags: tags, timestamp: timestamp); /// /// Records the latest fixed value for the specified named gauge. diff --git a/src/StatsdClient/IDogStatsd.cs b/src/StatsdClient/IDogStatsd.cs index f02751d..4cf2f0a 100644 --- a/src/StatsdClient/IDogStatsd.cs +++ b/src/StatsdClient/IDogStatsd.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace StatsdClient { @@ -41,7 +41,8 @@ public interface IDogStatsd : IDisposable /// The amount of decrement. /// Percentage of metric to be sent. /// Array of tags to be added to the data. - void Decrement(string statName, int value = 1, double sampleRate = 1, params string[] tags); + /// BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation. + void Decrement(string statName, int value = 1, double sampleRate = 1, string[] tags = null, DateTimeOffset? timestamp = null); /// /// Records an event. @@ -101,7 +102,8 @@ void Event( /// The amount of increment. /// Percentage of metric to be sent. /// Array of tags to be added to the data. - void Increment(string statName, int value = 1, double sampleRate = 1, string[] tags = null); + /// BETA - Please contact our support team for more information to use this feature: https://www.datadoghq.com/support/ - Timestamp at which the counter has been seen with the given value. This value is sent without any aggregation. + void Increment(string statName, int value = 1, double sampleRate = 1, string[] tags = null, DateTimeOffset? timestamp = null); /// /// Records a value for the specified set. diff --git a/src/StatsdClient/MetricsSender.cs b/src/StatsdClient/MetricsSender.cs index fa782e0..d2294d1 100644 --- a/src/StatsdClient/MetricsSender.cs +++ b/src/StatsdClient/MetricsSender.cs @@ -65,7 +65,7 @@ public void SendServiceCheck(string name, int status, int? timestamp = null, str } } - public void SendMetric(MetricType metricType, string name, double value, double sampleRate = 1.0, string[] tags = null, DateTimeOffset? timestamp = null) + public void SendMetric(MetricType metricType, string name, double value, double sampleRate, string[] tags, DateTimeOffset? timestamp) { if (metricType == MetricType.Set) { @@ -129,7 +129,7 @@ public void Send(Action actionToTime, string statName, double sampleRate = 1.0, finally { stopwatch.Stop(); - SendMetric(MetricType.Timing, statName, stopwatch.ElapsedMilliseconds(), sampleRate, tags); + SendMetric(MetricType.Timing, statName, stopwatch.ElapsedMilliseconds(), sampleRate, tags, null); } }