Core

/app/lib/telemetry/attribute.go (464 B)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package telemetry

import (
"go.opentelemetry.io/otel/attribute"

"{{{ .Package }}}/app/util"
)

type Attribute struct {
Key string `json:"key"`
Value any `json:"value"`
}

func (a *Attribute) ToOT() attribute.KeyValue {
switch t := a.Value.(type) {
case string:
return attribute.String(a.Key, t)
case int:
return attribute.Int(a.Key, t)
case bool:
return attribute.Bool(a.Key, t)
default:
return attribute.String(a.Key, util.ToJSON(t))
}
}