factory.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package mezmoexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/mezmoexporter"
  4. import (
  5. "context"
  6. "errors"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/exporter"
  9. "go.opentelemetry.io/collector/exporter/exporterhelper"
  10. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/mezmoexporter/internal/metadata"
  11. )
  12. // NewFactory creates a factory for Mezmo exporter.
  13. func NewFactory() exporter.Factory {
  14. return exporter.NewFactory(
  15. metadata.Type,
  16. createDefaultConfig,
  17. exporter.WithLogs(createLogsExporter, metadata.LogsStability),
  18. )
  19. }
  20. // Create a default Memzo config
  21. func createDefaultConfig() component.Config {
  22. return &Config{
  23. HTTPClientSettings: createDefaultHTTPClientSettings(),
  24. RetrySettings: exporterhelper.NewDefaultRetrySettings(),
  25. QueueSettings: exporterhelper.NewDefaultQueueSettings(),
  26. IngestURL: defaultIngestURL,
  27. }
  28. }
  29. // Create a log exporter for exporting to Mezmo
  30. func createLogsExporter(ctx context.Context, settings exporter.CreateSettings, exporterConfig component.Config) (exporter.Logs, error) {
  31. log := settings.Logger
  32. if exporterConfig == nil {
  33. return nil, errors.New("nil config")
  34. }
  35. expCfg := exporterConfig.(*Config)
  36. exp := newLogsExporter(expCfg, settings.TelemetrySettings, settings.BuildInfo, log)
  37. return exporterhelper.NewLogsExporter(
  38. ctx,
  39. settings,
  40. expCfg,
  41. exp.pushLogData,
  42. // explicitly disable since we rely on http.Client timeout logic.
  43. exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
  44. exporterhelper.WithRetry(expCfg.RetrySettings),
  45. exporterhelper.WithQueue(expCfg.QueueSettings),
  46. exporterhelper.WithStart(exp.start),
  47. exporterhelper.WithShutdown(exp.stop),
  48. )
  49. }