diff --git a/changelog/unreleased/move-graph-to-service-tracerprovider.md b/changelog/unreleased/move-graph-to-service-tracerprovider.md new file mode 100644 index 00000000000..57d23b0330a --- /dev/null +++ b/changelog/unreleased/move-graph-to-service-tracerprovider.md @@ -0,0 +1,6 @@ +Enhancement: Move graph to service tracerprovider + +This moves the graph to initialise a service tracer provider at service initialisation time, +instead of using a package global tracer provider. + +https://github.com/owncloud/ocis/pull/6695 diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index 44a9600bf57..0372eef472e 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -7,6 +7,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" + "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/graph/pkg/config" "github.com/owncloud/ocis/v2/services/graph/pkg/config/parser" @@ -14,7 +15,6 @@ import ( "github.com/owncloud/ocis/v2/services/graph/pkg/metrics" "github.com/owncloud/ocis/v2/services/graph/pkg/server/debug" "github.com/owncloud/ocis/v2/services/graph/pkg/server/http" - "github.com/owncloud/ocis/v2/services/graph/pkg/tracing" "github.com/urfave/cli/v2" ) @@ -29,11 +29,15 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) - err := tracing.Configure(cfg) + traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { return err } - err = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) + err = ogrpc.Configure( + append( + ogrpc.GetClientOptions(cfg.GRPCClientTLS), + ogrpc.WithTraceProvider(traceProvider), + )...) if err != nil { return err } @@ -58,7 +62,6 @@ func Server(cfg *config.Config) *cli.Command { http.Config(cfg), http.Metrics(mtrcs), ) - if err != nil { logger.Error().Err(err).Str("transport", "http").Msg("Failed to initialize server") return err @@ -82,7 +85,6 @@ func Server(cfg *config.Config) *cli.Command { debug.Context(ctx), debug.Config(cfg), ) - if err != nil { logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") return err diff --git a/services/graph/pkg/config/tracing.go b/services/graph/pkg/config/tracing.go index 35c004a9b7a..c117a563dc8 100644 --- a/services/graph/pkg/config/tracing.go +++ b/services/graph/pkg/config/tracing.go @@ -1,5 +1,7 @@ package config +import "github.com/owncloud/ocis/v2/ocis-pkg/tracing" + // Tracing defines the available tracing configuration. type Tracing struct { Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;GRAPH_TRACING_ENABLED" desc:"Activates tracing."` @@ -7,3 +9,13 @@ type Tracing struct { Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;GRAPH_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;GRAPH_TRACING_COLLECTOR" desc:"The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. Only used if the tracing endpoint is unset."` } + +// Convert Tracing to the tracing package's Config struct. +func (t Tracing) Convert() tracing.Config { + return tracing.Config{ + Enabled: t.Enabled, + Type: t.Type, + Endpoint: t.Endpoint, + Collector: t.Collector, + } +} diff --git a/services/graph/pkg/server/http/option.go b/services/graph/pkg/server/http/option.go index 641c8438a72..53a4b184e32 100644 --- a/services/graph/pkg/server/http/option.go +++ b/services/graph/pkg/server/http/option.go @@ -7,6 +7,7 @@ import ( "github.com/owncloud/ocis/v2/services/graph/pkg/config" "github.com/owncloud/ocis/v2/services/graph/pkg/metrics" "github.com/urfave/cli/v2" + "go.opentelemetry.io/otel/trace" ) // Option defines a single option function. @@ -14,12 +15,13 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { - Logger log.Logger - Context context.Context - Config *config.Config - Metrics *metrics.Metrics - Flags []cli.Flag - Namespace string + Logger log.Logger + Context context.Context + Config *config.Config + Metrics *metrics.Metrics + Flags []cli.Flag + Namespace string + TraceProvider trace.TracerProvider } // newOptions initializes the available default options. @@ -74,3 +76,10 @@ func Namespace(val string) Option { o.Namespace = val } } + +// TraceProvider provides a function to set the TraceProvider option. +func TraceProvider(val trace.TracerProvider) Option { + return func(o *Options) { + o.TraceProvider = val + } +} diff --git a/services/graph/pkg/server/http/server.go b/services/graph/pkg/server/http/server.go index 203ac1ee707..76bd11966c4 100644 --- a/services/graph/pkg/server/http/server.go +++ b/services/graph/pkg/server/http/server.go @@ -26,7 +26,6 @@ import ( settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" graphMiddleware "github.com/owncloud/ocis/v2/services/graph/pkg/middleware" svc "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0" - "github.com/owncloud/ocis/v2/services/graph/pkg/tracing" "github.com/pkg/errors" "go-micro.dev/v4" "go-micro.dev/v4/events" @@ -116,7 +115,7 @@ func Server(opts ...Option) (http.Service, error) { var requireAdminMiddleware func(stdhttp.Handler) stdhttp.Handler var roleService svc.RoleService var gatewaySelector pool.Selectable[gateway.GatewayAPIClient] - grpcClient, err := grpc.NewClient(append(grpc.GetClientOptions(options.Config.GRPCClientTLS), grpc.WithTraceProvider(tracing.TraceProvider))...) + grpcClient, err := grpc.NewClient(append(grpc.GetClientOptions(options.Config.GRPCClientTLS), grpc.WithTraceProvider(options.TraceProvider))...) if err != nil { return http.Service{}, err } @@ -164,18 +163,13 @@ func Server(opts ...Option) (http.Service, error) { svc.WithSearchService(searchsvc.NewSearchProviderService("com.owncloud.api.search", grpcClient)), svc.KeycloakClient(keyCloakClient), svc.EventHistoryClient(hClient), + svc.TraceProvider(options.TraceProvider), ) if err != nil { return http.Service{}, errors.New("could not initialize graph service") } - { - handle = svc.NewInstrument(handle, options.Metrics) - handle = svc.NewLogging(handle, options.Logger) - handle = svc.NewTracing(handle) - } - if err := micro.RegisterHandler(service.Server(), handle); err != nil { return http.Service{}, err } diff --git a/services/graph/pkg/service/v0/drives.go b/services/graph/pkg/service/v0/drives.go index f5832b27582..2e3898e678a 100644 --- a/services/graph/pkg/service/v0/drives.go +++ b/services/graph/pkg/service/v0/drives.go @@ -31,7 +31,6 @@ import ( v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0" settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode" - gtracing "github.com/owncloud/ocis/v2/services/graph/pkg/tracing" settingsServiceExt "github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults" "github.com/pkg/errors" merrors "go-micro.dev/v4/errors" @@ -161,7 +160,6 @@ func (g Graph) GetSingleDrive(w http.ResponseWriter, r *http.Request) { logger := g.logger.SubloggerWithRequestID(r.Context()) logger.Info().Interface("query", r.URL.Query()).Msg("calling get drive") driveID, err := url.PathUnescape(chi.URLParam(r, "driveID")) - if err != nil { logger.Debug().Err(err).Str("driveID", chi.URLParam(r, "driveID")).Msg("could not get drive: unescaping drive id failed") errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "unescaping drive id failed") @@ -602,7 +600,7 @@ func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*stor return nil, err } - grpcClient, err := grpc.NewClient(append(grpc.GetClientOptions(g.config.GRPCClientTLS), grpc.WithTraceProvider(gtracing.TraceProvider))...) + grpcClient, err := grpc.NewClient(append(grpc.GetClientOptions(g.config.GRPCClientTLS), grpc.WithTraceProvider(g.traceProvider))...) if err != nil { return nil, err } @@ -1099,7 +1097,6 @@ func (g Graph) DeleteDrive(w http.ResponseWriter, r *http.Request) { errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "grpc error") return } - } func sortSpaces(req *godata.GoDataRequest, spaces []*libregraph.Drive) ([]*libregraph.Drive, error) { diff --git a/services/graph/pkg/service/v0/graph.go b/services/graph/pkg/service/v0/graph.go index 86045e00ab9..9e5f33d7e27 100644 --- a/services/graph/pkg/service/v0/graph.go +++ b/services/graph/pkg/service/v0/graph.go @@ -23,6 +23,7 @@ import ( "github.com/owncloud/ocis/v2/services/graph/pkg/identity" "go-micro.dev/v4/client" mevents "go-micro.dev/v4/events" + "go.opentelemetry.io/otel/trace" "google.golang.org/protobuf/types/known/emptypb" ) @@ -73,6 +74,7 @@ type Graph struct { searchService searchsvc.SearchProviderService keycloakClient keycloak.Client historyClient ehsvc.EventHistoryService + traceProvider trace.TracerProvider } // ServeHTTP implements the Service interface. diff --git a/services/graph/pkg/service/v0/instrument.go b/services/graph/pkg/service/v0/instrument.go deleted file mode 100644 index 18125ece969..00000000000 --- a/services/graph/pkg/service/v0/instrument.go +++ /dev/null @@ -1,310 +0,0 @@ -package svc - -import ( - "net/http" - - "github.com/owncloud/ocis/v2/services/graph/pkg/metrics" -) - -// NewInstrument returns a service that instruments metrics. -func NewInstrument(next Service, metrics *metrics.Metrics) instrument { - return instrument{ - next: next, - metrics: metrics, - } -} - -type instrument struct { - next Service - metrics *metrics.Metrics -} - -// ServeHTTP implements the Service interface. -func (i instrument) ServeHTTP(w http.ResponseWriter, r *http.Request) { - i.next.ServeHTTP(w, r) -} - -// ListApplications implements the Service interface. -func (i instrument) ListApplications(w http.ResponseWriter, r *http.Request) { - i.next.ListApplications(w, r) -} - -// GetApplication implements the Service interface. -func (i instrument) GetApplication(w http.ResponseWriter, r *http.Request) { - i.next.GetApplication(w, r) -} - -// GetMe implements the Service interface. -func (i instrument) GetMe(w http.ResponseWriter, r *http.Request) { - i.next.GetMe(w, r) -} - -// GetUsers implements the Service interface. -func (i instrument) GetUsers(w http.ResponseWriter, r *http.Request) { - i.next.GetUsers(w, r) -} - -// GetUser implements the Service interface. -func (i instrument) GetUser(w http.ResponseWriter, r *http.Request) { - i.next.GetUser(w, r) -} - -// PostUser implements the Service interface. -func (i instrument) PostUser(w http.ResponseWriter, r *http.Request) { - i.next.PostUser(w, r) -} - -// DeleteUser implements the Service interface. -func (i instrument) DeleteUser(w http.ResponseWriter, r *http.Request) { - i.next.DeleteUser(w, r) -} - -// PatchUser implements the Service interface. -func (i instrument) PatchUser(w http.ResponseWriter, r *http.Request) { - i.next.PatchUser(w, r) -} - -// ChangeOwnPassword implements the Service interface. -func (i instrument) ChangeOwnPassword(w http.ResponseWriter, r *http.Request) { - i.next.ChangeOwnPassword(w, r) -} - -// ListAppRoleAssignments implements the Service interface. -func (i instrument) ListAppRoleAssignments(w http.ResponseWriter, r *http.Request) { - i.next.ListAppRoleAssignments(w, r) -} - -// CreateAppRoleAssignment implements the Service interface. -func (i instrument) CreateAppRoleAssignment(w http.ResponseWriter, r *http.Request) { - i.next.CreateAppRoleAssignment(w, r) -} - -// DeleteAppRoleAssignment implements the Service interface. -func (i instrument) DeleteAppRoleAssignment(w http.ResponseWriter, r *http.Request) { - i.next.DeleteAppRoleAssignment(w, r) -} - -// GetGroups implements the Service interface. -func (i instrument) GetGroups(w http.ResponseWriter, r *http.Request) { - i.next.GetGroups(w, r) -} - -// GetGroup implements the Service interface. -func (i instrument) GetGroup(w http.ResponseWriter, r *http.Request) { - i.next.GetGroup(w, r) -} - -// PostGroup implements the Service interface. -func (i instrument) PostGroup(w http.ResponseWriter, r *http.Request) { - i.next.PostGroup(w, r) -} - -// PatchGroup implements the Service interface. -func (i instrument) PatchGroup(w http.ResponseWriter, r *http.Request) { - i.next.PatchGroup(w, r) -} - -// DeleteGroup implements the Service interface. -func (i instrument) DeleteGroup(w http.ResponseWriter, r *http.Request) { - i.next.DeleteGroup(w, r) -} - -// GetGroupMembers implements the Service interface. -func (i instrument) GetGroupMembers(w http.ResponseWriter, r *http.Request) { - i.next.GetGroupMembers(w, r) -} - -// PostGroupMember implements the Service interface. -func (i instrument) PostGroupMember(w http.ResponseWriter, r *http.Request) { - i.next.PostGroupMember(w, r) -} - -// DeleteGroupMember implements the Service interface. -func (i instrument) DeleteGroupMember(w http.ResponseWriter, r *http.Request) { - i.next.DeleteGroupMember(w, r) -} - -// GetEducationSchools implements the Service interface. -func (i instrument) GetEducationSchools(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationSchools(w, r) -} - -// GetEducationSchool implements the Service interface. -func (i instrument) GetEducationSchool(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationSchool(w, r) -} - -// PostEducationSchool implements the Service interface. -func (i instrument) PostEducationSchool(w http.ResponseWriter, r *http.Request) { - i.next.PostEducationSchool(w, r) -} - -// PatchEducationSchool implements the Service interface. -func (i instrument) PatchEducationSchool(w http.ResponseWriter, r *http.Request) { - i.next.PatchEducationSchool(w, r) -} - -// DeleteEducationSchool implements the Service interface. -func (i instrument) DeleteEducationSchool(w http.ResponseWriter, r *http.Request) { - i.next.DeleteEducationSchool(w, r) -} - -// GetEducationSchoolUsers implements the Service interface. -func (i instrument) GetEducationSchoolUsers(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationSchoolUsers(w, r) -} - -// PostEducationSchoolUser implements the Service interface. -func (i instrument) PostEducationSchoolUser(w http.ResponseWriter, r *http.Request) { - i.next.PostEducationSchoolUser(w, r) -} - -// DeleteEducationSchoolUser implements the Service interface. -func (i instrument) DeleteEducationSchoolUser(w http.ResponseWriter, r *http.Request) { - i.next.DeleteEducationSchoolUser(w, r) -} - -// GetEducationSchoolClasses implements the Service interface. -func (i instrument) GetEducationSchoolClasses(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationSchoolClasses(w, r) -} - -// PostEducationSchoolClass implements the Service interface. -func (i instrument) PostEducationSchoolClass(w http.ResponseWriter, r *http.Request) { - i.next.PostEducationSchoolClass(w, r) -} - -// DeleteEducationSchoolClass implements the Service interface. -func (i instrument) DeleteEducationSchoolClass(w http.ResponseWriter, r *http.Request) { - i.next.DeleteEducationSchoolClass(w, r) -} - -// GetEducationClasses implements the Service interface. -func (i instrument) GetEducationClasses(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationClasses(w, r) -} - -// GetEducationClass implements the Service interface. -func (i instrument) GetEducationClass(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationClass(w, r) -} - -// PostEducationClass implements the Service interface. -func (i instrument) PostEducationClass(w http.ResponseWriter, r *http.Request) { - i.next.PostEducationClass(w, r) -} - -// PatchEducationClass implements the Service interface. -func (i instrument) PatchEducationClass(w http.ResponseWriter, r *http.Request) { - i.next.PatchEducationClass(w, r) -} - -// DeleteEducationClass implements the Service interface. -func (i instrument) DeleteEducationClass(w http.ResponseWriter, r *http.Request) { - i.next.DeleteEducationClass(w, r) -} - -// GetEducationClassMembers implements the Service interface. -func (i instrument) GetEducationClassMembers(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationClassMembers(w, r) -} - -// PostEducationClassMember implements the Service interface. -func (i instrument) PostEducationClassMember(w http.ResponseWriter, r *http.Request) { - i.next.PostEducationClassMember(w, r) -} - -// DeleteEducationClassMember implements the Service interface. -func (i instrument) DeleteEducationClassMember(w http.ResponseWriter, r *http.Request) { - i.next.DeleteEducationClassMember(w, r) -} - -// GetEducationUsers implements the Service interface. -func (i instrument) GetEducationUsers(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationUsers(w, r) -} - -// GetEducationUser implements the Service interface. -func (i instrument) GetEducationUser(w http.ResponseWriter, r *http.Request) { - i.next.GetEducationUser(w, r) -} - -// PostEducationUser implements the Service interface. -func (i instrument) PostEducationUser(w http.ResponseWriter, r *http.Request) { - i.next.PostEducationUser(w, r) -} - -// DeleteEducationUser implements the Service interface. -func (i instrument) DeleteEducationUser(w http.ResponseWriter, r *http.Request) { - i.next.DeleteEducationUser(w, r) -} - -// PatchEducationUser implements the Service interface. -func (i instrument) PatchEducationUser(w http.ResponseWriter, r *http.Request) { - i.next.PatchEducationUser(w, r) -} - -// GetDrives implements the Service interface. -func (i instrument) GetDrives(w http.ResponseWriter, r *http.Request) { - i.next.GetDrives(w, r) -} - -// GetSingleDrive implements the Service interface. -func (i instrument) GetSingleDrive(w http.ResponseWriter, r *http.Request) { - i.next.GetDrives(w, r) -} - -// UpdateDrive implements the Service interface. -func (i instrument) UpdateDrive(w http.ResponseWriter, r *http.Request) { - i.next.GetDrives(w, r) -} - -// DeleteDrive implements the Service interface. -func (i instrument) DeleteDrive(w http.ResponseWriter, r *http.Request) { - i.next.GetDrives(w, r) -} - -// GetAllDrives implements the Service interface. -func (i instrument) GetAllDrives(w http.ResponseWriter, r *http.Request) { - i.next.GetAllDrives(w, r) -} - -// CreateDrive implements the Service interface. -func (i instrument) CreateDrive(w http.ResponseWriter, r *http.Request) { - i.next.CreateDrive(w, r) -} - -// GetRootDriveChildren implements the Service interface. -func (i instrument) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) { - i.next.GetRootDriveChildren(w, r) -} - -// GetTags implements the Service interface. -func (i instrument) GetTags(w http.ResponseWriter, r *http.Request) { - i.next.GetTags(w, r) -} - -// AssignTags implements the Service interface. -func (i instrument) AssignTags(w http.ResponseWriter, r *http.Request) { - i.next.AssignTags(w, r) -} - -// UnassignTags implements the Service interface. -func (i instrument) UnassignTags(w http.ResponseWriter, r *http.Request) { - i.next.UnassignTags(w, r) -} - -// GetEducationClassTeachers implements the Service interface. -func (i instrument) GetEducationClassTeachers(w http.ResponseWriter, r *http.Request) { - i.next.UnassignTags(w, r) -} - -// PostEducationClassTeacher implements the Service interface. -func (i instrument) PostEducationClassTeacher(w http.ResponseWriter, r *http.Request) { - i.next.UnassignTags(w, r) -} - -// DeleteEducationClassTeacher implements the Service interface. -func (i instrument) DeleteEducationClassTeacher(w http.ResponseWriter, r *http.Request) { - i.next.UnassignTags(w, r) -} diff --git a/services/graph/pkg/service/v0/logging.go b/services/graph/pkg/service/v0/logging.go deleted file mode 100644 index 82156c9019a..00000000000 --- a/services/graph/pkg/service/v0/logging.go +++ /dev/null @@ -1,310 +0,0 @@ -package svc - -import ( - "net/http" - - "github.com/owncloud/ocis/v2/ocis-pkg/log" -) - -// NewLogging returns a service that logs messages. -func NewLogging(next Service, logger log.Logger) logging { - return logging{ - next: next, - logger: logger, - } -} - -type logging struct { - next Service - logger log.Logger -} - -// ServeHTTP implements the Service interface. -func (l logging) ServeHTTP(w http.ResponseWriter, r *http.Request) { - l.next.ServeHTTP(w, r) -} - -// ListApplications implements the Service interface. -func (l logging) ListApplications(w http.ResponseWriter, r *http.Request) { - l.next.ListApplications(w, r) -} - -// GetApplication implements the Service interface. -func (l logging) GetApplication(w http.ResponseWriter, r *http.Request) { - l.next.GetApplication(w, r) -} - -// GetMe implements the Service interface. -func (l logging) GetMe(w http.ResponseWriter, r *http.Request) { - l.next.GetMe(w, r) -} - -// GetUsers implements the Service interface. -func (l logging) GetUsers(w http.ResponseWriter, r *http.Request) { - l.next.GetUsers(w, r) -} - -// GetUser implements the Service interface. -func (l logging) GetUser(w http.ResponseWriter, r *http.Request) { - l.next.GetUser(w, r) -} - -// PostUser implements the Service interface. -func (l logging) PostUser(w http.ResponseWriter, r *http.Request) { - l.next.PostUser(w, r) -} - -// DeleteUser implements the Service interface. -func (l logging) DeleteUser(w http.ResponseWriter, r *http.Request) { - l.next.DeleteUser(w, r) -} - -// PatchUser implements the Service interface. -func (l logging) PatchUser(w http.ResponseWriter, r *http.Request) { - l.next.PatchUser(w, r) -} - -// ChangeOwnPassword implements the Service interface. -func (l logging) ChangeOwnPassword(w http.ResponseWriter, r *http.Request) { - l.next.ChangeOwnPassword(w, r) -} - -// ListAppRoleAssignments implements the Service interface. -func (l logging) ListAppRoleAssignments(w http.ResponseWriter, r *http.Request) { - l.next.ListAppRoleAssignments(w, r) -} - -// CreateAppRoleAssignment implements the Service interface. -func (l logging) CreateAppRoleAssignment(w http.ResponseWriter, r *http.Request) { - l.next.CreateAppRoleAssignment(w, r) -} - -// DeleteAppRoleAssignment implements the Service interface. -func (l logging) DeleteAppRoleAssignment(w http.ResponseWriter, r *http.Request) { - l.next.DeleteAppRoleAssignment(w, r) -} - -// GetGroups implements the Service interface. -func (l logging) GetGroups(w http.ResponseWriter, r *http.Request) { - l.next.GetGroups(w, r) -} - -// GetGroup implements the Service interface. -func (l logging) GetGroup(w http.ResponseWriter, r *http.Request) { - l.next.GetGroup(w, r) -} - -// PostGroup implements the Service interface. -func (l logging) PostGroup(w http.ResponseWriter, r *http.Request) { - l.next.PostGroup(w, r) -} - -// PatchGroup implements the Service interface. -func (l logging) PatchGroup(w http.ResponseWriter, r *http.Request) { - l.next.PatchGroup(w, r) -} - -// DeleteGroup implements the Service interface. -func (l logging) DeleteGroup(w http.ResponseWriter, r *http.Request) { - l.next.DeleteGroup(w, r) -} - -// GetGroupMembers implements the Service interface. -func (l logging) GetGroupMembers(w http.ResponseWriter, r *http.Request) { - l.next.GetGroupMembers(w, r) -} - -// PostGroupMember implements the Service interface. -func (l logging) PostGroupMember(w http.ResponseWriter, r *http.Request) { - l.next.PostGroupMember(w, r) -} - -// DeleteGroupMember implements the Service interface. -func (l logging) DeleteGroupMember(w http.ResponseWriter, r *http.Request) { - l.next.DeleteGroupMember(w, r) -} - -// GetEducationSchools implements the Service interface. -func (l logging) GetEducationSchools(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationSchools(w, r) -} - -// GetEducationSchool implements the Service interface. -func (l logging) GetEducationSchool(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationSchool(w, r) -} - -// PostEducationSchool implements the Service interface. -func (l logging) PostEducationSchool(w http.ResponseWriter, r *http.Request) { - l.next.PostEducationSchool(w, r) -} - -// PatchEducationSchool implements the Service interface. -func (l logging) PatchEducationSchool(w http.ResponseWriter, r *http.Request) { - l.next.PatchEducationSchool(w, r) -} - -// DeleteEducationSchool implements the Service interface. -func (l logging) DeleteEducationSchool(w http.ResponseWriter, r *http.Request) { - l.next.DeleteEducationSchool(w, r) -} - -// GetEducationSchoolUsers implements the Service interface. -func (l logging) GetEducationSchoolUsers(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationSchoolUsers(w, r) -} - -// PostEducationSchoolUser implements the Service interface. -func (l logging) PostEducationSchoolUser(w http.ResponseWriter, r *http.Request) { - l.next.PostEducationSchoolUser(w, r) -} - -// DeleteEducationSchoolUser implements the Service interface. -func (l logging) DeleteEducationSchoolUser(w http.ResponseWriter, r *http.Request) { - l.next.DeleteEducationSchoolUser(w, r) -} - -// GetEducationSchoolClasses implements the Service interface. -func (l logging) GetEducationSchoolClasses(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationSchoolClasses(w, r) -} - -// PostEducationSchoolClass implements the Service interface. -func (l logging) PostEducationSchoolClass(w http.ResponseWriter, r *http.Request) { - l.next.PostEducationSchoolClass(w, r) -} - -// DeleteEducationSchoolClass implements the Service interface. -func (l logging) DeleteEducationSchoolClass(w http.ResponseWriter, r *http.Request) { - l.next.DeleteEducationSchoolClass(w, r) -} - -// GetEducationClasses implements the Service interface. -func (l logging) GetEducationClasses(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationClasses(w, r) -} - -// GetEducationClass implements the Service interface. -func (l logging) GetEducationClass(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationClass(w, r) -} - -// PostEducationClass implements the Service interface. -func (l logging) PostEducationClass(w http.ResponseWriter, r *http.Request) { - l.next.PostEducationClass(w, r) -} - -// PatchEducationClass implements the Service interface. -func (l logging) PatchEducationClass(w http.ResponseWriter, r *http.Request) { - l.next.PatchEducationClass(w, r) -} - -// DeleteEducationClass implements the Service interface. -func (l logging) DeleteEducationClass(w http.ResponseWriter, r *http.Request) { - l.next.DeleteEducationClass(w, r) -} - -// GetEducationClassMembers implements the Service interface. -func (l logging) GetEducationClassMembers(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationClassMembers(w, r) -} - -// PostEducationClassMember implements the Service interface. -func (l logging) PostEducationClassMember(w http.ResponseWriter, r *http.Request) { - l.next.PostEducationClassMember(w, r) -} - -// DeleteEducationClassMember implements the Service interface. -func (l logging) DeleteEducationClassMember(w http.ResponseWriter, r *http.Request) { - l.next.DeleteEducationClassMember(w, r) -} - -// GetEducationUsers implements the Service interface. -func (l logging) GetEducationUsers(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationUsers(w, r) -} - -// GetEducationUser implements the Service interface. -func (l logging) GetEducationUser(w http.ResponseWriter, r *http.Request) { - l.next.GetEducationUser(w, r) -} - -// PostEducationUser implements the Service interface. -func (l logging) PostEducationUser(w http.ResponseWriter, r *http.Request) { - l.next.PostEducationUser(w, r) -} - -// DeleteEducationUser implements the Service interface. -func (l logging) DeleteEducationUser(w http.ResponseWriter, r *http.Request) { - l.next.DeleteEducationUser(w, r) -} - -// PatchEducationUser implements the Service interface. -func (l logging) PatchEducationUser(w http.ResponseWriter, r *http.Request) { - l.next.PatchEducationUser(w, r) -} - -// GetDrives implements the Service interface. -func (l logging) GetDrives(w http.ResponseWriter, r *http.Request) { - l.next.GetDrives(w, r) -} - -// GetSingleDrive implements the Service interface. -func (l logging) GetSingleDrive(w http.ResponseWriter, r *http.Request) { - l.next.GetDrives(w, r) -} - -// UpdateDrive implements the Service interface. -func (l logging) UpdateDrive(w http.ResponseWriter, r *http.Request) { - l.next.GetDrives(w, r) -} - -// DeleteDrive implements the Service interface. -func (l logging) DeleteDrive(w http.ResponseWriter, r *http.Request) { - l.next.GetDrives(w, r) -} - -// GetAllDrives implements the Service interface. -func (l logging) GetAllDrives(w http.ResponseWriter, r *http.Request) { - l.next.GetAllDrives(w, r) -} - -// CreateDrive implements the Service interface. -func (l logging) CreateDrive(w http.ResponseWriter, r *http.Request) { - l.next.CreateDrive(w, r) -} - -// GetRootDriveChildren implements the Service interface. -func (l logging) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) { - l.next.GetRootDriveChildren(w, r) -} - -// GetTags implements the Service interface. -func (l logging) GetTags(w http.ResponseWriter, r *http.Request) { - l.next.GetTags(w, r) -} - -// AssignTags implements the Service interface. -func (l logging) AssignTags(w http.ResponseWriter, r *http.Request) { - l.next.AssignTags(w, r) -} - -// UnassignTags implements the Service interface. -func (l logging) UnassignTags(w http.ResponseWriter, r *http.Request) { - l.next.UnassignTags(w, r) -} - -// GetEducationClassTeachers implements the Service interface. -func (l logging) GetEducationClassTeachers(w http.ResponseWriter, r *http.Request) { - l.next.UnassignTags(w, r) -} - -// PostEducationClassTeacher implements the Service interface. -func (l logging) PostEducationClassTeacher(w http.ResponseWriter, r *http.Request) { - l.next.UnassignTags(w, r) -} - -// DeleteEducationClassTeacher implements the Service interface. -func (l logging) DeleteEducationClassTeacher(w http.ResponseWriter, r *http.Request) { - l.next.UnassignTags(w, r) -} diff --git a/services/graph/pkg/service/v0/option.go b/services/graph/pkg/service/v0/option.go index a13714f54d3..9ed23fb4a12 100644 --- a/services/graph/pkg/service/v0/option.go +++ b/services/graph/pkg/service/v0/option.go @@ -14,6 +14,7 @@ import ( settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" "github.com/owncloud/ocis/v2/services/graph/pkg/config" "github.com/owncloud/ocis/v2/services/graph/pkg/identity" + "go.opentelemetry.io/otel/trace" ) // Option defines a single option function. @@ -35,6 +36,7 @@ type Options struct { SearchService searchsvc.SearchProviderService KeycloakClient keycloak.Client EventHistoryClient ehsvc.EventHistoryService + TraceProvider trace.TracerProvider } // newOptions initializes the available default options. @@ -145,3 +147,10 @@ func EventHistoryClient(val ehsvc.EventHistoryService) Option { o.EventHistoryClient = val } } + +// TraceProvider provides a function to set the TraceProvider option. +func TraceProvider(val trace.TracerProvider) Option { + return func(o *Options) { + o.TraceProvider = val + } +} diff --git a/services/graph/pkg/service/v0/service.go b/services/graph/pkg/service/v0/service.go index 404e10a4849..98a397847b0 100644 --- a/services/graph/pkg/service/v0/service.go +++ b/services/graph/pkg/service/v0/service.go @@ -25,7 +25,6 @@ import ( "github.com/owncloud/ocis/v2/services/graph/pkg/identity" "github.com/owncloud/ocis/v2/services/graph/pkg/identity/ldap" graphm "github.com/owncloud/ocis/v2/services/graph/pkg/middleware" - gtracing "github.com/owncloud/ocis/v2/services/graph/pkg/tracing" microstore "go-micro.dev/v4/store" ) @@ -151,6 +150,7 @@ func NewService(opts ...Option) (Graph, error) { identityEducationBackend: options.IdentityEducationBackend, keycloakClient: options.KeycloakClient, historyClient: options.EventHistoryClient, + traceProvider: options.TraceProvider, } if err := setIdentityBackends(options, &svc); err != nil { @@ -158,7 +158,7 @@ func NewService(opts ...Option) (Graph, error) { } if options.PermissionService == nil { - grpcClient, err := grpc.NewClient(append(grpc.GetClientOptions(options.Config.GRPCClientTLS), grpc.WithTraceProvider(gtracing.TraceProvider))...) + grpcClient, err := grpc.NewClient(append(grpc.GetClientOptions(options.Config.GRPCClientTLS), grpc.WithTraceProvider(options.TraceProvider))...) if err != nil { return svc, err } diff --git a/services/graph/pkg/service/v0/tracing.go b/services/graph/pkg/service/v0/tracing.go deleted file mode 100644 index ad4a6b5c7de..00000000000 --- a/services/graph/pkg/service/v0/tracing.go +++ /dev/null @@ -1,306 +0,0 @@ -package svc - -import ( - "net/http" -) - -// NewTracing returns a service that instruments traces. -func NewTracing(next Service) tracing { - return tracing{ - next: next, - } -} - -type tracing struct { - next Service -} - -// ServeHTTP implements the Service interface. -func (t tracing) ServeHTTP(w http.ResponseWriter, r *http.Request) { - t.next.ServeHTTP(w, r) -} - -// ListApplications implements the Service interface. -func (t tracing) ListApplications(w http.ResponseWriter, r *http.Request) { - t.next.ListApplications(w, r) -} - -// GetApplication implements the Service interface. -func (t tracing) GetApplication(w http.ResponseWriter, r *http.Request) { - t.next.GetApplication(w, r) -} - -// GetMe implements the Service interface. -func (t tracing) GetMe(w http.ResponseWriter, r *http.Request) { - t.next.GetMe(w, r) -} - -// GetUsers implements the Service interface. -func (t tracing) GetUsers(w http.ResponseWriter, r *http.Request) { - t.next.GetUsers(w, r) -} - -// GetUser implements the Service interface. -func (t tracing) GetUser(w http.ResponseWriter, r *http.Request) { - t.next.GetUser(w, r) -} - -// PostUser implements the Service interface. -func (t tracing) PostUser(w http.ResponseWriter, r *http.Request) { - t.next.PostUser(w, r) -} - -// DeleteUser implements the Service interface. -func (t tracing) DeleteUser(w http.ResponseWriter, r *http.Request) { - t.next.DeleteUser(w, r) -} - -// PatchUser implements the Service interface. -func (t tracing) PatchUser(w http.ResponseWriter, r *http.Request) { - t.next.PatchUser(w, r) -} - -// ChangeOwnPassword implements the Service interface. -func (t tracing) ChangeOwnPassword(w http.ResponseWriter, r *http.Request) { - t.next.ChangeOwnPassword(w, r) -} - -// ListAppRoleAssignments implements the Service interface. -func (t tracing) ListAppRoleAssignments(w http.ResponseWriter, r *http.Request) { - t.next.ListAppRoleAssignments(w, r) -} - -// CreateAppRoleAssignment implements the Service interface. -func (t tracing) CreateAppRoleAssignment(w http.ResponseWriter, r *http.Request) { - t.next.CreateAppRoleAssignment(w, r) -} - -// DeleteAppRoleAssignment implements the Service interface. -func (t tracing) DeleteAppRoleAssignment(w http.ResponseWriter, r *http.Request) { - t.next.DeleteAppRoleAssignment(w, r) -} - -// GetGroups implements the Service interface. -func (t tracing) GetGroups(w http.ResponseWriter, r *http.Request) { - t.next.GetGroups(w, r) -} - -// GetGroup implements the Service interface. -func (t tracing) GetGroup(w http.ResponseWriter, r *http.Request) { - t.next.GetGroup(w, r) -} - -// PostGroup implements the Service interface. -func (t tracing) PostGroup(w http.ResponseWriter, r *http.Request) { - t.next.PostGroup(w, r) -} - -// PatchGroup implements the Service interface. -func (t tracing) PatchGroup(w http.ResponseWriter, r *http.Request) { - t.next.PatchGroup(w, r) -} - -// DeleteGroup implements the Service interface. -func (t tracing) DeleteGroup(w http.ResponseWriter, r *http.Request) { - t.next.DeleteGroup(w, r) -} - -// GetGroupMembers implements the Service interface. -func (t tracing) GetGroupMembers(w http.ResponseWriter, r *http.Request) { - t.next.GetGroupMembers(w, r) -} - -// PostGroupMember implements the Service interface. -func (t tracing) PostGroupMember(w http.ResponseWriter, r *http.Request) { - t.next.PostGroupMember(w, r) -} - -// DeleteGroupMember implements the Service interface. -func (t tracing) DeleteGroupMember(w http.ResponseWriter, r *http.Request) { - t.next.DeleteGroupMember(w, r) -} - -// GetEducationSchools implements the Service interface. -func (t tracing) GetEducationSchools(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationSchools(w, r) -} - -// GetEducationSchool implements the Service interface. -func (t tracing) GetEducationSchool(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationSchool(w, r) -} - -// PostEducationSchool implements the Service interface. -func (t tracing) PostEducationSchool(w http.ResponseWriter, r *http.Request) { - t.next.PostEducationSchool(w, r) -} - -// PatchEducationSchool implements the Service interface. -func (t tracing) PatchEducationSchool(w http.ResponseWriter, r *http.Request) { - t.next.PatchEducationSchool(w, r) -} - -// DeleteEducationSchool implements the Service interface. -func (t tracing) DeleteEducationSchool(w http.ResponseWriter, r *http.Request) { - t.next.DeleteEducationSchool(w, r) -} - -// GetEducationSchoolUsers implements the Service interface. -func (t tracing) GetEducationSchoolUsers(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationSchoolUsers(w, r) -} - -// PostEducationSchoolUser implements the Service interface. -func (t tracing) PostEducationSchoolUser(w http.ResponseWriter, r *http.Request) { - t.next.PostEducationSchoolUser(w, r) -} - -// DeleteEducationSchoolUser implements the Service interface. -func (t tracing) DeleteEducationSchoolUser(w http.ResponseWriter, r *http.Request) { - t.next.DeleteEducationSchoolUser(w, r) -} - -// GetEducationSchoolClasses implements the Service interface. -func (t tracing) GetEducationSchoolClasses(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationSchoolClasses(w, r) -} - -// PostEducationSchoolClass implements the Service interface. -func (t tracing) PostEducationSchoolClass(w http.ResponseWriter, r *http.Request) { - t.next.PostEducationSchoolClass(w, r) -} - -// DeleteEducationSchoolClass implements the Service interface. -func (t tracing) DeleteEducationSchoolClass(w http.ResponseWriter, r *http.Request) { - t.next.DeleteEducationSchoolClass(w, r) -} - -// GetEducationClasses implements the Service interface. -func (t tracing) GetEducationClasses(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationClasses(w, r) -} - -// GetEducationClass implements the Service interface. -func (t tracing) GetEducationClass(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationClass(w, r) -} - -// PostEducationClass implements the Service interface. -func (t tracing) PostEducationClass(w http.ResponseWriter, r *http.Request) { - t.next.PostEducationClass(w, r) -} - -// PatchEducationClass implements the Service interface. -func (t tracing) PatchEducationClass(w http.ResponseWriter, r *http.Request) { - t.next.PatchEducationClass(w, r) -} - -// DeleteEducationClass implements the Service interface. -func (t tracing) DeleteEducationClass(w http.ResponseWriter, r *http.Request) { - t.next.DeleteEducationClass(w, r) -} - -// GetEducationClassMembers implements the Service interface. -func (t tracing) GetEducationClassMembers(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationClassMembers(w, r) -} - -// PostEducationClassMember implements the Service interface. -func (t tracing) PostEducationClassMember(w http.ResponseWriter, r *http.Request) { - t.next.PostEducationClassMember(w, r) -} - -// DeleteEducationClassMember implements the Service interface. -func (t tracing) DeleteEducationClassMember(w http.ResponseWriter, r *http.Request) { - t.next.DeleteEducationClassMember(w, r) -} - -// GetEducationUsers implements the Service interface. -func (t tracing) GetEducationUsers(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationUsers(w, r) -} - -// GetEducationUser implements the Service interface. -func (t tracing) GetEducationUser(w http.ResponseWriter, r *http.Request) { - t.next.GetEducationUser(w, r) -} - -// PostEducationUser implements the Service interface. -func (t tracing) PostEducationUser(w http.ResponseWriter, r *http.Request) { - t.next.PostEducationUser(w, r) -} - -// DeleteEducationUser implements the Service interface. -func (t tracing) DeleteEducationUser(w http.ResponseWriter, r *http.Request) { - t.next.DeleteEducationUser(w, r) -} - -// PatchEducationUser implements the Service interface. -func (t tracing) PatchEducationUser(w http.ResponseWriter, r *http.Request) { - t.next.PatchEducationUser(w, r) -} - -// GetDrives implements the Service interface. -func (t tracing) GetDrives(w http.ResponseWriter, r *http.Request) { - t.next.GetDrives(w, r) -} - -// GetSingleDrive implements the Service interface. -func (t tracing) GetSingleDrive(w http.ResponseWriter, r *http.Request) { - t.next.GetDrives(w, r) -} - -// UpdateDrive implements the Service interface. -func (t tracing) UpdateDrive(w http.ResponseWriter, r *http.Request) { - t.next.GetDrives(w, r) -} - -// DeleteDrive implements the Service interface. -func (t tracing) DeleteDrive(w http.ResponseWriter, r *http.Request) { - t.next.GetDrives(w, r) -} - -// GetAllDrives implements the Service interface. -func (t tracing) GetAllDrives(w http.ResponseWriter, r *http.Request) { - t.next.GetAllDrives(w, r) -} - -// CreateDrive implements the Service interface. -func (t tracing) CreateDrive(w http.ResponseWriter, r *http.Request) { - t.next.CreateDrive(w, r) -} - -// GetRootDriveChildren implements the Service interface. -func (t tracing) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) { - t.next.GetRootDriveChildren(w, r) -} - -// GetTags implements the Service interface. -func (t tracing) GetTags(w http.ResponseWriter, r *http.Request) { - t.next.GetTags(w, r) -} - -// AssignTags implements the Service interface. -func (t tracing) AssignTags(w http.ResponseWriter, r *http.Request) { - t.next.AssignTags(w, r) -} - -// UnassignTags implements the Service interface. -func (t tracing) UnassignTags(w http.ResponseWriter, r *http.Request) { - t.next.UnassignTags(w, r) -} - -// GetEducationClassTeachers implements the Service interface. -func (t tracing) GetEducationClassTeachers(w http.ResponseWriter, r *http.Request) { - t.next.UnassignTags(w, r) -} - -// PostEducationClassTeacher implements the Service interface. -func (t tracing) PostEducationClassTeacher(w http.ResponseWriter, r *http.Request) { - t.next.UnassignTags(w, r) -} - -// DeleteEducationClassTeacher implements the Service interface. -func (t tracing) DeleteEducationClassTeacher(w http.ResponseWriter, r *http.Request) { - t.next.UnassignTags(w, r) -} diff --git a/services/graph/pkg/tracing/tracing.go b/services/graph/pkg/tracing/tracing.go deleted file mode 100644 index b0b22395b0c..00000000000 --- a/services/graph/pkg/tracing/tracing.go +++ /dev/null @@ -1,23 +0,0 @@ -package tracing - -import ( - pkgtrace "github.com/owncloud/ocis/v2/ocis-pkg/tracing" - "github.com/owncloud/ocis/v2/services/graph/pkg/config" - "go.opentelemetry.io/otel/trace" -) - -var ( - // TraceProvider is the global trace provider for the graph service. - TraceProvider = trace.NewNoopTracerProvider() -) - -func Configure(cfg *config.Config) error { - var err error - if cfg.Tracing.Enabled { - if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil { - return err - } - } - - return nil -}