@@ -102,6 +102,7 @@ void main() {
102
102
final delay = Duration (milliseconds: 100 );
103
103
final completer = Completer <void >();
104
104
fixture._options.tracesSampleRate = 1 ;
105
+ fixture._options.enableMetrics = true ;
105
106
MetricsApi api = fixture.getSut (hub: fixture.hub);
106
107
107
108
// Start a transaction so that timing api can start a child span
@@ -114,17 +115,28 @@ void main() {
114
115
115
116
// Timing starts a span
116
117
api.timing ('my key' ,
118
+ unit: DurationSentryMeasurementUnit .milliSecond,
117
119
function: () => Future .delayed (delay, () => completer.complete ()));
118
120
final span = transaction.children.first;
119
121
expect (span.finished, false );
120
122
expect (span.context.operation, 'metric.timing' );
121
123
expect (span.context.description, 'my key' );
122
- final spanDuration = span.endTimestamp! .difference (span.startTimestamp);
123
124
124
125
// Timing finishes the span when the function is finished, which takes 100 milliseconds
125
126
await completer.future;
126
- expect (spanDuration.inMilliseconds >= 100 , true );
127
127
expect (span.finished, true );
128
+ final spanDuration = span.endTimestamp! .difference (span.startTimestamp);
129
+ expect (spanDuration.inMilliseconds >= 100 , true );
130
+ await Future .delayed (Duration ());
131
+
132
+ Iterable <Metric > sentMetrics =
133
+ fixture.hub.metricsAggregator! .buckets.values.first.values;
134
+
135
+ // The emitted metric value should match the span duration
136
+ expect (sentMetrics.first.unit, DurationSentryMeasurementUnit .milliSecond);
137
+ // Duration.inMilliseconds returns an int, so we have to assert it
138
+ expect ((sentMetrics.first as DistributionMetric ).values.first.toInt (),
139
+ spanDuration.inMilliseconds);
128
140
});
129
141
});
130
142
}
0 commit comments