@@ -26,7 +26,6 @@ import (
2626 "go.opentelemetry.io/otel/metric"
2727 sdkmetric "go.opentelemetry.io/otel/sdk/metric"
2828 "go.opentelemetry.io/otel/sdk/metric/metricdata"
29- "go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
3029 "go.uber.org/zap"
3130 "go.uber.org/zap/zaptest/observer"
3231
@@ -1181,42 +1180,69 @@ func TestDropLargeTraces(t *testing.T) {
11811180 assert .Len (t , allSampledTraces , 2 )
11821181
11831182 // These traces should not count as dropped too early as we record a separate metric.
1184- var md metricdata.ResourceMetrics
1185- require .NoError (t , telem .reader .Collect (t .Context (), & md ))
1186-
1187- expectedTooEarly := metricdata.Metrics {
1188- Name : "otelcol_processor_tail_sampling_sampling_trace_dropped_too_early" ,
1189- Description : "Count of traces that needed to be dropped before the configured wait time [Development]" ,
1190- Unit : "{traces}" ,
1191- Data : metricdata.Sum [int64 ]{
1192- IsMonotonic : true ,
1193- Temporality : metricdata .CumulativeTemporality ,
1194- DataPoints : []metricdata.DataPoint [int64 ]{
1195- {
1196- Value : 0 ,
1183+ // Use Eventually to ensure metric aggregation is complete before asserting.
1184+ // This handles async metric pipeline timing, especially in slower CI environments.
1185+ require .EventuallyWithT (t , func (collect * assert.CollectT ) {
1186+ var md metricdata.ResourceMetrics
1187+ err := telem .reader .Collect (t .Context (), & md )
1188+ require .NoError (collect , err )
1189+
1190+ expectedTooEarly := metricdata.Metrics {
1191+ Name : "otelcol_processor_tail_sampling_sampling_trace_dropped_too_early" ,
1192+ Description : "Count of traces that needed to be dropped before the configured wait time [Development]" ,
1193+ Unit : "{traces}" ,
1194+ Data : metricdata.Sum [int64 ]{
1195+ IsMonotonic : true ,
1196+ Temporality : metricdata .CumulativeTemporality ,
1197+ DataPoints : []metricdata.DataPoint [int64 ]{
1198+ {
1199+ Value : 0 ,
1200+ },
11971201 },
11981202 },
1199- },
1200- }
1201- tooEarly := telem .getMetric (expectedTooEarly .Name , md )
1202- metricdatatest .AssertEqual (t , expectedTooEarly , tooEarly , metricdatatest .IgnoreTimestamp ())
1203-
1204- expectedTooLarge := metricdata.Metrics {
1205- Name : "otelcol_processor_tail_sampling_traces_dropped_too_large" ,
1206- Description : "Count of traces that were dropped because they were too large [Development]" ,
1207- Unit : "{traces}" ,
1208- Data : metricdata.Sum [int64 ]{
1209- IsMonotonic : true ,
1210- Temporality : metricdata .CumulativeTemporality ,
1211- DataPoints : []metricdata.DataPoint [int64 ]{
1212- {
1213- Value : 1 ,
1203+ }
1204+ tooEarly := telem .getMetric (expectedTooEarly .Name , md )
1205+ // Verify metric exists and has expected structure
1206+ require .NotNil (collect , tooEarly )
1207+ require .Equal (collect , expectedTooEarly .Name , tooEarly .Name )
1208+ require .Equal (collect , expectedTooEarly .Unit , tooEarly .Unit )
1209+ // Validate metric metadata (IsMonotonic and Temporality)
1210+ tooEarlySum := tooEarly .Data .(metricdata.Sum [int64 ])
1211+ require .True (collect , tooEarlySum .IsMonotonic , "tooEarly metric must be monotonic" )
1212+ require .Equal (collect , metricdata .CumulativeTemporality , tooEarlySum .Temporality ,
1213+ "tooEarly metric must have CumulativeTemporality" )
1214+ require .Equal (collect , len (expectedTooEarly .Data .(metricdata.Sum [int64 ]).DataPoints ),
1215+ len (tooEarlySum .DataPoints ))
1216+ require .Equal (collect , int64 (0 ), tooEarlySum .DataPoints [0 ].Value )
1217+
1218+ expectedTooLarge := metricdata.Metrics {
1219+ Name : "otelcol_processor_tail_sampling_traces_dropped_too_large" ,
1220+ Description : "Count of traces that were dropped because they were too large [Development]" ,
1221+ Unit : "{traces}" ,
1222+ Data : metricdata.Sum [int64 ]{
1223+ IsMonotonic : true ,
1224+ Temporality : metricdata .CumulativeTemporality ,
1225+ DataPoints : []metricdata.DataPoint [int64 ]{
1226+ {
1227+ Value : 1 ,
1228+ },
12141229 },
12151230 },
1216- },
1217- }
1218- tooLarge := telem .getMetric (expectedTooLarge .Name , md )
1219- metricdatatest .AssertEqual (t , expectedTooLarge , tooLarge , metricdatatest .IgnoreTimestamp ())
1231+ }
1232+ tooLarge := telem .getMetric (expectedTooLarge .Name , md )
1233+ // Verify metric exists and has expected structure
1234+ require .NotNil (collect , tooLarge )
1235+ require .Equal (collect , expectedTooLarge .Name , tooLarge .Name )
1236+ require .Equal (collect , expectedTooLarge .Unit , tooLarge .Unit )
1237+ // Validate metric metadata (IsMonotonic and Temporality)
1238+ tooLargeSum := tooLarge .Data .(metricdata.Sum [int64 ])
1239+ require .True (collect , tooLargeSum .IsMonotonic , "tooLarge metric must be monotonic" )
1240+ require .Equal (collect , metricdata .CumulativeTemporality , tooLargeSum .Temporality ,
1241+ "tooLarge metric must have CumulativeTemporality" )
1242+ require .Equal (collect , len (expectedTooLarge .Data .(metricdata.Sum [int64 ]).DataPoints ),
1243+ len (tooLargeSum .DataPoints ))
1244+ require .Equal (collect , int64 (1 ), tooLargeSum .DataPoints [0 ].Value )
1245+ }, 2 * time .Second , 100 * time .Millisecond )
12201246}
12211247
12221248// TestDeleteQueueCleared verifies that all in memory traces are removed from
0 commit comments