fluentd_exporter.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import (
  3. "context"
  4. "go.opentelemetry.io/collector/component"
  5. "go.opentelemetry.io/collector/component/componenttest"
  6. "go.opentelemetry.io/collector/consumer/consumertest"
  7. "go.opentelemetry.io/collector/exporter"
  8. )
  9. const typeStr = "nop"
  10. // NewNopCreateSettings returns a new nop settings for Create*Exporter functions.
  11. func NewNopCreateSettings() exporter.CreateSettings {
  12. return exporter.CreateSettings{
  13. TelemetrySettings: componenttest.NewNopTelemetrySettings(),
  14. BuildInfo: component.NewDefaultBuildInfo(),
  15. }
  16. }
  17. // NewNopFactory returns an exporter.Factory that constructs nop exporters.
  18. func NewNopFactory() exporter.Factory {
  19. return exporter.NewFactory(
  20. "nop",
  21. func() component.Config { return &nopConfig{} },
  22. exporter.WithTraces(createTracesExporter, component.StabilityLevelStable),
  23. exporter.WithMetrics(createMetricsExporter, component.StabilityLevelStable),
  24. exporter.WithLogs(createLogsExporter, component.StabilityLevelStable),
  25. )
  26. }
  27. func createTracesExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Traces, error) {
  28. return nopInstance, nil
  29. }
  30. func createMetricsExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Metrics, error) {
  31. return nopInstance, nil
  32. }
  33. func createLogsExporter(context.Context, exporter.CreateSettings, component.Config) (exporter.Logs, error) {
  34. return nopInstance, nil
  35. }
  36. type nopConfig struct{}
  37. var nopInstance = &nopExporter{
  38. Consumer: consumertest.NewNop(),
  39. }
  40. // nopExporter stores consumed traces and metrics for testing purposes.
  41. type nopExporter struct {
  42. component.StartFunc
  43. component.ShutdownFunc
  44. consumertest.Consumer
  45. }
  46. // NewNopBuilder returns an exporter.Builder that constructs nop receivers.
  47. func NewNopBuilder() *exporter.Builder {
  48. nopFactory := NewNopFactory()
  49. return exporter.NewBuilder(
  50. map[component.ID]component.Config{component.NewID(typeStr): nopFactory.CreateDefaultConfig()},
  51. map[component.Type]exporter.Factory{typeStr: nopFactory})
  52. }