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