diff --git a/pkg/micro/ocdav/option.go b/pkg/micro/ocdav/option.go index 4cf46d2703b..9d7ebdabe41 100644 --- a/pkg/micro/ocdav/option.go +++ b/pkg/micro/ocdav/option.go @@ -30,6 +30,7 @@ import ( "github.com/rs/zerolog" "go-micro.dev/v4/broker" "go.opentelemetry.io/otel/trace" + "google.golang.org/grpc/credentials" ) // Option defines a single option function. @@ -50,11 +51,10 @@ type Options struct { FavoriteManager favorite.Manager GatewaySelector pool.Selectable[gateway.GatewayAPIClient] - TracingEnabled bool - TracingInsecure bool - TracingExporter string - TracingCollector string - TracingEndpoint string + TracingEnabled bool + TracingInsecure bool + TracingEndpoint string + TracingTransportCredentials credentials.TransportCredentials TraceProvider trace.TracerProvider @@ -230,11 +230,25 @@ func LockSystem(val ocdav.LockSystem) Option { } // Tracing enables tracing +// Deprecated: use WithTracingEndpoint and WithTracingEnabled, Collector is unused func Tracing(endpoint, collector string) Option { return func(o *Options) { o.TracingEnabled = true o.TracingEndpoint = endpoint - o.TracingCollector = collector + } +} + +// WithTracingEnabled option +func WithTracingEnabled(enabled bool) Option { + return func(o *Options) { + o.TracingEnabled = enabled + } +} + +// WithTracingEndpoint option +func WithTracingEndpoint(endpoint string) Option { + return func(o *Options) { + o.TracingEndpoint = endpoint } } @@ -246,9 +260,15 @@ func WithTracingInsecure() Option { } // WithTracingExporter option +// Deprecated: unused func WithTracingExporter(exporter string) Option { + return func(o *Options) {} +} + +// WithTracingTransportCredentials option +func WithTracingTransportCredentials(v credentials.TransportCredentials) Option { return func(o *Options) { - o.TracingExporter = exporter + o.TracingTransportCredentials = v } } diff --git a/pkg/micro/ocdav/service.go b/pkg/micro/ocdav/service.go index 29d8b135cf3..252288d5441 100644 --- a/pkg/micro/ocdav/service.go +++ b/pkg/micro/ocdav/service.go @@ -90,9 +90,7 @@ func Service(opts ...Option) (micro.Service, error) { if tp == nil { topts := []rtrace.Option{ - rtrace.WithExporter(sopts.TracingExporter), rtrace.WithEndpoint(sopts.TracingEndpoint), - rtrace.WithCollector(sopts.TracingCollector), rtrace.WithServiceName(sopts.Name), } if sopts.TracingEnabled { @@ -101,6 +99,9 @@ func Service(opts ...Option) (micro.Service, error) { if sopts.TracingInsecure { topts = append(topts, rtrace.WithInsecure()) } + if sopts.TracingTransportCredentials != nil { + topts = append(topts, rtrace.WithTransportCredentials(sopts.TracingTransportCredentials)) + } tp = rtrace.NewTracerProvider(topts...) } if err := useMiddlewares(r, &sopts, revaService, tp); err != nil { diff --git a/pkg/trace/options.go b/pkg/trace/options.go index 7d0646f0f86..fbd8b8237ff 100644 --- a/pkg/trace/options.go +++ b/pkg/trace/options.go @@ -24,6 +24,7 @@ func WithEnabled() Option { } // WithExporter option +// Deprecated: unused func WithExporter(v string) Option { return func(o *Options) { o.Exporter = v @@ -38,6 +39,7 @@ func WithInsecure() Option { } // WithCollector option +// Deprecated: unused func WithCollector(v string) Option { return func(o *Options) { o.Collector = v @@ -57,3 +59,10 @@ func WithServiceName(v string) Option { o.ServiceName = v } } + +// WithTransportCredentials option +func WithTransportCredentials(v credentials.TransportCredentials) Option { + return func(o *Options) { + o.TransportCredentials = v + } +} diff --git a/pkg/trace/trace.go b/pkg/trace/trace.go index 051b9671b64..e96fe10cda4 100644 --- a/pkg/trace/trace.go +++ b/pkg/trace/trace.go @@ -89,10 +89,9 @@ func InitDefaultTracerProvider(collector, endpoint string) { defer defaultProvider.mutex.Unlock() if !defaultProvider.initialized { SetDefaultTracerProvider(getOtlpTracerProvider(Options{ - Enabled: true, - Collector: collector, Endpoint: endpoint, ServiceName: "reva default otlp provider", + Insecure: true, })) } } @@ -107,16 +106,17 @@ func DefaultProvider() trace.TracerProvider { // getOtelTracerProvider returns a new TracerProvider, configure for the specified service func getOtlpTracerProvider(options Options) trace.TracerProvider { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() + transportCredentials := options.TransportCredentials + if options.Insecure { + transportCredentials = insecure.NewCredentials() + } conn, err := grpc.DialContext(ctx, options.Endpoint, - // Note the use of insecure transport here. TLS is recommended in production. - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), + grpc.WithTransportCredentials(transportCredentials), ) if err != nil { - panic(fmt.Errorf("failed to create gRPC connection to collector: %w", err)) + panic(fmt.Errorf("failed to create gRPC connection to endpoint: %w", err)) } exporter, err := otlptracegrpc.New( context.Background(),