@@ -6,6 +6,7 @@ import 'dart:async';
66
77import 'package:opentelemetry/api.dart' as api;
88import 'package:opentelemetry/sdk.dart' as sdk;
9+ import 'package:opentelemetry/src/api/trace/span_event.dart' ;
910import 'package:opentelemetry/src/sdk/trace/span.dart' ;
1011import 'package:opentelemetry/src/sdk/trace/tracer.dart' ;
1112import 'package:test/test.dart' ;
@@ -74,10 +75,14 @@ void main() {
7475 expect (span.endTime, isNotNull);
7576 expect (span.status.code, equals (api.StatusCode .error));
7677 expect (span.status.description, equals ('Exception: Oh noes!' ));
77- expect (span.attributes.get (api.SemanticAttributes .exceptionType),
78- equals ('_Exception' ));
79- expect (span.attributes.get (api.SemanticAttributes .exceptionMessage),
80- equals ('Exception: Oh noes!' ));
78+ expect (span.events, [
79+ hasExceptionEvent ({
80+ api.SemanticAttributes .exceptionType: '_Exception' ,
81+ api.SemanticAttributes .exceptionMessage: 'Exception: Oh noes!' ,
82+ api.SemanticAttributes .exceptionStacktrace: anything,
83+ api.SemanticAttributes .exceptionEscaped: true ,
84+ })
85+ ]);
8186 });
8287
8388 test ('trace asynchronous execution' , () async {
@@ -145,10 +150,14 @@ void main() {
145150 expect (span.endTime, isNotNull);
146151 expect (span.status.code, equals (api.StatusCode .error));
147152 expect (span.status.description, equals ('Exception: Oh noes!' ));
148- expect (span.attributes.get (api.SemanticAttributes .exceptionType),
149- equals ('_Exception' ));
150- expect (span.attributes.get (api.SemanticAttributes .exceptionMessage),
151- equals ('Exception: Oh noes!' ));
153+ expect (span.events, [
154+ hasExceptionEvent ({
155+ api.SemanticAttributes .exceptionType: '_Exception' ,
156+ api.SemanticAttributes .exceptionMessage: 'Exception: Oh noes!' ,
157+ api.SemanticAttributes .exceptionStacktrace: anything,
158+ api.SemanticAttributes .exceptionEscaped: true ,
159+ })
160+ ]);
152161 });
153162
154163 test ('trace asynchronous execution completes with error' , () async {
@@ -173,9 +182,22 @@ void main() {
173182 expect (span.endTime, isNotNull);
174183 expect (span.status.code, equals (api.StatusCode .error));
175184 expect (span.status.description, equals ('Exception: Oh noes!' ));
176- expect (span.attributes.get (api.SemanticAttributes .exceptionType),
177- equals ('_Exception' ));
178- expect (span.attributes.get (api.SemanticAttributes .exceptionMessage),
179- equals ('Exception: Oh noes!' ));
185+ expect (span.events, [
186+ hasExceptionEvent ({
187+ api.SemanticAttributes .exceptionType: '_Exception' ,
188+ api.SemanticAttributes .exceptionMessage: 'Exception: Oh noes!' ,
189+ api.SemanticAttributes .exceptionStacktrace: anything,
190+ api.SemanticAttributes .exceptionEscaped: true ,
191+ })
192+ ]);
180193 });
181194}
195+
196+ Matcher hasExceptionEvent (Map <String , Object > attributes) =>
197+ isA <SpanEvent >().having (
198+ (e) => e.attributes,
199+ 'attributes' ,
200+ isA< Iterable <api.Attribute >> ().having (
201+ (a) => a.map ((e) => [e.key, e.value]),
202+ 'attributes' ,
203+ containsAll (attributes.entries.map ((e) => [e.key, e.value]))));
0 commit comments