@@ -1164,6 +1164,59 @@ func TestRecordErrorNil(t *testing.T) {
1164
1164
}
1165
1165
}
1166
1166
1167
+ func TestRecordErrorWithStatus (t * testing.T ) {
1168
+ scenarios := []struct {
1169
+ err error
1170
+ typ string
1171
+ msg string
1172
+ }{
1173
+ {
1174
+ err : ottest .NewTestError ("test error" ),
1175
+ typ : "go.opentelemetry.io/otel/internal/internaltest.TestError" ,
1176
+ msg : "test error" ,
1177
+ },
1178
+ }
1179
+
1180
+ for _ , s := range scenarios {
1181
+ te := NewTestExporter ()
1182
+ tp := NewTracerProvider (WithSyncer (te ), WithResource (resource .Empty ()))
1183
+ span := startSpan (tp , "RecordError" )
1184
+
1185
+ errTime := time .Now ()
1186
+ span .RecordError (s .err , trace .WithTimestamp (errTime ), trace .WithStatus (true ))
1187
+
1188
+ got , err := endSpan (te , span )
1189
+ if err != nil {
1190
+ t .Fatal (err )
1191
+ }
1192
+
1193
+ want := & SpanSnapshot {
1194
+ SpanContext : trace .NewSpanContext (trace.SpanContextConfig {
1195
+ TraceID : tid ,
1196
+ TraceFlags : 0x1 ,
1197
+ }),
1198
+ Parent : sc .WithRemote (true ),
1199
+ Name : "span0" ,
1200
+ StatusCode : codes .Error ,
1201
+ SpanKind : trace .SpanKindInternal ,
1202
+ MessageEvents : []trace.Event {
1203
+ {
1204
+ Name : semconv .ExceptionEventName ,
1205
+ Time : errTime ,
1206
+ Attributes : []attribute.KeyValue {
1207
+ semconv .ExceptionTypeKey .String (s .typ ),
1208
+ semconv .ExceptionMessageKey .String (s .msg ),
1209
+ },
1210
+ },
1211
+ },
1212
+ InstrumentationLibrary : instrumentation.Library {Name : "RecordError" },
1213
+ }
1214
+ if diff := cmpDiff (got , want ); diff != "" {
1215
+ t .Errorf ("SpanErrorOptions: -got +want %s" , diff )
1216
+ }
1217
+ }
1218
+ }
1219
+
1167
1220
func TestWithSpanKind (t * testing.T ) {
1168
1221
te := NewTestExporter ()
1169
1222
tp := NewTracerProvider (WithSyncer (te ), WithSampler (AlwaysSample ()), WithResource (resource .Empty ()))
0 commit comments