forked from zhevron/gqlgen-opentelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.go
86 lines (82 loc) · 1.96 KB
/
value.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package gqlgen_opentelemetry
import (
"fmt"
"go.opentelemetry.io/otel/attribute"
)
func makeAttributeValue(value interface{}) attribute.Value {
switch v := value.(type) {
case bool:
return attribute.BoolValue(v)
case float32:
return attribute.Float64Value(float64(v))
case float64:
return attribute.Float64Value(v)
case int:
return attribute.Int64Value(int64(v))
case int32:
return attribute.Int64Value(int64(v))
case int64:
return attribute.Int64Value(v)
case string:
return attribute.StringValue(v)
case []interface{}:
return makeAttributeSliceValue(v)
default:
return attribute.StringValue(fmt.Sprintf("%+v", v))
}
}
func makeAttributeSliceValue(value []interface{}) attribute.Value {
if len(value) == 0 {
return attribute.StringSliceValue([]string{})
}
switch value[0].(type) {
case bool:
arr := make([]bool, len(value))
for i, v := range value {
arr[i] = v.(bool)
}
return attribute.BoolSliceValue(arr)
case float32:
arr := make([]float64, len(value))
for i, v := range value {
arr[i] = float64(v.(float32))
}
return attribute.Float64SliceValue(arr)
case float64:
arr := make([]float64, len(value))
for i, v := range value {
arr[i] = v.(float64)
}
return attribute.Float64SliceValue(arr)
case int:
arr := make([]int64, len(value))
for i, v := range value {
arr[i] = int64(v.(int))
}
return attribute.Int64SliceValue(arr)
case int32:
arr := make([]int64, len(value))
for i, v := range value {
arr[i] = int64(v.(int32))
}
return attribute.Int64SliceValue(arr)
case int64:
arr := make([]int64, len(value))
for i, v := range value {
arr[i] = v.(int64)
}
return attribute.Int64SliceValue(arr)
case string:
arr := make([]string, len(value))
for i, v := range value {
arr[i] = v.(string)
}
return attribute.StringSliceValue(arr)
default:
arr := make([]string, len(value))
for i, v := range value {
arr[i] = fmt.Sprintf("%+v", v)
}
return attribute.StringSliceValue(arr)
}
}