Skip to content

Commit

Permalink
fix zipkin transport
Browse files Browse the repository at this point in the history
  • Loading branch information
waynz0r committed May 16, 2023
1 parent 389acc0 commit 6c627cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
28 changes: 18 additions & 10 deletions pkg/istio/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ func NewIstioIntegrationHandler(config *IstioIntegrationHandlerConfig, logger lo

s.environment = e

if s.environment.ZipkinAddress != "" {
s.zipkinTracer, err = tracing.SetupZipkinTracing(s.environment)
if err != nil {
return nil, err
}
}

registry := prometheus.NewRegistry()
s.metricHandler = proxywasm.NewPrometheusMetricHandler(registry, logger)
baseContext := proxywasm.GetBaseContext("root")
Expand Down Expand Up @@ -292,6 +285,20 @@ func NewIstioIntegrationHandler(config *IstioIntegrationHandlerConfig, logger lo
s.metricsPusher = createMetricsPusher(config.PushgatewayConfig, jobName, httpClient, registry)
}

if s.environment.ZipkinAddress != "" {
transport, err := s.GetHTTPTransport(http.DefaultTransport)
if err != nil {
return nil, err
}

s.zipkinTracer, err = tracing.SetupZipkinTracing(s.environment, &http.Client{
Transport: transport,
})
if err != nil {
return nil, err
}
}

return s, nil
}

Expand All @@ -309,15 +316,16 @@ func (h *istioIntegrationHandler) GetHTTPTransport(transport http.RoundTripper)
return nil, errors.Wrap(err, "could not get stream handler")
}

logger := h.logger.WithName("http-transport")
tp := NewIstioHTTPRequestTransport(transport, h.caClient, h.discoveryClient, logger, h.zipkinTracer)

if h.zipkinTracer != nil {
transport, err = zipkinhttp.NewTransport(h.zipkinTracer, zipkinhttp.RoundTripper(transport))
tp, err = zipkinhttp.NewTransport(h.zipkinTracer, zipkinhttp.RoundTripper(tp))
if err != nil {
return nil, errors.Wrap(err, "could not get zipkin tracer")
}
}

logger := h.logger.WithName("http-transport")
tp := NewIstioHTTPRequestTransport(transport, h.caClient, h.discoveryClient, logger, h.zipkinTracer)
httpTransport := pwhttp.NewHTTPTransport(tp, streamHandler, logger)

if h.zipkinTracer != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/istio/tracing/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// SetupZipkinTracing initializes and returns a zipkin tracer to be used for tracing middlewares and clients
func SetupZipkinTracing(istioEnvironment *environment.IstioEnvironment) (*zipkin.Tracer, error) {
func SetupZipkinTracing(istioEnvironment *environment.IstioEnvironment, httpClient httpreporter.HTTPDoer) (*zipkin.Tracer, error) {
localIP := ""
if len(istioEnvironment.InstanceIPs) > 0 {
localIP = istioEnvironment.InstanceIPs[0]
Expand All @@ -27,7 +27,7 @@ func SetupZipkinTracing(istioEnvironment *environment.IstioEnvironment) (*zipkin
return nil, err
}

reporter := httpreporter.NewReporter(istioEnvironment.ZipkinAddress)
reporter := httpreporter.NewReporter(istioEnvironment.ZipkinAddress, httpreporter.Client(httpClient))

tracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(localEndpoint), zipkin.WithSharedSpans(false))
if err != nil {
Expand Down

0 comments on commit 6c627cf

Please sign in to comment.