Skip to content

otelhttp: Cannot record error for spans when producing new semantic convention #7254

@XSAM

Description

@XSAM

Description

otelhttp only uses span.RecordError(err) when errType is not empty

if err != nil {
// set error type attribute if the error is part of the predefined
// error types.
// otherwise, record it as an exception
if errType := t.semconv.ErrorType(err); errType.Valid() {
span.SetAttributes(errType)
} else {
span.RecordError(err)
}

But ErrorType method never returns an empty attribute.

func (n CurrentHTTPClient) ErrorType(err error) attribute.KeyValue {
t := reflect.TypeOf(err)
var value string
if t.PkgPath() == "" && t.Name() == "" {
// Likely a builtin type.
value = t.String()
} else {
value = fmt.Sprintf("%s.%s", t.PkgPath(), t.Name())
}
if value == "" {
return semconvNew.ErrorTypeOther
}
return semconvNew.ErrorTypeKey.String(value)
}

Expected behavior

I don't have a preference on whether we should record error.type with exception.type at the same time. But the comment and the logic here seem conflicted.

Metadata

Metadata

Assignees

Type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions