From 6c627cf7af0a2f7deb291806084e0ee651b45659 Mon Sep 17 00:00:00 2001 From: Zsolt Varga Date: Tue, 16 May 2023 14:34:00 +0200 Subject: [PATCH] fix zipkin transport --- pkg/istio/istio.go | 28 ++++++++++++++++++---------- pkg/istio/tracing/zipkin.go | 4 ++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pkg/istio/istio.go b/pkg/istio/istio.go index 01404097..9dca46cf 100644 --- a/pkg/istio/istio.go +++ b/pkg/istio/istio.go @@ -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") @@ -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 } @@ -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 { diff --git a/pkg/istio/tracing/zipkin.go b/pkg/istio/tracing/zipkin.go index 8b9eedde..a13d04d2 100644 --- a/pkg/istio/tracing/zipkin.go +++ b/pkg/istio/tracing/zipkin.go @@ -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] @@ -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 {