Skip to content

semconv: Add ErrorType function #6904

Open
@pellared

Description

@pellared

Problem Statement

There is no easy way to set error.type (stable) attribute.

Proposed Solution

We can add a helper method to semconv package:

func 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 ErrorTypeOther
	}
	return ErrorTypeKey.String(value)
}

Additional Context

Related to:

Metadata

Metadata

Labels

enhancementNew feature or requestpkg:semconvRelated to a semconv package

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions