factory.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package skywalkingexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/skywalkingexporter"
  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/skywalkingexporter/internal/metadata"
  12. )
  13. // NewFactory creates a factory for Skywalking exporter.
  14. func NewFactory() exporter.Factory {
  15. return exporter.NewFactory(
  16. metadata.Type,
  17. createDefaultConfig,
  18. exporter.WithLogs(createLogsExporter, metadata.LogsStability),
  19. exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability))
  20. }
  21. func createDefaultConfig() component.Config {
  22. return &Config{
  23. RetrySettings: exporterhelper.NewDefaultRetrySettings(),
  24. QueueSettings: exporterhelper.NewDefaultQueueSettings(),
  25. TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
  26. GRPCClientSettings: configgrpc.GRPCClientSettings{
  27. // We almost read 0 bytes, so no need to tune ReadBufferSize.
  28. WriteBufferSize: 512 * 1024,
  29. },
  30. NumStreams: 2,
  31. }
  32. }
  33. func createLogsExporter(
  34. ctx context.Context,
  35. set exporter.CreateSettings,
  36. cfg component.Config,
  37. ) (exporter.Logs, error) {
  38. oCfg := cfg.(*Config)
  39. oce := newLogsExporter(ctx, oCfg, set.TelemetrySettings)
  40. return exporterhelper.NewLogsExporter(
  41. ctx,
  42. set,
  43. cfg,
  44. oce.pushLogs,
  45. exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
  46. exporterhelper.WithRetry(oCfg.RetrySettings),
  47. exporterhelper.WithQueue(oCfg.QueueSettings),
  48. exporterhelper.WithTimeout(oCfg.TimeoutSettings),
  49. exporterhelper.WithStart(oce.start),
  50. exporterhelper.WithShutdown(oce.shutdown),
  51. )
  52. }
  53. func createMetricsExporter(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (exporter.Metrics, error) {
  54. oCfg := cfg.(*Config)
  55. oce := newMetricsExporter(ctx, oCfg, set.TelemetrySettings)
  56. return exporterhelper.NewMetricsExporter(
  57. ctx,
  58. set,
  59. cfg,
  60. oce.pushMetrics,
  61. exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
  62. exporterhelper.WithRetry(oCfg.RetrySettings),
  63. exporterhelper.WithQueue(oCfg.QueueSettings),
  64. exporterhelper.WithTimeout(oCfg.TimeoutSettings),
  65. exporterhelper.WithStart(oce.start),
  66. exporterhelper.WithShutdown(oce.shutdown))
  67. }