traces_exporter.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package logicmonitorexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logicmonitorexporter"
  4. import (
  5. "context"
  6. "fmt"
  7. "github.com/logicmonitor/lm-data-sdk-go/utils"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/exporter"
  10. "go.opentelemetry.io/collector/pdata/ptrace"
  11. traces "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logicmonitorexporter/internal/traces"
  12. )
  13. type tracesExporter struct {
  14. config *Config
  15. sender *traces.Sender
  16. settings component.TelemetrySettings
  17. }
  18. // newTracesExporter creates new Logicmonitor Traces Exporter.
  19. func newTracesExporter(_ context.Context, cfg component.Config, set exporter.CreateSettings) *tracesExporter {
  20. oCfg := cfg.(*Config)
  21. // client construction is deferred to start
  22. return &tracesExporter{
  23. config: oCfg,
  24. settings: set.TelemetrySettings,
  25. }
  26. }
  27. func (e *tracesExporter) start(ctx context.Context, host component.Host) error {
  28. client, err := e.config.HTTPClientSettings.ToClient(host, e.settings)
  29. if err != nil {
  30. return fmt.Errorf("failed to create http client: %w", err)
  31. }
  32. authParams := utils.AuthParams{
  33. AccessID: e.config.APIToken.AccessID,
  34. AccessKey: string(e.config.APIToken.AccessKey),
  35. BearerToken: string(e.config.Headers["Authorization"]),
  36. }
  37. e.sender, err = traces.NewSender(ctx, e.config.Endpoint, client, authParams, e.settings.Logger)
  38. if err != nil {
  39. return err
  40. }
  41. return nil
  42. }
  43. func (e *tracesExporter) PushTraceData(ctx context.Context, td ptrace.Traces) error {
  44. return e.sender.SendTraces(ctx, td)
  45. }