factory.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package opencensusexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opencensusexporter"
  4. import (
  5. "context"
  6. "go.opentelemetry.io/collector/component"
  7. "go.opentelemetry.io/collector/config/configgrpc"
  8. "go.opentelemetry.io/collector/consumer"
  9. "go.opentelemetry.io/collector/exporter"
  10. "go.opentelemetry.io/collector/exporter/exporterhelper"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opencensusexporter/internal/metadata"
  12. )
  13. // NewFactory creates a factory for OTLP exporter.
  14. func NewFactory() exporter.Factory {
  15. return exporter.NewFactory(
  16. metadata.Type,
  17. createDefaultConfig,
  18. exporter.WithTraces(createTracesExporter, metadata.TracesStability),
  19. exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability))
  20. }
  21. func createDefaultConfig() component.Config {
  22. return &Config{
  23. GRPCClientSettings: configgrpc.GRPCClientSettings{
  24. // We almost read 0 bytes, so no need to tune ReadBufferSize.
  25. WriteBufferSize: 512 * 1024,
  26. },
  27. NumWorkers: 2,
  28. }
  29. }
  30. func createTracesExporter(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (exporter.Traces, error) {
  31. oCfg := cfg.(*Config)
  32. oce, err := newTracesExporter(ctx, oCfg, set.TelemetrySettings)
  33. if err != nil {
  34. return nil, err
  35. }
  36. return exporterhelper.NewTracesExporter(
  37. ctx,
  38. set,
  39. cfg,
  40. oce.pushTraces,
  41. exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
  42. exporterhelper.WithRetry(oCfg.RetrySettings),
  43. exporterhelper.WithQueue(oCfg.QueueSettings),
  44. exporterhelper.WithStart(oce.start),
  45. exporterhelper.WithShutdown(oce.shutdown))
  46. }
  47. func createMetricsExporter(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (exporter.Metrics, error) {
  48. oCfg := cfg.(*Config)
  49. oce, err := newMetricsExporter(ctx, oCfg, set.TelemetrySettings)
  50. if err != nil {
  51. return nil, err
  52. }
  53. return exporterhelper.NewMetricsExporter(
  54. ctx,
  55. set,
  56. cfg,
  57. oce.pushMetrics,
  58. exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
  59. exporterhelper.WithRetry(oCfg.RetrySettings),
  60. exporterhelper.WithQueue(oCfg.QueueSettings),
  61. exporterhelper.WithStart(oce.start),
  62. exporterhelper.WithShutdown(oce.shutdown))
  63. }