File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
internal/tools/semconvkit/templates Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright The OpenTelemetry Authors
2+ // SPDX-License-Identifier: Apache-2.0
3+
4+ package semconv // import "go.opentelemetry.io/otel/semconv/{{.TagVer}}"
5+
6+
7+ // ErrorType returns an attribute KeyValue that identifies the type of the given error.
8+ // It uses reflection to determine the fully qualified type name for observability and monitoring.
9+ func ErrorType(err error) attribute.KeyValue {
10+ t := reflect.TypeOf(err)
11+ var value string
12+ if t.PkgPath() == "" && t.Name() == "" {
13+ // Likely a builtin type.
14+ value = t.String()
15+ } else {
16+ value = fmt.Sprintf("%s.%s", t.PkgPath(), t.Name())
17+ }
18+
19+ if value == "" {
20+ return ErrorTypeOther
21+ }
22+ return ErrorTypeKey.String(value)
23+ }
Original file line number Diff line number Diff line change 1+ // Copyright The OpenTelemetry Authors
2+ // SPDX-License-Identifier: Apache-2.0
3+
4+ package semconv // import "go.opentelemetry.io/otel/semconv/v1.34.0"
5+
6+ import (
7+ "fmt"
8+ "reflect"
9+
10+ "go.opentelemetry.io/otel/attribute"
11+ )
12+
13+ // ErrorType returns an attribute KeyValue that identifies the type of the given error.
14+ // It uses reflection to determine the fully qualified type name for observability and monitoring.
15+ func ErrorType (err error ) attribute.KeyValue {
16+ t := reflect .TypeOf (err )
17+ var value string
18+ if t .PkgPath () == "" && t .Name () == "" {
19+ // Likely a builtin type.
20+ value = t .String ()
21+ } else {
22+ value = fmt .Sprintf ("%s.%s" , t .PkgPath (), t .Name ())
23+ }
24+
25+ if value == "" {
26+ return ErrorTypeOther
27+ }
28+ return ErrorTypeKey .String (value )
29+ }
You can’t perform that action at this time.
0 commit comments