-
Notifications
You must be signed in to change notification settings - Fork 2
/
logs.go
44 lines (38 loc) · 1 KB
/
logs.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
package generator
import (
"time"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
logspb "go.opentelemetry.io/proto/otlp/logs/v1"
)
type LogConfig struct {
Attributes map[string]interface{} `js:"attributes"`
Data LogData `js:"data"`
}
type LogData struct {
Body string `js:"body"`
Severity int32 `js:"severity"`
}
func ResourceLogs(resourceAttrs []*commonpb.KeyValue, config LogConfig) *logspb.ResourceLogs {
return &logspb.ResourceLogs{
Resource: resource(resourceAttrs),
ScopeLogs: []*logspb.ScopeLogs{
{
LogRecords: []*logspb.LogRecord{
logRecord(ToAttributes(config.Attributes), config.Data),
},
},
},
}
}
func logRecord(attrs []*commonpb.KeyValue, data LogData) *logspb.LogRecord {
return &logspb.LogRecord{
Attributes: attrs,
TimeUnixNano: uint64(time.Now().UnixNano()),
SeverityNumber: logspb.SeverityNumber(data.Severity),
Body: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{
StringValue: data.Body,
},
},
}
}