Skip to content

Commit

Permalink
Create overload that internal unix timestamp can be used
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci committed Mar 22, 2021
1 parent ef26003 commit 125b0cd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Elastic.Apm/Helpers/TimeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

namespace Elastic.Apm.Helpers
{
public static class TimeUtils
internal static class TimeUtils
{
/// <summary>
/// DateTime.UnixEpoch Field does not exist in .NET Standard 2.0
/// https://docs.microsoft.com/en-us/dotnet/api/system.datetime.unixepoch
/// </summary>
internal static readonly DateTime UnixEpochDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

public static long TimestampNow() => ToTimestamp(DateTime.UtcNow);
internal static long TimestampNow() => ToTimestamp(DateTime.UtcNow);

/// <summary>
/// UTC based and formatted as microseconds since Unix epoch.
Expand Down
4 changes: 4 additions & 0 deletions src/Elastic.Apm/Metrics/MetricSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using Elastic.Apm.Api;
using Elastic.Apm.Helpers;
using Elastic.Apm.Report.Serialization;
using Newtonsoft.Json;

Expand All @@ -12,6 +13,9 @@ namespace Elastic.Apm.Metrics
[JsonConverter(typeof(MetricSetConverter))]
public class MetricSet : IMetricSet
{
public MetricSet(IEnumerable<MetricSample> samples)
: this(TimeUtils.TimestampNow(), samples) { }

public MetricSet(long timestamp, IEnumerable<MetricSample> samples)
=> (Timestamp, Samples) = (timestamp, samples);

Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Apm/Metrics/MetricsCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void CollectAllMetricsImpl()
return;
}

var metricSet = new MetricSet(TimeUtils.TimestampNow(), samplesFromAllProviders);
var metricSet = new MetricSet(samplesFromAllProviders);

try
{
Expand Down

0 comments on commit 125b0cd

Please sign in to comment.