mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-01 22:09:57 +02:00
Allow errors supplied to RecordError to supply values for semconv.ExceptionType
This commit is contained in:
parent
e47618fc36
commit
157183170c
@ -469,7 +469,14 @@ func (s *recordingSpan) RecordError(err error, opts ...trace.EventOption) {
|
||||
s.addEvent(semconv.ExceptionEventName, opts...)
|
||||
}
|
||||
|
||||
type exceptionTyper interface {
|
||||
ExceptionType() string
|
||||
}
|
||||
|
||||
func typeStr(i interface{}) string {
|
||||
if i, ok := i.(exceptionTyper); ok {
|
||||
return i.ExceptionType()
|
||||
}
|
||||
t := reflect.TypeOf(i)
|
||||
if t.PkgPath() == "" && t.Name() == "" {
|
||||
// Likely a builtin type.
|
||||
|
@ -1189,6 +1189,14 @@ func TestCustomStartEndTime(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type errWithExceptionType struct {
|
||||
error
|
||||
}
|
||||
|
||||
func (errWithExceptionType) ExceptionType() string {
|
||||
return "CustomExceptionType"
|
||||
}
|
||||
|
||||
func TestRecordError(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
err error
|
||||
@ -1205,6 +1213,11 @@ func TestRecordError(t *testing.T) {
|
||||
typ: "*errors.errorString",
|
||||
msg: "test error 2",
|
||||
},
|
||||
{
|
||||
err: errWithExceptionType{errors.New("test error 3")},
|
||||
typ: "CustomExceptionType",
|
||||
msg: "test error 3",
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
|
Loading…
Reference in New Issue
Block a user