MCPcopy Index your code
hub / github.com/coder/coder / slogFieldsToAttributes

Function slogFieldsToAttributes

coderd/tracing/slog.go:47–119  ·  view source on GitHub ↗
(m slog.Map)

Source from the content-addressed store, hash-verified

45func (SlogSink) Sync() {}
46
47func slogFieldsToAttributes(m slog.Map) []attribute.KeyValue {
48 attrs := make([]attribute.KeyValue, 0, len(m))
49 for _, f := range m {
50 var value attribute.Value
51 switch v := f.Value.(type) {
52 case bool:
53 value = attribute.BoolValue(v)
54 case []bool:
55 value = attribute.BoolSliceValue(v)
56 case float32:
57 value = attribute.Float64Value(float64(v))
58 // no float32 slice method
59 case float64:
60 value = attribute.Float64Value(v)
61 case []float64:
62 value = attribute.Float64SliceValue(v)
63 case int:
64 value = attribute.Int64Value(int64(v))
65 case []int:
66 value = attribute.IntSliceValue(v)
67 case int8:
68 value = attribute.Int64Value(int64(v))
69 // no int8 slice method
70 case int16:
71 value = attribute.Int64Value(int64(v))
72 // no int16 slice method
73 case int32:
74 value = attribute.Int64Value(int64(v))
75 // no int32 slice method
76 case int64:
77 value = attribute.Int64Value(v)
78 case []int64:
79 value = attribute.Int64SliceValue(v)
80 case uint:
81 // #nosec G115 - Safe conversion from uint to int64 as we're only using this for non-critical logging/tracing
82 value = attribute.Int64Value(int64(v))
83 // no uint slice method
84 case uint8:
85 value = attribute.Int64Value(int64(v))
86 // no uint8 slice method
87 case uint16:
88 value = attribute.Int64Value(int64(v))
89 // no uint16 slice method
90 case uint32:
91 value = attribute.Int64Value(int64(v))
92 // no uint32 slice method
93 case uint64:
94 // #nosec G115 - Safe conversion from uint64 to int64 as we're only using this for non-critical logging/tracing
95 // This is intentionally lossy for very large values, but acceptable for tracing purposes
96 value = attribute.Int64Value(int64(v))
97 // no uint64 slice method
98 case string:
99 value = attribute.StringValue(v)
100 case []string:
101 value = attribute.StringSliceValue(v)
102 case time.Duration:
103 value = attribute.StringValue(v.String())
104 case time.Time:

Callers 1

LogEntryMethod · 0.85

Calls 3

FormatMethod · 0.65
TypeMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected