factory.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. //go:generate mdatagen metadata.yaml
  4. package sumologicexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter"
  5. import (
  6. "context"
  7. "fmt"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/exporter"
  10. "go.opentelemetry.io/collector/exporter/exporterhelper"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter/internal/metadata"
  12. )
  13. // NewFactory returns a new factory for the sumologic exporter.
  14. func NewFactory() exporter.Factory {
  15. return exporter.NewFactory(
  16. metadata.Type,
  17. createDefaultConfig,
  18. exporter.WithLogs(createLogsExporter, metadata.LogsStability),
  19. exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability),
  20. )
  21. }
  22. func createDefaultConfig() component.Config {
  23. qs := exporterhelper.NewDefaultQueueSettings()
  24. qs.Enabled = false
  25. return &Config{
  26. CompressEncoding: DefaultCompressEncoding,
  27. MaxRequestBodySize: DefaultMaxRequestBodySize,
  28. LogFormat: DefaultLogFormat,
  29. MetricFormat: DefaultMetricFormat,
  30. SourceCategory: DefaultSourceCategory,
  31. SourceName: DefaultSourceName,
  32. SourceHost: DefaultSourceHost,
  33. Client: DefaultClient,
  34. GraphiteTemplate: DefaultGraphiteTemplate,
  35. HTTPClientSettings: createDefaultHTTPClientSettings(),
  36. RetrySettings: exporterhelper.NewDefaultRetrySettings(),
  37. QueueSettings: qs,
  38. }
  39. }
  40. func createLogsExporter(
  41. _ context.Context,
  42. params exporter.CreateSettings,
  43. cfg component.Config,
  44. ) (exporter.Logs, error) {
  45. exp, err := newLogsExporter(cfg.(*Config), params)
  46. if err != nil {
  47. return nil, fmt.Errorf("failed to create the logs exporter: %w", err)
  48. }
  49. return exp, nil
  50. }
  51. func createMetricsExporter(
  52. _ context.Context,
  53. params exporter.CreateSettings,
  54. cfg component.Config,
  55. ) (exporter.Metrics, error) {
  56. exp, err := newMetricsExporter(cfg.(*Config), params)
  57. if err != nil {
  58. return nil, fmt.Errorf("failed to create the metrics exporter: %w", err)
  59. }
  60. return exp, nil
  61. }