Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micro: Add TraceProvider injector. #4040

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/external-traceprovider-micro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Allow to use external trace provider in micro service

Allow injecting of external trace provider in the micro service instead of forcing the initialisation of an internal one.

https://github.com/cs3org/reva/pull/4040
10 changes: 10 additions & 0 deletions pkg/micro/ocdav/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cs3org/reva/v2/pkg/storage/favorite"
"github.com/rs/zerolog"
"go-micro.dev/v4/broker"
"go.opentelemetry.io/otel/trace"
)

// Option defines a single option function.
Expand All @@ -54,6 +55,8 @@ type Options struct {
TracingCollector string
TracingEndpoint string

TraceProvider trace.TracerProvider

MetricsEnabled bool
MetricsNamespace string
MetricsSubsystem string
Expand Down Expand Up @@ -234,6 +237,13 @@ func WithTracingExporter(exporter string) Option {
}
}

// WithTraceProvider option
func WithTraceProvider(provider trace.TracerProvider) Option {
return func(o *Options) {
o.TraceProvider = provider
}
}

// Version provides a function to set the Version config option.
func Version(val string) Option {
return func(o *Options) {
Expand Down
30 changes: 16 additions & 14 deletions pkg/micro/ocdav/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const (

// Service initializes the ocdav service and underlying http server.
func Service(opts ...Option) (micro.Service, error) {

sopts := newOptions(opts...)

// set defaults
Expand Down Expand Up @@ -86,19 +85,23 @@ func Service(opts ...Option) (micro.Service, error) {
// chi.RegisterMethod(ocdav.MethodMkcol)
// chi.RegisterMethod(ocdav.MethodReport)
r := chi.NewRouter()
topts := []rtrace.Option{
rtrace.WithExporter(sopts.TracingExporter),
rtrace.WithEndpoint(sopts.TracingEndpoint),
rtrace.WithCollector(sopts.TracingCollector),
rtrace.WithServiceName(sopts.Name),
}
if sopts.TracingEnabled {
topts = append(topts, rtrace.WithEnabled())
}
if sopts.TracingInsecure {
topts = append(topts, rtrace.WithInsecure())
tp := sopts.TraceProvider

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 {
topts = append(topts, rtrace.WithEnabled())
}
if sopts.TracingInsecure {
topts = append(topts, rtrace.WithInsecure())
}
tp = rtrace.NewTracerProvider(topts...)
}
tp := rtrace.NewTracerProvider(topts...)
if err := useMiddlewares(r, &sopts, revaService, tp); err != nil {
return nil, err
}
Expand Down Expand Up @@ -132,7 +135,6 @@ func Service(opts ...Option) (micro.Service, error) {
}

func setDefaults(sopts *Options) error {

// set defaults
if sopts.Name == "" {
sopts.Name = ServerName
Expand Down