-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
rawlogs_unmarshaler.go
40 lines (32 loc) · 1.12 KB
/
rawlogs_unmarshaler.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package azureeventhubreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azureeventhubreceiver"
import (
"time"
eventhub "github.com/Azure/azure-event-hubs-go/v3"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.uber.org/zap"
)
type rawLogsUnmarshaler struct {
logger *zap.Logger
}
func newRawLogsUnmarshaler(logger *zap.Logger) eventLogsUnmarshaler {
return rawLogsUnmarshaler{
logger: logger,
}
}
func (r rawLogsUnmarshaler) UnmarshalLogs(event *eventhub.Event) (plog.Logs, error) {
l := plog.NewLogs()
lr := l.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()
slice := lr.Body().SetEmptyBytes()
slice.Append(event.Data...)
lr.SetObservedTimestamp(pcommon.NewTimestampFromTime(time.Now()))
if event.SystemProperties.EnqueuedTime != nil {
lr.SetTimestamp(pcommon.NewTimestampFromTime(*event.SystemProperties.EnqueuedTime))
}
if err := lr.Attributes().FromRaw(event.Properties); err != nil {
return l, err
}
return l, nil
}