factory.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package datadogreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver"
  4. import (
  5. "context"
  6. "time"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/config/confighttp"
  9. "go.opentelemetry.io/collector/consumer"
  10. "go.opentelemetry.io/collector/receiver"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver/internal/metadata"
  13. )
  14. // NewFactory creates a factory for DataDog receiver.
  15. func NewFactory() receiver.Factory {
  16. return receiver.NewFactory(
  17. metadata.Type,
  18. createDefaultConfig,
  19. receiver.WithTraces(createTracesReceiver, metadata.TracesStability))
  20. }
  21. func createDefaultConfig() component.Config {
  22. return &Config{
  23. HTTPServerSettings: confighttp.HTTPServerSettings{
  24. Endpoint: "localhost:8126",
  25. },
  26. ReadTimeout: 60 * time.Second,
  27. }
  28. }
  29. func createTracesReceiver(_ context.Context, params receiver.CreateSettings, cfg component.Config, consumer consumer.Traces) (r receiver.Traces, err error) {
  30. rcfg := cfg.(*Config)
  31. r = receivers.GetOrAdd(cfg, func() component.Component {
  32. dd, _ := newDataDogReceiver(rcfg, consumer, params)
  33. return dd
  34. })
  35. return r, nil
  36. }
  37. var receivers = sharedcomponent.NewSharedComponents()