diff --git a/src/Elastic.Apm/Model/DroppedSpanStats.cs b/src/Elastic.Apm/Model/DroppedSpanStats.cs
index 2254a6f78..63121a0be 100644
--- a/src/Elastic.Apm/Model/DroppedSpanStats.cs
+++ b/src/Elastic.Apm/Model/DroppedSpanStats.cs
@@ -3,6 +3,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
+using System;
using Elastic.Apm.Api;
using Elastic.Apm.Libraries.Newtonsoft.Json;
@@ -18,7 +19,7 @@ public DroppedSpanStats(string serviceTargetType, string serviceTargetName, stri
double durationSumUs
)
{
- Duration = new DroppedSpanDuration { Count = 1, Sum = new DroppedSpanDuration.DroppedSpanDurationSum { Us = durationSumUs } };
+ Duration = new DroppedSpanDuration { Count = 1, Sum = new DroppedSpanDuration.DroppedSpanDurationSum { UsRaw = durationSumUs } };
ServiceTargetType = serviceTargetType;
ServiceTargetName = serviceTargetName;
DestinationServiceResource = destinationServiceResource;
@@ -49,7 +50,6 @@ double durationSumUs
///
public Outcome Outcome { get; }
-
///
/// Duration holds duration aggregations about the dropped span.
///
@@ -63,13 +63,17 @@ internal class DroppedSpanDuration
public int Count { get; set; }
///
- /// Sum holds dimensions about the dropped span's duration.
+ /// Sum holds dimensions about the dropped span's duration.
///
public DroppedSpanDurationSum Sum { get; set; }
internal class DroppedSpanDurationSum
{
- public double Us { get; set; }
+ [JsonIgnore]
+ public double UsRaw { get; set; }
+
+ // As `duration.sum.us` is an integer in the intake API we round during serialization.
+ public int Us => Convert.ToInt32(UsRaw);
}
}
}
diff --git a/src/Elastic.Apm/Model/Transaction.cs b/src/Elastic.Apm/Model/Transaction.cs
index c1f401d59..c80f962e2 100644
--- a/src/Elastic.Apm/Model/Transaction.cs
+++ b/src/Elastic.Apm/Model/Transaction.cs
@@ -575,7 +575,7 @@ double duration
new DroppedSpanStats.DroppedSpanDuration { Sum = new DroppedSpanStats.DroppedSpanDuration.DroppedSpanDurationSum() };
item.Duration.Count++;
- item.Duration.Sum.Us += duration;
+ item.Duration.Sum.UsRaw += duration;
}
else
{
diff --git a/test/Elastic.Apm.Tests/DroppedSpansStatsTests.cs b/test/Elastic.Apm.Tests/DroppedSpansStatsTests.cs
index e01434844..e0cd2453e 100644
--- a/test/Elastic.Apm.Tests/DroppedSpansStatsTests.cs
+++ b/test/Elastic.Apm.Tests/DroppedSpansStatsTests.cs
@@ -60,7 +60,7 @@ public void SingleDroppedSpanTest()
//This span will be dropped
var span1 = transaction.StartSpan("foo", "bar", isExitSpan: true);
span1.Context.Http = new Http { Method = "GET", StatusCode = 200, Url = "https://foo.bar" };
- span1.Duration = 100;
+ span1.Duration = 100.001;
span1.End();
transaction.End();
@@ -75,7 +75,7 @@ public void SingleDroppedSpanTest()
payloadSender.FirstTransaction.DroppedSpanStats.First().ServiceTargetType.Should().Be("bar");
payloadSender.FirstTransaction.DroppedSpanStats.First().Outcome.Should().Be(Outcome.Success);
payloadSender.FirstTransaction.DroppedSpanStats.First().Duration.Count.Should().Be(1);
- payloadSender.FirstTransaction.DroppedSpanStats.First().Duration.Sum.Us.Should().Be(100);
+ payloadSender.FirstTransaction.DroppedSpanStats.First().Duration.Sum.Us.Should().Be(100); // This should be rounded and will be sent in the JSON
}
[Fact]
@@ -130,22 +130,22 @@ public void MultipleDroppedSpanTest()
payloadSender.FirstTransaction.DroppedSpanStats.Should()
.Contain(n => n.Outcome == Outcome.Success
- && n.Duration.Count == 2 && Math.Abs(n.Duration.Sum.Us - 250) < 1 && n.DestinationServiceResource == "foo.bar:443"
+ && n.Duration.Count == 2 && Math.Abs(n.Duration.Sum.UsRaw - 250) < 1 && n.DestinationServiceResource == "foo.bar:443"
&& n.ServiceTargetName == "foo.bar:443" && n.ServiceTargetType == "bar");
payloadSender.FirstTransaction.DroppedSpanStats.Should()
.Contain(n => n.Outcome == Outcome.Failure
- && n.Duration.Count == 1 && Math.Abs(n.Duration.Sum.Us - 50) < 1 && n.DestinationServiceResource == "foo.bar:443"
+ && n.Duration.Count == 1 && Math.Abs(n.Duration.Sum.UsRaw - 50) < 1 && n.DestinationServiceResource == "foo.bar:443"
&& n.ServiceTargetName == "foo.bar:443" && n.ServiceTargetType == "bar");
payloadSender.FirstTransaction.DroppedSpanStats.Should()
.Contain(n => n.Outcome == Outcome.Success
- && n.Duration.Count == 1 && Math.Abs(n.Duration.Sum.Us - 15) < 1 && n.DestinationServiceResource == "foo2.bar:443"
+ && n.Duration.Count == 1 && Math.Abs(n.Duration.Sum.UsRaw - 15) < 1 && n.DestinationServiceResource == "foo2.bar:443"
&& n.ServiceTargetName == "foo2.bar:443" && n.ServiceTargetType == "bar");
payloadSender.FirstTransaction.DroppedSpanStats.Should()
.Contain(n => n.Outcome == Outcome.Success
- && n.Duration.Count == 50 && Math.Abs(n.Duration.Sum.Us - 50 * 50) < 1 && n.DestinationServiceResource == "mysql");
+ && n.Duration.Count == 50 && Math.Abs(n.Duration.Sum.UsRaw - 50 * 50) < 1 && n.DestinationServiceResource == "mysql");
}
///
diff --git a/test/Elastic.Apm.Tests/SerializationTests.cs b/test/Elastic.Apm.Tests/SerializationTests.cs
index cfe8586a2..9a76672c8 100644
--- a/test/Elastic.Apm.Tests/SerializationTests.cs
+++ b/test/Elastic.Apm.Tests/SerializationTests.cs
@@ -495,7 +495,7 @@ public void DroppedSpanStatsTest()
transaction.End();
var json = _payloadItemSerializer.Serialize(transaction);
- json.Should().Contain("\"duration\":{\"count\":1,\"sum\":{\"us\":100.0}}");
+ json.Should().Contain("\"duration\":{\"count\":1,\"sum\":{\"us\":100}}");
}
///