factory.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package zipkinexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter"
  4. import (
  5. "context"
  6. "errors"
  7. "time"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/config/confighttp"
  10. "go.opentelemetry.io/collector/exporter"
  11. "go.opentelemetry.io/collector/exporter/exporterhelper"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter/internal/metadata"
  13. )
  14. const (
  15. defaultTimeout = time.Second * 5
  16. defaultFormat = "json"
  17. defaultServiceName string = "<missing service name>"
  18. )
  19. // NewFactory creates a factory for Zipkin exporter.
  20. func NewFactory() exporter.Factory {
  21. return exporter.NewFactory(
  22. metadata.Type,
  23. createDefaultConfig,
  24. exporter.WithTraces(createTracesExporter, metadata.TracesStability))
  25. }
  26. func createDefaultConfig() component.Config {
  27. return &Config{
  28. RetrySettings: exporterhelper.NewDefaultRetrySettings(),
  29. QueueSettings: exporterhelper.NewDefaultQueueSettings(),
  30. HTTPClientSettings: confighttp.HTTPClientSettings{
  31. Timeout: defaultTimeout,
  32. // We almost read 0 bytes, so no need to tune ReadBufferSize.
  33. WriteBufferSize: 512 * 1024,
  34. },
  35. Format: defaultFormat,
  36. DefaultServiceName: defaultServiceName,
  37. }
  38. }
  39. func createTracesExporter(
  40. ctx context.Context,
  41. set exporter.CreateSettings,
  42. cfg component.Config,
  43. ) (exporter.Traces, error) {
  44. zc := cfg.(*Config)
  45. if zc.Endpoint == "" {
  46. // TODO https://github.com/open-telemetry/opentelemetry-collector/issues/215
  47. return nil, errors.New("exporter config requires a non-empty 'endpoint'")
  48. }
  49. ze, err := createZipkinExporter(zc, set.TelemetrySettings)
  50. if err != nil {
  51. return nil, err
  52. }
  53. return exporterhelper.NewTracesExporter(
  54. ctx,
  55. set,
  56. cfg,
  57. ze.pushTraces,
  58. exporterhelper.WithStart(ze.start),
  59. // explicitly disable since we rely on http.Client timeout logic.
  60. exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
  61. exporterhelper.WithQueue(zc.QueueSettings),
  62. exporterhelper.WithRetry(zc.RetrySettings))
  63. }