zipkin.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package datasenders // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/datasenders"
  4. import (
  5. "context"
  6. "fmt"
  7. "go.opentelemetry.io/collector/component/componenttest"
  8. "go.opentelemetry.io/collector/consumer"
  9. "go.opentelemetry.io/collector/exporter/exportertest"
  10. "go.uber.org/zap"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed"
  13. )
  14. // zipkinDataSender implements TraceDataSender for Zipkin http exporter.
  15. type zipkinDataSender struct {
  16. testbed.DataSenderBase
  17. consumer.Traces
  18. }
  19. // NewZipkinDataSender creates a new Zipkin exporter sender that will send
  20. // to the specified port after Start is called.
  21. func NewZipkinDataSender(host string, port int) testbed.TraceDataSender {
  22. return &zipkinDataSender{
  23. DataSenderBase: testbed.DataSenderBase{
  24. Port: port,
  25. Host: host,
  26. },
  27. }
  28. }
  29. func (zs *zipkinDataSender) Start() error {
  30. factory := zipkinexporter.NewFactory()
  31. cfg := factory.CreateDefaultConfig().(*zipkinexporter.Config)
  32. cfg.Endpoint = fmt.Sprintf("http://%s/api/v2/spans", zs.GetEndpoint())
  33. // Disable retries, we should push data and if error just log it.
  34. cfg.RetrySettings.Enabled = false
  35. // Disable sending queue, we should push data from the caller goroutine.
  36. cfg.QueueSettings.Enabled = false
  37. params := exportertest.NewNopCreateSettings()
  38. params.Logger = zap.L()
  39. exp, err := factory.CreateTracesExporter(context.Background(), params, cfg)
  40. if err != nil {
  41. return err
  42. }
  43. zs.Traces = exp
  44. return exp.Start(context.Background(), componenttest.NewNopHost())
  45. }
  46. func (zs *zipkinDataSender) GenConfigYAMLStr() string {
  47. return fmt.Sprintf(`
  48. zipkin:
  49. endpoint: %s`, zs.GetEndpoint())
  50. }
  51. func (zs *zipkinDataSender) ProtocolName() string {
  52. return "zipkin"
  53. }