-
Notifications
You must be signed in to change notification settings - Fork 3
/
helpers.go
36 lines (31 loc) · 1.01 KB
/
helpers.go
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
26
27
28
29
30
31
32
33
34
35
36
package ydb
import (
"fmt"
"github.com/ydb-platform/ydb-go-sdk/v3/spans"
"go.opentelemetry.io/otel/attribute"
)
func fieldToAttribute(field spans.KeyValue) attribute.KeyValue {
switch field.Type() {
case spans.IntType:
return attribute.Int(field.Key(), field.IntValue())
case spans.Int64Type:
return attribute.Int64(field.Key(), field.Int64Value())
case spans.StringType:
return attribute.String(field.Key(), field.StringValue())
case spans.BoolType:
return attribute.Bool(field.Key(), field.BoolValue())
case spans.StringsType:
return attribute.StringSlice(field.Key(), field.StringsValue())
case spans.StringerType:
return attribute.Stringer(field.Key(), field.Stringer())
default:
return attribute.String(field.Key(), fmt.Sprintf("%v", field.AnyValue()))
}
}
func fieldsToAttributes(fields []spans.KeyValue) []attribute.KeyValue {
attributes := make([]attribute.KeyValue, 0, len(fields))
for _, kv := range fields {
attributes = append(attributes, fieldToAttribute(kv))
}
return attributes
}