factory.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package mockdatadogagentexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/mockdatasenders/mockdatadogagentexporter"
  4. import (
  5. "context"
  6. "errors"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/component/componenttest"
  9. "go.opentelemetry.io/collector/config/confighttp"
  10. "go.opentelemetry.io/collector/consumer"
  11. "go.opentelemetry.io/collector/exporter"
  12. "go.opentelemetry.io/collector/exporter/exporterhelper"
  13. )
  14. // This file implements factory for awsxray receiver.
  15. const (
  16. // The value of "type" key in configuration.
  17. typeStr = "datadog"
  18. )
  19. func NewFactory() exporter.Factory {
  20. return exporter.NewFactory(typeStr,
  21. createDefaultConfig,
  22. exporter.WithTraces(CreateTracesExporter, component.StabilityLevelAlpha))
  23. }
  24. // CreateDefaultConfig creates the default configuration for DDAPM Exporter
  25. func createDefaultConfig() component.Config {
  26. return &Config{
  27. HTTPClientSettings: confighttp.HTTPClientSettings{Endpoint: "localhost:8126"},
  28. }
  29. }
  30. func CreateTracesExporter(
  31. _ context.Context,
  32. set exporter.CreateSettings,
  33. cfg component.Config,
  34. ) (exporter.Traces, error) {
  35. c := cfg.(*Config)
  36. if c.Endpoint == "" {
  37. // TODO https://github.com/open-telemetry/opentelemetry-collector/issues/215
  38. return nil, errors.New("exporter config requires a non-empty 'endpoint'")
  39. }
  40. dd := createExporter(c)
  41. err := dd.start(context.Background(), componenttest.NewNopHost())
  42. if err != nil {
  43. return nil, err
  44. }
  45. return exporterhelper.NewTracesExporter(
  46. context.Background(),
  47. set,
  48. dd.pushTraces,
  49. consumer.ConsumeTracesFunc(dd.pushTraces),
  50. // explicitly disable since we rely on http.Client timeout logic.
  51. exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
  52. )
  53. }