factory.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package alertmanagerexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alertmanagerexporter"
  4. import (
  5. "context"
  6. "fmt"
  7. "time"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/config/confighttp"
  10. "go.opentelemetry.io/collector/config/configopaque"
  11. "go.opentelemetry.io/collector/exporter"
  12. "go.opentelemetry.io/collector/exporter/exporterhelper"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alertmanagerexporter/internal/metadata"
  14. )
  15. // NewFactory creates a factory for Alertmanager exporter
  16. func NewFactory() exporter.Factory {
  17. return exporter.NewFactory(
  18. metadata.Type,
  19. createDefaultConfig,
  20. exporter.WithTraces(createTracesExporter, metadata.TracesStability))
  21. }
  22. func createDefaultConfig() component.Config {
  23. return &Config{
  24. GeneratorURL: "opentelemetry-collector",
  25. DefaultSeverity: "info",
  26. TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
  27. RetrySettings: exporterhelper.NewDefaultRetrySettings(),
  28. QueueSettings: exporterhelper.NewDefaultQueueSettings(),
  29. HTTPClientSettings: confighttp.HTTPClientSettings{
  30. Endpoint: "http://localhost:9093",
  31. Timeout: 30 * time.Second,
  32. Headers: map[string]configopaque.String{},
  33. // We almost read 0 bytes, so no need to tune ReadBufferSize.
  34. WriteBufferSize: 512 * 1024,
  35. },
  36. }
  37. }
  38. func createTracesExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Traces, error) {
  39. cfg := config.(*Config)
  40. if cfg.Endpoint == "" {
  41. return nil, fmt.Errorf(
  42. "exporter config requires a non-empty \"endpoint\"")
  43. }
  44. return newTracesExporter(ctx, cfg, set)
  45. }