factory.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. //go:generate mdatagen metadata.yaml
  4. package googlecloudexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter"
  5. import (
  6. "context"
  7. "time"
  8. "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/exporter"
  11. "go.opentelemetry.io/collector/exporter/exporterhelper"
  12. "go.opentelemetry.io/collector/featuregate"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter/internal/metadata"
  14. )
  15. const (
  16. defaultTimeout = 12 * time.Second // Consistent with Cloud Monitoring's timeout
  17. )
  18. var _ = featuregate.GlobalRegistry().MustRegister(
  19. "exporter.googlecloud.OTLPDirect",
  20. featuregate.StageStable,
  21. featuregate.WithRegisterDescription("When enabled, the googlecloud exporter translates pdata directly to google cloud monitoring's types, rather than first translating to opencensus."),
  22. featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/7132"),
  23. featuregate.WithRegisterToVersion("v0.69.0"),
  24. )
  25. // NewFactory creates a factory for the googlecloud exporter
  26. func NewFactory() exporter.Factory {
  27. return exporter.NewFactory(
  28. metadata.Type,
  29. createDefaultConfig,
  30. exporter.WithTraces(createTracesExporter, metadata.TracesStability),
  31. exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability),
  32. exporter.WithLogs(createLogsExporter, metadata.LogsStability),
  33. )
  34. }
  35. // createDefaultConfig creates the default configuration for exporter.
  36. func createDefaultConfig() component.Config {
  37. return &Config{
  38. TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: defaultTimeout},
  39. QueueSettings: exporterhelper.NewDefaultQueueSettings(),
  40. Config: collector.DefaultConfig(),
  41. }
  42. }
  43. func createLogsExporter(
  44. ctx context.Context,
  45. params exporter.CreateSettings,
  46. cfg component.Config) (exporter.Logs, error) {
  47. eCfg := cfg.(*Config)
  48. logsExporter, err := collector.NewGoogleCloudLogsExporter(ctx, eCfg.Config, params.TelemetrySettings.Logger, params.BuildInfo.Version)
  49. if err != nil {
  50. return nil, err
  51. }
  52. return exporterhelper.NewLogsExporter(
  53. ctx,
  54. params,
  55. cfg,
  56. logsExporter.PushLogs,
  57. exporterhelper.WithShutdown(logsExporter.Shutdown),
  58. // Disable exporterhelper Timeout, since we are using a custom mechanism
  59. // within exporter itself
  60. exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
  61. exporterhelper.WithQueue(eCfg.QueueSettings))
  62. }
  63. // createTracesExporter creates a trace exporter based on this config.
  64. func createTracesExporter(
  65. ctx context.Context,
  66. params exporter.CreateSettings,
  67. cfg component.Config) (exporter.Traces, error) {
  68. eCfg := cfg.(*Config)
  69. tExp, err := collector.NewGoogleCloudTracesExporter(ctx, eCfg.Config, params.BuildInfo.Version, eCfg.Timeout)
  70. if err != nil {
  71. return nil, err
  72. }
  73. return exporterhelper.NewTracesExporter(
  74. ctx,
  75. params,
  76. cfg,
  77. tExp.PushTraces,
  78. exporterhelper.WithShutdown(tExp.Shutdown),
  79. // Disable exporterhelper Timeout, since we are using a custom mechanism
  80. // within exporter itself
  81. exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
  82. exporterhelper.WithQueue(eCfg.QueueSettings))
  83. }
  84. // createMetricsExporter creates a metrics exporter based on this config.
  85. func createMetricsExporter(
  86. ctx context.Context,
  87. params exporter.CreateSettings,
  88. cfg component.Config) (exporter.Metrics, error) {
  89. eCfg := cfg.(*Config)
  90. mExp, err := collector.NewGoogleCloudMetricsExporter(ctx, eCfg.Config, params.TelemetrySettings.Logger, params.BuildInfo.Version, eCfg.Timeout)
  91. if err != nil {
  92. return nil, err
  93. }
  94. return exporterhelper.NewMetricsExporter(
  95. ctx,
  96. params,
  97. cfg,
  98. mExp.PushMetrics,
  99. exporterhelper.WithShutdown(mExp.Shutdown),
  100. // Disable exporterhelper Timeout, since we are using a custom mechanism
  101. // within exporter itself
  102. exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
  103. exporterhelper.WithQueue(eCfg.QueueSettings))
  104. }