logs_exporter.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package tencentcloudlogserviceexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/tencentcloudlogserviceexporter"
  4. import (
  5. "context"
  6. "go.opentelemetry.io/collector/component"
  7. "go.opentelemetry.io/collector/exporter"
  8. "go.opentelemetry.io/collector/exporter/exporterhelper"
  9. "go.opentelemetry.io/collector/pdata/plog"
  10. "go.uber.org/zap"
  11. )
  12. // newLogsExporter return a new LogService logs exporter.
  13. func newLogsExporter(set exporter.CreateSettings, cfg component.Config) (exporter.Logs, error) {
  14. l := &logServiceLogsSender{
  15. logger: set.Logger,
  16. }
  17. l.client = newLogServiceClient(cfg.(*Config), set.Logger)
  18. return exporterhelper.NewLogsExporter(
  19. context.TODO(),
  20. set,
  21. cfg,
  22. l.pushLogsData)
  23. }
  24. type logServiceLogsSender struct {
  25. logger *zap.Logger
  26. client logServiceClient
  27. }
  28. func (s *logServiceLogsSender) pushLogsData(
  29. _ context.Context,
  30. md plog.Logs) error {
  31. var err error
  32. clsLogs := convertLogs(md)
  33. if len(clsLogs) > 0 {
  34. err = s.client.sendLogs(clsLogs)
  35. }
  36. return err
  37. }