Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk/trace: Allow errors supplied to RecordError to supply values for semconv.ExceptionType #5760

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down