marshaler.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package awss3exporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awss3exporter"
  4. import (
  5. "errors"
  6. "go.opentelemetry.io/collector/pdata/plog"
  7. "go.opentelemetry.io/collector/pdata/pmetric"
  8. "go.opentelemetry.io/collector/pdata/ptrace"
  9. "go.uber.org/zap"
  10. )
  11. type marshaler interface {
  12. MarshalTraces(td ptrace.Traces) ([]byte, error)
  13. MarshalLogs(ld plog.Logs) ([]byte, error)
  14. MarshalMetrics(md pmetric.Metrics) ([]byte, error)
  15. format() string
  16. }
  17. var (
  18. ErrUnknownMarshaler = errors.New("unknown marshaler")
  19. )
  20. func newMarshaler(mType MarshalerType, logger *zap.Logger) (marshaler, error) {
  21. marshaler := &s3Marshaler{logger: logger}
  22. switch mType {
  23. case OtlpJSON:
  24. marshaler.logsMarshaler = &plog.JSONMarshaler{}
  25. marshaler.tracesMarshaler = &ptrace.JSONMarshaler{}
  26. marshaler.metricsMarshaler = &pmetric.JSONMarshaler{}
  27. marshaler.fileFormat = "json"
  28. case SumoIC:
  29. sumomarshaler := newSumoICMarshaler()
  30. marshaler.logsMarshaler = &sumomarshaler
  31. marshaler.fileFormat = "json.gz"
  32. default:
  33. return nil, ErrUnknownMarshaler
  34. }
  35. return marshaler, nil
  36. }