rawlogs_unmarshaler.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package azureeventhubreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azureeventhubreceiver"
  4. import (
  5. eventhub "github.com/Azure/azure-event-hubs-go/v3"
  6. "go.opentelemetry.io/collector/pdata/pcommon"
  7. "go.opentelemetry.io/collector/pdata/plog"
  8. "go.uber.org/zap"
  9. )
  10. type rawLogsUnmarshaler struct {
  11. logger *zap.Logger
  12. }
  13. func newRawLogsUnmarshaler(logger *zap.Logger) eventLogsUnmarshaler {
  14. return rawLogsUnmarshaler{
  15. logger: logger,
  16. }
  17. }
  18. func (r rawLogsUnmarshaler) UnmarshalLogs(event *eventhub.Event) (plog.Logs, error) {
  19. l := plog.NewLogs()
  20. lr := l.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()
  21. slice := lr.Body().SetEmptyBytes()
  22. slice.Append(event.Data...)
  23. if event.SystemProperties.EnqueuedTime != nil {
  24. lr.SetTimestamp(pcommon.NewTimestampFromTime(*event.SystemProperties.EnqueuedTime))
  25. }
  26. if err := lr.Attributes().FromRaw(event.Properties); err != nil {
  27. return l, err
  28. }
  29. return l, nil
  30. }