Skip to content

Commit

Permalink
Merge pull request #188 from DataDog/olivierg/add-missing-timestamp
Browse files Browse the repository at this point in the history
Add `timestamp` arguments to `Increment` and `Decrement` methods
  • Loading branch information
ogaca-dd authored Oct 26, 2022
2 parents a126d7a + e0e53b6 commit 536a9fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/StatsdClient/DogStatsdService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ public void Counter(string statName, double value, double sampleRate = 1.0, stri
/// <param name="value">The amount of increment.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
public void Increment(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null)
/// <param name="timestamp">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.</param>
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);
}

/// <summary>
Expand All @@ -118,9 +119,10 @@ public void Increment(string statName, int value = 1, double sampleRate = 1.0, s
/// <param name="value">The amount of decrement.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
public void Decrement(string statName, int value = 1, double sampleRate = 1.0, string[] tags = null)
/// <param name="timestamp">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.</param>
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);
}

/// <summary>
Expand All @@ -145,7 +147,7 @@ public void Gauge(string statName, double value, double sampleRate = 1.0, string
/// <param name="tags">Array of tags to be added to the data.</param>
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);
}

/// <summary>
Expand All @@ -157,7 +159,7 @@ public void Histogram(string statName, double value, double sampleRate = 1.0, st
/// <param name="tags">Array of tags to be added to the data.</param>
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);
}

/// <summary>
Expand Down Expand Up @@ -195,7 +197,7 @@ public void Set(string statName, string value, double sampleRate = 1.0, string[]
/// <param name="tags">Array of tags to be added to the data.</param>
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);
}

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions src/StatsdClient/Dogstatsd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ public static void Counter(string statName, double value, double sampleRate = 1.
/// <param name="value">The amount of increment.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
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);
/// <param name="timestamp">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.</param>
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);

/// <summary>
/// Decrements the specified counter.
Expand All @@ -121,8 +122,9 @@ public static void Increment(string statName, int value = 1, double sampleRate =
/// <param name="value">The amount of decrement.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
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);
/// <param name="timestamp">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.</param>
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);

/// <summary>
/// Records the latest fixed value for the specified named gauge.
Expand Down
8 changes: 5 additions & 3 deletions src/StatsdClient/IDogStatsd.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace StatsdClient
{
Expand Down Expand Up @@ -41,7 +41,8 @@ public interface IDogStatsd : IDisposable
/// <param name="value">The amount of decrement.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
void Decrement(string statName, int value = 1, double sampleRate = 1, params string[] tags);
/// <param name="timestamp">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.</param>
void Decrement(string statName, int value = 1, double sampleRate = 1, string[] tags = null, DateTimeOffset? timestamp = null);

/// <summary>
/// Records an event.
Expand Down Expand Up @@ -101,7 +102,8 @@ void Event(
/// <param name="value">The amount of increment.</param>
/// <param name="sampleRate">Percentage of metric to be sent.</param>
/// <param name="tags">Array of tags to be added to the data.</param>
void Increment(string statName, int value = 1, double sampleRate = 1, string[] tags = null);
/// <param name="timestamp">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.</param>
void Increment(string statName, int value = 1, double sampleRate = 1, string[] tags = null, DateTimeOffset? timestamp = null);

/// <summary>
/// Records a value for the specified set.
Expand Down
4 changes: 2 additions & 2 deletions src/StatsdClient/MetricsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 536a9fc

Please sign in to comment.