diff --git a/cmd/auth/main.go b/cmd/auth/main.go index 8ece27702..fe66d1260 100644 --- a/cmd/auth/main.go +++ b/cmd/auth/main.go @@ -103,7 +103,7 @@ func main() { } defer db.Close() - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index 421b2560d..0ee7b0693 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -105,7 +105,7 @@ func main() { defer authHandler.Close() logger.Info("Successfully connected to auth grpc server " + authHandler.Secure()) - tp, err := jaeger.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaeger.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/cassandra-writer/main.go b/cmd/cassandra-writer/main.go index 1beb70ad3..4829b6cd5 100644 --- a/cmd/cassandra-writer/main.go +++ b/cmd/cassandra-writer/main.go @@ -89,7 +89,7 @@ func main() { } defer csdSession.Close() - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/certs/main.go b/cmd/certs/main.go index 03426bc07..5e572a632 100644 --- a/cmd/certs/main.go +++ b/cmd/certs/main.go @@ -121,7 +121,7 @@ func main() { logger.Info("Successfully connected to auth grpc server " + authHandler.Secure()) - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/coap/main.go b/cmd/coap/main.go index ea0cc4a34..4eff2a6c8 100644 --- a/cmd/coap/main.go +++ b/cmd/coap/main.go @@ -95,7 +95,7 @@ func main() { logger.Info("Successfully connected to things grpc server " + aHandler.Secure()) - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/http/main.go b/cmd/http/main.go index a0c2c3ec8..5a1a8ba72 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -92,7 +92,7 @@ func main() { logger.Info("Successfully connected to things grpc server " + aHandler.Secure()) - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/influxdb-writer/main.go b/cmd/influxdb-writer/main.go index c8f5bcd84..ee3449e7b 100644 --- a/cmd/influxdb-writer/main.go +++ b/cmd/influxdb-writer/main.go @@ -77,7 +77,7 @@ func main() { return } - tp, err := jaeger.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaeger.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/lora/main.go b/cmd/lora/main.go index 4b0f2457d..9697c9568 100644 --- a/cmd/lora/main.go +++ b/cmd/lora/main.go @@ -102,7 +102,7 @@ func main() { } defer rmConn.Close() - tp, err := jaeger.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaeger.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/mongodb-writer/main.go b/cmd/mongodb-writer/main.go index 11aae4b38..65bc447fc 100644 --- a/cmd/mongodb-writer/main.go +++ b/cmd/mongodb-writer/main.go @@ -79,7 +79,7 @@ func main() { return } - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/mqtt/main.go b/cmd/mqtt/main.go index 3a4583fdb..758e9c9ec 100644 --- a/cmd/mqtt/main.go +++ b/cmd/mqtt/main.go @@ -102,7 +102,7 @@ func main() { Port: cfg.HTTPTargetPort, } - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/opcua/main.go b/cmd/opcua/main.go index 477dc1b1b..5bbd875fd 100644 --- a/cmd/opcua/main.go +++ b/cmd/opcua/main.go @@ -105,7 +105,7 @@ func main() { chanRM := newRouteMapRepositoy(rmConn, channelsRMPrefix, logger) connRM := newRouteMapRepositoy(rmConn, connectionRMPrefix, logger) - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/postgres-writer/main.go b/cmd/postgres-writer/main.go index bfc0f0de5..337da6bc9 100644 --- a/cmd/postgres-writer/main.go +++ b/cmd/postgres-writer/main.go @@ -87,7 +87,7 @@ func main() { } defer db.Close() - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/smpp-notifier/main.go b/cmd/smpp-notifier/main.go index 88003e48d..ad0a1f5ac 100644 --- a/cmd/smpp-notifier/main.go +++ b/cmd/smpp-notifier/main.go @@ -100,7 +100,7 @@ func main() { return } - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/smtp-notifier/main.go b/cmd/smtp-notifier/main.go index 370ba5092..4c2ed2bf5 100644 --- a/cmd/smtp-notifier/main.go +++ b/cmd/smtp-notifier/main.go @@ -103,7 +103,7 @@ func main() { return } - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/things/main.go b/cmd/things/main.go index f725158a6..8e7463885 100644 --- a/cmd/things/main.go +++ b/cmd/things/main.go @@ -114,7 +114,7 @@ func main() { } defer db.Close() - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/timescale-writer/main.go b/cmd/timescale-writer/main.go index 4cd810c91..7c1cd89cb 100644 --- a/cmd/timescale-writer/main.go +++ b/cmd/timescale-writer/main.go @@ -89,7 +89,7 @@ func main() { } defer db.Close() - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/twins/main.go b/cmd/twins/main.go index 4437a3a5d..5945eaab3 100644 --- a/cmd/twins/main.go +++ b/cmd/twins/main.go @@ -106,7 +106,7 @@ func main() { return } - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/users/main.go b/cmd/users/main.go index d72560923..14db0ce61 100644 --- a/cmd/users/main.go +++ b/cmd/users/main.go @@ -127,7 +127,7 @@ func main() { } defer db.Close() - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/cmd/ws/main.go b/cmd/ws/main.go index 06724b0e4..c134f4f58 100644 --- a/cmd/ws/main.go +++ b/cmd/ws/main.go @@ -96,7 +96,7 @@ func main() { logger.Info("Successfully connected to things grpc server " + aHandler.Secure()) - tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) + tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio) if err != nil { logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err)) exitCode = 1 diff --git a/go.mod b/go.mod index 862998d97..134aef644 100644 --- a/go.mod +++ b/go.mod @@ -50,7 +50,8 @@ require ( go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 go.opentelemetry.io/otel v1.19.0 - go.opentelemetry.io/otel/exporters/jaeger v1.17.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 go.opentelemetry.io/otel/sdk v1.19.0 go.opentelemetry.io/otel/trace v1.19.0 golang.org/x/crypto v0.14.0 @@ -213,6 +214,7 @@ require ( github.com/yosssi/ace v0.0.5 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/proto/otlp v1.0.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/arch v0.5.0 // indirect diff --git a/go.sum b/go.sum index 57d8e23b8..456226b34 100644 --- a/go.sum +++ b/go.sum @@ -1258,14 +1258,18 @@ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 h1:x8Z78aZ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0/go.mod h1:62CPTSry9QZtOaSsE3tOzhx6LzDhHnXJ6xHeMNNiM6Q= go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= -go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4= -go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= diff --git a/internal/clients/jaeger/provider.go b/internal/clients/jaeger/provider.go index 9a7510635..d5392234f 100644 --- a/internal/clients/jaeger/provider.go +++ b/internal/clients/jaeger/provider.go @@ -6,23 +6,26 @@ package jaeger import ( "context" "errors" + "net/url" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - jaegerexp "go.opentelemetry.io/otel/exporters/jaeger" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" "go.opentelemetry.io/otel/sdk/resource" tracesdk "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.12.0" ) var ( - errNoURL = errors.New("URL is empty") - errNoSvcName = errors.New("service Name is empty") + errNoURL = errors.New("URL is empty") + errNoSvcName = errors.New("service Name is empty") + errUnsupportedTraceURLScheme = errors.New("unsupported tracing url scheme") ) // NewProvider initializes Jaeger TraceProvider. -func NewProvider(svcName, url, instanceID string, fraction float64) (*tracesdk.TracerProvider, error) { - if url == "" { +func NewProvider(ctx context.Context, svcName, jaegerUrl, instanceID string, fraction float64) (*tracesdk.TracerProvider, error) { + if jaegerUrl == "" { return nil, errNoURL } @@ -30,17 +33,33 @@ func NewProvider(svcName, url, instanceID string, fraction float64) (*tracesdk.T return nil, errNoSvcName } - exporter, err := jaegerexp.New(jaegerexp.WithCollectorEndpoint(jaegerexp.WithEndpoint(url))) + url, err := url.Parse(jaegerUrl) if err != nil { return nil, err } + var exporter *otlptrace.Exporter + switch url.Scheme { + case "http": + exporter, err = otlptracehttp.New(ctx, otlptracehttp.WithEndpoint(url.Host), otlptracehttp.WithURLPath(url.Path), otlptracehttp.WithInsecure()) + if err != nil { + return nil, err + } + case "https": + exporter, err = otlptracehttp.New(ctx, otlptracehttp.WithEndpoint(url.Host), otlptracehttp.WithURLPath(url.Path)) + if err != nil { + return nil, err + } + default: + return nil, errUnsupportedTraceURLScheme + } + attributes := []attribute.KeyValue{ semconv.ServiceNameKey.String(svcName), attribute.String("host.id", instanceID), } - hostAttr, err := resource.New(context.TODO(), resource.WithHost(), resource.WithOSDescription(), resource.WithContainer()) + hostAttr, err := resource.New(ctx, resource.WithHost(), resource.WithOSDescription(), resource.WithContainer()) if err != nil { return nil, err }