diff --git a/changelog/unreleased/opentelemetry.md b/changelog/unreleased/opentelemetry.md new file mode 100644 index 0000000000..ee5837c04e --- /dev/null +++ b/changelog/unreleased/opentelemetry.md @@ -0,0 +1,9 @@ +Enhancement: Replace OpenCensus with OpenTelemetry + +OpenTelemetry](https://opentelemetry.io/docs/concepts/what-is-opentelemetry/) is an [open standard](https://github.com/open-telemetry/opentelemetry-specification) a sandbox CNCF project and it was formed through a merger of the OpenTracing and OpenCensus. + +> OpenCensus and OpenTracing have merged to form OpenTelemetry, which serves as the next major version of OpenCensus and OpenTracing. OpenTelemetry will offer backwards compatibility with existing OpenCensus integrations, and we will continue to make security patches to existing OpenCensus libraries for two years. + +There is a lot of outdated documentation as a result of this merger, and we will be better off adopting the latest standard and libraries. + +https://github.com/cs3org/reva/pull/1984 \ No newline at end of file diff --git a/cmd/revad/runtime/runtime.go b/cmd/revad/runtime/runtime.go index b1e918b102..bac257454b 100644 --- a/cmd/revad/runtime/runtime.go +++ b/cmd/revad/runtime/runtime.go @@ -28,23 +28,17 @@ import ( "strconv" "strings" - "github.com/cs3org/reva/pkg/registry/memory" - - "github.com/cs3org/reva/pkg/utils" - - "contrib.go.opencensus.io/exporter/jaeger" "github.com/cs3org/reva/cmd/revad/internal/grace" "github.com/cs3org/reva/pkg/logger" + "github.com/cs3org/reva/pkg/registry/memory" "github.com/cs3org/reva/pkg/rgrpc" "github.com/cs3org/reva/pkg/rhttp" "github.com/cs3org/reva/pkg/sharedconf" + rtrace "github.com/cs3org/reva/pkg/trace" + "github.com/cs3org/reva/pkg/utils" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" "github.com/rs/zerolog" - "go.opencensus.io/plugin/ocgrpc" - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/stats/view" - "go.opencensus.io/trace" ) // Run runs a reva server with the given config file and pid file. @@ -84,14 +78,18 @@ type coreConf struct { TracingEndpoint string `mapstructure:"tracing_endpoint"` TracingCollector string `mapstructure:"tracing_collector"` TracingServiceName string `mapstructure:"tracing_service_name"` + + // TracingService specifies the service. i.e OpenCensus, OpenTelemetry, OpenTracing... + TracingService string `mapstructure:"tracing_service"` } func run(mainConf map[string]interface{}, coreConf *coreConf, logger *zerolog.Logger, filename string) { host, _ := os.Hostname() logger.Info().Msgf("host info: %s", host) - // initRegistry() - initTracing(coreConf, logger) + if coreConf.TracingEnabled { + initTracing(coreConf) + } initCPUCount(coreConf, logger) servers := initServers(mainConf, logger) @@ -144,18 +142,14 @@ func initServers(mainConf map[string]interface{}, log *zerolog.Logger) map[strin } if len(servers) == 0 { - // nothing to do log.Info().Msg("nothing to do, no grpc/http enabled_services declared in config") os.Exit(1) } return servers } -func initTracing(conf *coreConf, log *zerolog.Logger) { - if err := setupOpenCensus(conf); err != nil { - log.Error().Err(err).Msg("error configuring open census stats and tracing") - os.Exit(1) - } +func initTracing(conf *coreConf) { + rtrace.SetTraceProvider(conf.TracingCollector) } func initCPUCount(conf *coreConf, log *zerolog.Logger) { @@ -270,39 +264,6 @@ func getHTTPServer(conf interface{}, l *zerolog.Logger) (*rhttp.Server, error) { return s, nil } -func setupOpenCensus(conf *coreConf) error { - if err := view.Register(ochttp.DefaultServerViews...); err != nil { - return err - } - - if err := view.Register(ocgrpc.DefaultServerViews...); err != nil { - return err - } - - if !conf.TracingEnabled { - return nil - } - - if conf.TracingServiceName == "" { - conf.TracingServiceName = "revad" - } - - je, err := jaeger.NewExporter(jaeger.Options{ - AgentEndpoint: conf.TracingEndpoint, - CollectorEndpoint: conf.TracingCollector, - ServiceName: conf.TracingServiceName, - }) - - if err != nil { - return err - } - - // register it as a trace exporter - trace.RegisterExporter(je) - trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) - return nil -} - // adjustCPU parses string cpu and sets GOMAXPROCS // according to its value. It accepts either // a number (e.g. 3) or a percent (e.g. 50%). @@ -349,6 +310,7 @@ func parseCoreConfOrDie(v interface{}) *coreConf { fmt.Fprintf(os.Stderr, "error decoding core config: %s\n", err.Error()) os.Exit(1) } + return c } diff --git a/go.mod b/go.mod index aeefd821df..87d4dc3d95 100644 --- a/go.mod +++ b/go.mod @@ -58,9 +58,15 @@ require ( github.com/tus/tusd v1.1.1-0.20200416115059-9deabf9d80c2 go.mongodb.org/mongo-driver v1.5.1 // indirect go.opencensus.io v0.23.0 + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.22.0 + go.opentelemetry.io/otel v1.0.0-RC2 + go.opentelemetry.io/otel/exporters/jaeger v1.0.0-RC2 + go.opentelemetry.io/otel/metric v0.20.0 // indirect + go.opentelemetry.io/otel/sdk v1.0.0-RC2 + go.opentelemetry.io/otel/trace v1.0.0-RC2 golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d - golang.org/x/sys v0.0.0-20210423082822-04245dca01da + golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98 // indirect google.golang.org/grpc v1.39.1 diff --git a/go.sum b/go.sum index 2a46e292ff..55074c9e2e 100644 --- a/go.sum +++ b/go.sum @@ -594,6 +594,23 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opentelemetry.io/contrib v0.22.0 h1:0F7gDEjgb1WGn4ODIjaCAg75hmqF+UN0LiVgwxsCodc= +go.opentelemetry.io/contrib v0.22.0/go.mod h1:EH4yDYeNoaTqn/8yCWQmfNB78VHfGX2Jt2bvnvzBlGM= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.22.0 h1:TjqELdtCtlOJQrTnXd2y+RP6wXKZUnnJer0HR0CSo18= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.22.0/go.mod h1:KjqwX4uJNaj479ZjFpADOMJKOM4rBXq4kN7nbeuGKrY= +go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= +go.opentelemetry.io/otel v1.0.0-RC2 h1:SHhxSjB+omnGZPgGlKe+QMp3MyazcOHdQ8qwo89oKbg= +go.opentelemetry.io/otel v1.0.0-RC2/go.mod h1:w1thVQ7qbAy8MHb0IFj8a5Q2QU0l2ksf8u/CN8m3NOM= +go.opentelemetry.io/otel/exporters/jaeger v1.0.0-RC2 h1:RF0nWsIDpDBe+s06lkLxUw9CWQUAhO6hBSxxB7dz45s= +go.opentelemetry.io/otel/exporters/jaeger v1.0.0-RC2/go.mod h1:sZZqN3Vb0iT+NE6mZ1S7sNyH3t4PFk6ElK5TLGFBZ7E= +go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= +go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= +go.opentelemetry.io/otel/oteltest v1.0.0-RC2/go.mod h1:kiQ4tw5tAL4JLTbcOYwK1CWI1HkT5aiLzHovgOVnz/A= +go.opentelemetry.io/otel/sdk v1.0.0-RC2 h1:ROuteeSCBaZNjiT9JcFzZepmInDvLktR28Y6qKo8bCs= +go.opentelemetry.io/otel/sdk v1.0.0-RC2/go.mod h1:fgwHyiDn4e5k40TD9VX243rOxXR+jzsWBZYA2P5jpEw= +go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= +go.opentelemetry.io/otel/trace v1.0.0-RC2 h1:dunAP0qDULMIT82atj34m5RgvsIK6LcsXf1c/MsYg1w= +go.opentelemetry.io/otel/trace v1.0.0-RC2/go.mod h1:JPQ+z6nNw9mqEGT8o3eoPTdnNI+Aj5JcxEsVGREIAy4= 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= @@ -754,6 +771,8 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/internal/grpc/interceptors/appctx/appctx.go b/internal/grpc/interceptors/appctx/appctx.go index 428a2109d4..2ff8e92e59 100644 --- a/internal/grpc/interceptors/appctx/appctx.go +++ b/internal/grpc/interceptors/appctx/appctx.go @@ -23,16 +23,13 @@ import ( "github.com/cs3org/reva/pkg/appctx" "github.com/rs/zerolog" - "go.opencensus.io/trace" "google.golang.org/grpc" ) // NewUnary returns a new unary interceptor that creates the application context. func NewUnary(log zerolog.Logger) grpc.UnaryServerInterceptor { interceptor := func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - span := trace.FromContext(ctx) - sub := log.With().Str("traceid", span.SpanContext().TraceID.String()).Logger() - ctx = appctx.WithLogger(ctx, &sub) + ctx = appctx.WithLogger(ctx, &log) res, err := handler(ctx, req) return res, err } @@ -43,9 +40,7 @@ func NewUnary(log zerolog.Logger) grpc.UnaryServerInterceptor { // that creates the application context. func NewStream(log zerolog.Logger) grpc.StreamServerInterceptor { interceptor := func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - span := trace.FromContext(ss.Context()) - sub := log.With().Str("traceid", span.SpanContext().TraceID.String()).Logger() - ctx := appctx.WithLogger(ss.Context(), &sub) + ctx := appctx.WithLogger(ss.Context(), &log) wrapped := newWrappedServerStream(ctx, ss) err := handler(srv, wrapped) return err diff --git a/internal/grpc/interceptors/auth/auth.go b/internal/grpc/interceptors/auth/auth.go index 700d32155b..490b47da1a 100644 --- a/internal/grpc/interceptors/auth/auth.go +++ b/internal/grpc/interceptors/auth/auth.go @@ -32,7 +32,6 @@ import ( "github.com/cs3org/reva/pkg/utils" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" - "go.opencensus.io/trace" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -80,12 +79,9 @@ func NewUnary(m map[string]interface{}, unprotected []string) (grpc.UnaryServerI } interceptor := func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - ctx, span := trace.StartSpan(ctx, "auth") - defer span.End() log := appctx.GetLogger(ctx) if utils.Skip(info.FullMethod, unprotected) { - span.AddAttributes(trace.BoolAttribute("auth_enabled", false)) log.Debug().Str("method", info.FullMethod).Msg("skipping auth") // If a token is present, set it anyway, as we might need the user info @@ -100,8 +96,6 @@ func NewUnary(m map[string]interface{}, unprotected []string) (grpc.UnaryServerI return handler(ctx, req) } - span.AddAttributes(trace.BoolAttribute("auth_enabled", true)) - tkn, ok := ctxpkg.ContextGetToken(ctx) if !ok || tkn == "" { @@ -116,14 +110,6 @@ func NewUnary(m map[string]interface{}, unprotected []string) (grpc.UnaryServerI return nil, status.Errorf(codes.PermissionDenied, "auth: core access token is invalid") } - // store user and core access token in context. - span.AddAttributes( - trace.StringAttribute("id.idp", u.Id.Idp), - trace.StringAttribute("id.opaque_id", u.Id.OpaqueId), - trace.StringAttribute("username", u.Username), - trace.StringAttribute("token", tkn)) - span.AddAttributes(trace.StringAttribute("user", u.String()), trace.StringAttribute("token", tkn)) - ctx = ctxpkg.ContextSetUser(ctx, u) return handler(ctx, req) } diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 1464954fe6..5dd46af077 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -28,6 +28,8 @@ import ( "sync" "time" + rtrace "github.com/cs3org/reva/pkg/trace" + collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" @@ -849,15 +851,17 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide }, nil } + ctx, span := rtrace.Provider.Tracer("reva").Start(ctx, "Delete") + defer span.End() + if !s.inSharedFolder(ctx, p) { return s.delete(ctx, req) } if s.isSharedFolder(ctx, p) { // TODO(labkode): deleting share names should be allowed, means unmounting. - log.Debug().Msgf("path:%s points to shared folder or share name", p) err := errtypes.BadRequest("gateway: cannot delete share folder or share name: path=" + p) - log.Err(err).Msg("gateway: error creating container") + span.RecordError(err) return &provider.DeleteResponse{ Status: status.NewInvalidArg(ctx, "path points to share folder or share name"), }, nil diff --git a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go index 32bf2f485a..adde74160f 100644 --- a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go +++ b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go @@ -34,12 +34,13 @@ import ( "github.com/cs3org/reva/pkg/rgrpc" "github.com/cs3org/reva/pkg/rgrpc/status" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/cs3org/reva/pkg/utils" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" + "google.golang.org/grpc/codes" gstatus "google.golang.org/grpc/status" ) @@ -305,12 +306,13 @@ func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteSt } func (s *service) CreateContainer(ctx context.Context, req *provider.CreateContainerRequest) (*provider.CreateContainerResponse, error) { - ctx, span := trace.StartSpan(ctx, "CreateContainer") + ctx, span := rtrace.Provider.Tracer("publicstorageprovider").Start(ctx, "CreateContainer") defer span.End() - span.AddAttributes( - trace.StringAttribute("ref", req.Ref.String()), - ) + span.SetAttributes(attribute.KeyValue{ + Key: "reference", + Value: attribute.StringValue(req.Ref.String()), + }) cs3Ref, _, ls, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref) switch { @@ -344,12 +346,13 @@ func (s *service) CreateContainer(ctx context.Context, req *provider.CreateConta } func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*provider.DeleteResponse, error) { - ctx, span := trace.StartSpan(ctx, "Delete") + ctx, span := rtrace.Provider.Tracer("publicstorageprovider").Start(ctx, "Delete") defer span.End() - span.AddAttributes( - trace.StringAttribute("ref", req.Ref.String()), - ) + span.SetAttributes(attribute.KeyValue{ + Key: "reference", + Value: attribute.StringValue(req.Ref.String()), + }) cs3Ref, _, ls, st, err := s.translatePublicRefToCS3Ref(ctx, req.Ref) switch { @@ -383,12 +386,18 @@ func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*pro } func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provider.MoveResponse, error) { - ctx, span := trace.StartSpan(ctx, "Move") + ctx, span := rtrace.Provider.Tracer("publicstorageprovider").Start(ctx, "Move") defer span.End() - span.AddAttributes( - trace.StringAttribute("source", req.Source.String()), - trace.StringAttribute("destination", req.Destination.String()), + span.SetAttributes( + attribute.KeyValue{ + Key: "source", + Value: attribute.StringValue(req.Source.String()), + }, + attribute.KeyValue{ + Key: "destination", + Value: attribute.StringValue(req.Destination.String()), + }, ) cs3RefSource, tknSource, ls, st, err := s.translatePublicRefToCS3Ref(ctx, req.Source) @@ -440,12 +449,14 @@ func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provide } func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) { - ctx, span := trace.StartSpan(ctx, "Stat") + ctx, span := rtrace.Provider.Tracer("publicstorageprovider").Start(ctx, "Stat") defer span.End() - span.AddAttributes( - trace.StringAttribute("ref", req.Ref.String()), - ) + span.SetAttributes( + attribute.KeyValue{ + Key: "source", + Value: attribute.StringValue(req.Ref.String()), + }) tkn, relativePath, err := s.unwrap(ctx, req.Ref) if err != nil { diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index 87d280a07a..df288be75c 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -20,19 +20,15 @@ package storageprovider import ( "context" - "sort" - - // "encoding/json" "fmt" "net/url" "os" "path" + "sort" "strconv" "strings" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" - - // link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" @@ -42,10 +38,11 @@ import ( "github.com/cs3org/reva/pkg/rhttp/router" "github.com/cs3org/reva/pkg/storage" "github.com/cs3org/reva/pkg/storage/fs/registry" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/cs3org/reva/pkg/utils" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/attribute" "google.golang.org/grpc" ) @@ -603,12 +600,13 @@ func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provide } func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) { - ctx, span := trace.StartSpan(ctx, "Stat") + ctx, span := rtrace.Provider.Tracer("reva").Start(ctx, "stat") defer span.End() - span.AddAttributes( - trace.StringAttribute("ref", req.Ref.String()), - ) + span.SetAttributes(attribute.KeyValue{ + Key: "reference", + Value: attribute.StringValue(req.Ref.String()), + }) newRef, err := s.unwrap(ctx, req.Ref) if err != nil { diff --git a/internal/http/interceptors/appctx/appctx.go b/internal/http/interceptors/appctx/appctx.go index aa959c5590..b3277bf7f1 100644 --- a/internal/http/interceptors/appctx/appctx.go +++ b/internal/http/interceptors/appctx/appctx.go @@ -26,7 +26,6 @@ import ( "github.com/cs3org/reva/pkg/appctx" "github.com/rs/zerolog" - "go.opencensus.io/trace" ) // New returns a new HTTP middleware that stores the log @@ -41,13 +40,7 @@ func New(log zerolog.Logger) func(http.Handler) http.Handler { func handler(log zerolog.Logger, h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - - // trace is set on the httpserver.go file as the outermost wrapper handler. - span := trace.FromContext(ctx) - sub := log.With().Str("traceid", span.SpanContext().TraceID.String()).Logger() - ctx = appctx.WithLogger(ctx, &sub) - + ctx := appctx.WithLogger(r.Context(), &log) r = r.WithContext(ctx) h.ServeHTTP(w, r) }) diff --git a/internal/http/services/owncloud/ocdav/copy.go b/internal/http/services/owncloud/ocdav/copy.go index 8860da2e8f..8663d48c6a 100644 --- a/internal/http/services/owncloud/ocdav/copy.go +++ b/internal/http/services/owncloud/ocdav/copy.go @@ -34,9 +34,9 @@ import ( "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rhttp" "github.com/cs3org/reva/pkg/rhttp/router" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/cs3org/reva/pkg/utils" "github.com/rs/zerolog" - "go.opencensus.io/trace" ) type copy struct { @@ -49,8 +49,7 @@ type copy struct { type intermediateDirRefFunc func() (*provider.Reference, *rpc.Status, error) func (s *svc) handlePathCopy(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "copy") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), "copy") defer span.End() src := path.Join(ns, r.URL.Path) @@ -259,8 +258,7 @@ func (s *svc) executePathCopy(ctx context.Context, client gateway.GatewayAPIClie } func (s *svc) handleSpacesCopy(w http.ResponseWriter, r *http.Request, spaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_copy") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), "spaces_copy") defer span.End() dst, err := extractDestination(r) diff --git a/internal/http/services/owncloud/ocdav/delete.go b/internal/http/services/owncloud/ocdav/delete.go index 69bba949ac..ed8f365539 100644 --- a/internal/http/services/owncloud/ocdav/delete.go +++ b/internal/http/services/owncloud/ocdav/delete.go @@ -27,20 +27,16 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/rs/zerolog" - "go.opencensus.io/trace" ) func (s *svc) handlePathDelete(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "delete") - defer span.End() - fn := path.Join(ns, r.URL.Path) - sublog := appctx.GetLogger(ctx).With().Str("path", fn).Logger() + sublog := appctx.GetLogger(r.Context()).With().Str("path", fn).Logger() ref := &provider.Reference{Path: fn} - s.handleDelete(ctx, w, r, ref, sublog) + s.handleDelete(r.Context(), w, r, ref, sublog) } func (s *svc) handleDelete(ctx context.Context, w http.ResponseWriter, r *http.Request, ref *provider.Reference, log zerolog.Logger) { @@ -51,9 +47,13 @@ func (s *svc) handleDelete(ctx context.Context, w http.ResponseWriter, r *http.R return } + ctx, span := rtrace.Provider.Tracer("reva").Start(ctx, "delete") + defer span.End() + req := &provider.DeleteRequest{Ref: ref} res, err := client.Delete(ctx, req) if err != nil { + span.RecordError(err) log.Error().Err(err).Msg("error performing delete grpc request") w.WriteHeader(http.StatusInternalServerError) return @@ -86,15 +86,17 @@ func (s *svc) handleDelete(ctx context.Context, w http.ResponseWriter, r *http.R }) HandleWebdavError(&log, w, b, err) } + HandleErrorStatus(&log, w, res.Status) return } + w.WriteHeader(http.StatusNoContent) } func (s *svc) handleSpacesDelete(w http.ResponseWriter, r *http.Request, spaceID string) { ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_delete") + ctx, span := rtrace.Provider.Tracer("reva").Start(ctx, "spaces_delete") defer span.End() sublog := appctx.GetLogger(ctx).With().Logger() diff --git a/internal/http/services/owncloud/ocdav/get.go b/internal/http/services/owncloud/ocdav/get.go index ba5837db90..6bd08c52da 100644 --- a/internal/http/services/owncloud/ocdav/get.go +++ b/internal/http/services/owncloud/ocdav/get.go @@ -28,21 +28,19 @@ import ( "strings" "time" - "github.com/cs3org/reva/internal/grpc/services/storageprovider" - "github.com/cs3org/reva/internal/http/services/datagateway" - "github.com/rs/zerolog" - "go.opencensus.io/trace" - rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/internal/grpc/services/storageprovider" + "github.com/cs3org/reva/internal/http/services/datagateway" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rhttp" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/cs3org/reva/pkg/utils" + "github.com/rs/zerolog" ) func (s *svc) handlePathGet(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "get") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), "get") defer span.End() fn := path.Join(ns, r.URL.Path) @@ -161,8 +159,7 @@ func (s *svc) handleGet(ctx context.Context, w http.ResponseWriter, r *http.Requ } func (s *svc) handleSpacesGet(w http.ResponseWriter, r *http.Request, spaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_get") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), "spaces_get") defer span.End() sublog := appctx.GetLogger(ctx).With().Str("path", r.URL.Path).Str("spaceid", spaceID).Str("handler", "get").Logger() diff --git a/internal/http/services/owncloud/ocdav/head.go b/internal/http/services/owncloud/ocdav/head.go index f74c7d5bc0..7b3094595b 100644 --- a/internal/http/services/owncloud/ocdav/head.go +++ b/internal/http/services/owncloud/ocdav/head.go @@ -27,18 +27,18 @@ import ( "strings" "time" + rtrace "github.com/cs3org/reva/pkg/trace" + rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/internal/grpc/services/storageprovider" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/utils" "github.com/rs/zerolog" - "go.opencensus.io/trace" ) func (s *svc) handlePathHead(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "head") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), "head") defer span.End() fn := path.Join(ns, r.URL.Path) @@ -89,8 +89,7 @@ func (s *svc) handleHead(ctx context.Context, w http.ResponseWriter, r *http.Req } func (s *svc) handleSpacesHead(w http.ResponseWriter, r *http.Request, spaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_head") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), "spaces_head") defer span.End() sublog := appctx.GetLogger(ctx).With().Str("spaceid", spaceID).Str("path", r.URL.Path).Logger() diff --git a/internal/http/services/owncloud/ocdav/mkcol.go b/internal/http/services/owncloud/ocdav/mkcol.go index c8707fbc32..ddee72b86b 100644 --- a/internal/http/services/owncloud/ocdav/mkcol.go +++ b/internal/http/services/owncloud/ocdav/mkcol.go @@ -27,13 +27,12 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/rs/zerolog" - "go.opencensus.io/trace" ) func (s *svc) handlePathMkcol(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "mkcol") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), "mkcol") defer span.End() fn := path.Join(ns, r.URL.Path) @@ -51,8 +50,7 @@ func (s *svc) handlePathMkcol(w http.ResponseWriter, r *http.Request, ns string) } func (s *svc) handleSpacesMkCol(w http.ResponseWriter, r *http.Request, spaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_mkcol") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), "spaces_mkcol") defer span.End() sublog := appctx.GetLogger(ctx).With().Str("path", r.URL.Path).Str("spaceid", spaceID).Str("handler", "mkcol").Logger() diff --git a/internal/http/services/owncloud/ocdav/move.go b/internal/http/services/owncloud/ocdav/move.go index b1e7bc5139..376f57d72b 100644 --- a/internal/http/services/owncloud/ocdav/move.go +++ b/internal/http/services/owncloud/ocdav/move.go @@ -29,13 +29,12 @@ import ( provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rhttp/router" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/rs/zerolog" - "go.opencensus.io/trace" ) func (s *svc) handlePathMove(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "move") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "move") defer span.End() srcPath := path.Join(ns, r.URL.Path) @@ -67,8 +66,7 @@ func (s *svc) handlePathMove(w http.ResponseWriter, r *http.Request, ns string) } func (s *svc) handleSpacesMove(w http.ResponseWriter, r *http.Request, srcSpaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_move") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "spaces_move") defer span.End() dst, err := extractDestination(r) diff --git a/internal/http/services/owncloud/ocdav/propfind.go b/internal/http/services/owncloud/ocdav/propfind.go index 94f8614da0..0e9c99be88 100644 --- a/internal/http/services/owncloud/ocdav/propfind.go +++ b/internal/http/services/owncloud/ocdav/propfind.go @@ -32,8 +32,6 @@ import ( "strings" "time" - "go.opencensus.io/trace" - userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1" @@ -42,8 +40,10 @@ import ( "github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions" "github.com/cs3org/reva/pkg/appctx" ctxpkg "github.com/cs3org/reva/pkg/ctx" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/cs3org/reva/pkg/utils" "github.com/rs/zerolog" + "go.opentelemetry.io/otel/attribute" ) const ( @@ -63,10 +63,11 @@ const ( // ns is the namespace that is prefixed to the path in the cs3 namespace func (s *svc) handlePathPropfind(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "propfind") + ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), fmt.Sprintf("%s %v", r.Method, r.URL.Path)) defer span.End() + span.SetAttributes(attribute.String("component", "ocdav")) + fn := path.Join(ns, r.URL.Path) sublog := appctx.GetLogger(ctx).With().Str("path", fn).Logger() @@ -89,8 +90,7 @@ func (s *svc) handlePathPropfind(w http.ResponseWriter, r *http.Request, ns stri } func (s *svc) handleSpacesPropfind(w http.ResponseWriter, r *http.Request, spaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_propfind") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "spaces_propfind") defer span.End() sublog := appctx.GetLogger(ctx).With().Str("path", r.URL.Path).Str("spaceid", spaceID).Logger() diff --git a/internal/http/services/owncloud/ocdav/proppatch.go b/internal/http/services/owncloud/ocdav/proppatch.go index 326550cf2d..2fb3a0f6a3 100644 --- a/internal/http/services/owncloud/ocdav/proppatch.go +++ b/internal/http/services/owncloud/ocdav/proppatch.go @@ -27,18 +27,16 @@ import ( "path" "strings" - "go.opencensus.io/trace" - rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/pkg/errors" "github.com/rs/zerolog" ) func (s *svc) handlePathProppatch(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "proppatch") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "proppatch") defer span.End() fn := path.Join(ns, r.URL.Path) @@ -105,8 +103,7 @@ func (s *svc) handlePathProppatch(w http.ResponseWriter, r *http.Request, ns str } func (s *svc) handleSpacesProppatch(w http.ResponseWriter, r *http.Request, spaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_proppatch") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "spaces_proppatch") defer span.End() sublog := appctx.GetLogger(ctx).With().Str("path", r.URL.Path).Str("spaceid", spaceID).Logger() diff --git a/internal/http/services/owncloud/ocdav/publicfile.go b/internal/http/services/owncloud/ocdav/publicfile.go index ba4cc78ee8..797f1e4d53 100644 --- a/internal/http/services/owncloud/ocdav/publicfile.go +++ b/internal/http/services/owncloud/ocdav/publicfile.go @@ -27,7 +27,7 @@ import ( typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rhttp/router" - "go.opencensus.io/trace" + rtrace "github.com/cs3org/reva/pkg/trace" ) // PublicFileHandler handles requests on a shared file. it needs to be wrapped in a collection @@ -87,8 +87,7 @@ func (h *PublicFileHandler) Handler(s *svc) http.Handler { } func (s *svc) adjustResourcePathInURL(w http.ResponseWriter, r *http.Request) bool { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "adjustResourcePathInURL") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "adjustResourcePathInURL") defer span.End() // find actual file name @@ -130,8 +129,7 @@ func (s *svc) adjustResourcePathInURL(w http.ResponseWriter, r *http.Request) bo // ns is the namespace that is prefixed to the path in the cs3 namespace func (s *svc) handlePropfindOnToken(w http.ResponseWriter, r *http.Request, ns string, onContainer bool) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "token_propfind") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "token_propfind") defer span.End() tokenStatInfo := ctx.Value(tokenStatInfoKey{}).(*provider.ResourceInfo) diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go index 9b8701ca3b..2e2c8225c8 100644 --- a/internal/http/services/owncloud/ocdav/put.go +++ b/internal/http/services/owncloud/ocdav/put.go @@ -34,9 +34,9 @@ import ( "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rhttp" "github.com/cs3org/reva/pkg/storage/utils/chunking" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/cs3org/reva/pkg/utils" "github.com/rs/zerolog" - "go.opencensus.io/trace" ) func sufferMacOSFinder(r *http.Request) bool { @@ -105,8 +105,7 @@ func isContentRange(r *http.Request) bool { } func (s *svc) handlePathPut(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "put") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "put") defer span.End() fn := path.Join(ns, r.URL.Path) @@ -334,8 +333,7 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ } func (s *svc) handleSpacesPut(w http.ResponseWriter, r *http.Request, spaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces_put") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "spaces_put") defer span.End() sublog := appctx.GetLogger(ctx).With().Str("spaceid", spaceID).Str("path", r.URL.Path).Logger() diff --git a/internal/http/services/owncloud/ocdav/trashbin.go b/internal/http/services/owncloud/ocdav/trashbin.go index 390a3cf479..3a8ea830ca 100644 --- a/internal/http/services/owncloud/ocdav/trashbin.go +++ b/internal/http/services/owncloud/ocdav/trashbin.go @@ -29,6 +29,8 @@ import ( "strings" "time" + rtrace "github.com/cs3org/reva/pkg/trace" + gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" @@ -38,7 +40,6 @@ import ( "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/rhttp/router" "github.com/cs3org/reva/pkg/utils" - "go.opencensus.io/trace" ) // TrashbinHandler handles trashbin requests @@ -142,8 +143,7 @@ func (h *TrashbinHandler) Handler(s *svc) http.Handler { } func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s *svc, u *userpb.User, key, itemPath string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "listTrashbin") + ctx, span := rtrace.Provider.Tracer("trash-bin").Start(r.Context(), "list_trashbin") defer span.End() depth := r.Header.Get(HeaderDepth) @@ -431,8 +431,7 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *use } func (h *TrashbinHandler) restore(w http.ResponseWriter, r *http.Request, s *svc, u *userpb.User, dst, key, itemPath string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "restore") + ctx, span := rtrace.Provider.Tracer("trash-bin").Start(r.Context(), "restore") defer span.End() sublog := appctx.GetLogger(ctx).With().Logger() @@ -591,8 +590,7 @@ func (h *TrashbinHandler) restore(w http.ResponseWriter, r *http.Request, s *svc // delete has only a key func (h *TrashbinHandler) delete(w http.ResponseWriter, r *http.Request, s *svc, u *userpb.User, key, itemPath string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "erase") + ctx, span := rtrace.Provider.Tracer("trash-bin").Start(r.Context(), "erase") defer span.End() sublog := appctx.GetLogger(ctx).With().Str("key", key).Logger() diff --git a/internal/http/services/owncloud/ocdav/tus.go b/internal/http/services/owncloud/ocdav/tus.go index 57c128aedc..0c1eb5c4e5 100644 --- a/internal/http/services/owncloud/ocdav/tus.go +++ b/internal/http/services/owncloud/ocdav/tus.go @@ -31,15 +31,14 @@ import ( typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rhttp" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/cs3org/reva/pkg/utils" "github.com/rs/zerolog" tusd "github.com/tus/tusd/pkg/handler" - "go.opencensus.io/trace" ) func (s *svc) handlePathTusPost(w http.ResponseWriter, r *http.Request, ns string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "tus-post") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "tus-post") defer span.End() // read filename from metadata @@ -62,8 +61,7 @@ func (s *svc) handlePathTusPost(w http.ResponseWriter, r *http.Request, ns strin } func (s *svc) handleSpacesTusPost(w http.ResponseWriter, r *http.Request, spaceID string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "spaces-tus-post") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "spaces-tus-post") defer span.End() // read filename from metadata diff --git a/internal/http/services/owncloud/ocdav/versions.go b/internal/http/services/owncloud/ocdav/versions.go index 962808729b..b9af216c47 100644 --- a/internal/http/services/owncloud/ocdav/versions.go +++ b/internal/http/services/owncloud/ocdav/versions.go @@ -23,12 +23,13 @@ import ( "net/http" "path" + rtrace "github.com/cs3org/reva/pkg/trace" + rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rhttp/router" - "go.opencensus.io/trace" ) // VersionsHandler handles version requests @@ -79,8 +80,7 @@ func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler } func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.ResourceId) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "listVersions") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "listVersions") defer span.End() sublog := appctx.GetLogger(ctx).With().Interface("resourceid", rid).Logger() @@ -182,8 +182,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request, } func (h *VersionsHandler) doRestore(w http.ResponseWriter, r *http.Request, s *svc, rid *provider.ResourceId, key string) { - ctx := r.Context() - ctx, span := trace.StartSpan(ctx, "restore") + ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "restore") defer span.End() sublog := appctx.GetLogger(ctx).With().Interface("resourceid", rid).Str("key", key).Logger() diff --git a/pkg/publicshare/manager/json/json.go b/pkg/publicshare/manager/json/json.go index 0ae33a0286..d7a047a369 100644 --- a/pkg/publicshare/manager/json/json.go +++ b/pkg/publicshare/manager/json/json.go @@ -44,7 +44,6 @@ import ( "github.com/cs3org/reva/pkg/utils" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" - "go.opencensus.io/trace" ) func init() { @@ -438,12 +437,6 @@ func (m *manager) revokeExpiredPublicShare(ctx context.Context, s *link.PublicSh m.mutex.Unlock() defer m.mutex.Lock() - span := trace.FromContext(ctx) - span.AddAttributes( - trace.StringAttribute("operation", "delete expired share"), - trace.StringAttribute("opaqueId", s.Id.OpaqueId), - ) - err := m.RevokePublicShare(ctx, u, &link.PublicShareReference{ Spec: &link.PublicShareReference_Id{ Id: &link.PublicShareId{ diff --git a/pkg/rgrpc/rgrpc.go b/pkg/rgrpc/rgrpc.go index a5ad5c55da..220fa50199 100644 --- a/pkg/rgrpc/rgrpc.go +++ b/pkg/rgrpc/rgrpc.go @@ -30,11 +30,12 @@ import ( "github.com/cs3org/reva/internal/grpc/interceptors/recovery" "github.com/cs3org/reva/internal/grpc/interceptors/token" "github.com/cs3org/reva/pkg/sharedconf" + rtrace "github.com/cs3org/reva/pkg/trace" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" "github.com/rs/zerolog" - "go.opencensus.io/plugin/ocgrpc" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "google.golang.org/grpc" "google.golang.org/grpc/reflection" ) @@ -195,7 +196,6 @@ func (s *Server) registerServices() error { if err != nil { return err } - opts = append(opts, grpc.StatsHandler(&ocgrpc.ServerHandler{})) grpcServer := grpc.NewServer(opts...) for _, svc := range s.services { @@ -281,6 +281,12 @@ func (s *Server) getInterceptors(unprotected []string) ([]grpc.ServerOption, err s.log.Info().Msgf("rgrpc: chaining grpc unary interceptor %s with priority %d", t.Name, t.Priority) } + unaryInterceptors = append(unaryInterceptors, + otelgrpc.UnaryServerInterceptor( + otelgrpc.WithTracerProvider(rtrace.Provider), + otelgrpc.WithPropagators(rtrace.Propagator)), + ) + unaryInterceptors = append([]grpc.UnaryServerInterceptor{ appctx.NewUnary(s.log), token.NewUnary(), diff --git a/pkg/rgrpc/status/status.go b/pkg/rgrpc/status/status.go index 5be9c670d0..d1cb34bf15 100644 --- a/pkg/rgrpc/status/status.go +++ b/pkg/rgrpc/status/status.go @@ -28,7 +28,7 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/trace" ) // NewOK returns a Status with CODE_OK. @@ -170,6 +170,6 @@ func NewErrorFromCode(code rpc.Code, pkgname string) error { // internal function to attach the trace to a context func getTrace(ctx context.Context) string { - span := trace.FromContext(ctx) - return span.SpanContext().TraceID.String() + span := trace.SpanFromContext(ctx) + return span.SpanContext().TraceID().String() } diff --git a/pkg/rgrpc/todo/pool/pool.go b/pkg/rgrpc/todo/pool/pool.go index 5003ba711b..550d7d7499 100644 --- a/pkg/rgrpc/todo/pool/pool.go +++ b/pkg/rgrpc/todo/pool/pool.go @@ -39,7 +39,8 @@ import ( storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" storageregistry "github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1" datatx "github.com/cs3org/go-cs3apis/cs3/tx/v1beta1" - "go.opencensus.io/plugin/ocgrpc" + rtrace "github.com/cs3org/reva/pkg/trace" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "google.golang.org/grpc" ) @@ -87,10 +88,28 @@ func NewConn(endpoint string) (*grpc.ClientConn, error) { conn, err := grpc.Dial( endpoint, grpc.WithInsecure(), - grpc.WithStatsHandler(&ocgrpc.ClientHandler{}), grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(maxCallRecvMsgSize), - )) + ), + grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor( + otelgrpc.WithTracerProvider( + rtrace.Provider, + ), + otelgrpc.WithPropagators( + rtrace.Propagator, + ), + )), + grpc.WithUnaryInterceptor( + otelgrpc.UnaryClientInterceptor( + otelgrpc.WithTracerProvider( + rtrace.Provider, + ), + otelgrpc.WithPropagators( + rtrace.Propagator, + ), + ), + ), + ) if err != nil { return nil, err } diff --git a/pkg/rhttp/rhttp.go b/pkg/rhttp/rhttp.go index 378a02dd39..e3a4c12680 100644 --- a/pkg/rhttp/rhttp.go +++ b/pkg/rhttp/rhttp.go @@ -33,11 +33,11 @@ import ( "github.com/cs3org/reva/internal/http/interceptors/providerauthorizer" "github.com/cs3org/reva/pkg/rhttp/global" "github.com/cs3org/reva/pkg/rhttp/router" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" "github.com/rs/zerolog" - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/trace" + "go.opentelemetry.io/otel/propagation" ) // New returns a new server @@ -289,22 +289,18 @@ func (s *Server) getHandler() (http.Handler, error) { handler = triple.Middleware(traceHandler(triple.Name, handler)) } - // use opencensus handler to trace endpoints. - // TODO(labkode): enable also opencensus telemetry. - handler = &ochttp.Handler{ - Handler: handler, - //IsPublicEndpoint: true, - } - return handler, nil } func traceHandler(name string, h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx, span := trace.StartSpan(r.Context(), name) - r = r.WithContext(ctx) - h.ServeHTTP(w, r) - span.End() + ctx := rtrace.Propagator.Extract(r.Context(), propagation.HeaderCarrier(r.Header)) + t := rtrace.Provider.Tracer("reva") + ctx, span := t.Start(ctx, name) + defer span.End() + + rtrace.Propagator.Inject(ctx, propagation.HeaderCarrier(r.Header)) + h.ServeHTTP(w, r.WithContext(ctx)) }) } diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go index d851323f85..7dacfeaad7 100644 --- a/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -47,6 +47,7 @@ import ( "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/tree" "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs" "github.com/cs3org/reva/pkg/storage/utils/templates" + rtrace "github.com/cs3org/reva/pkg/trace" "github.com/cs3org/reva/pkg/utils" "github.com/pkg/errors" "github.com/pkg/xattr" @@ -434,6 +435,9 @@ func (fs *Decomposedfs) ListFolder(ctx context.Context, ref *provider.Reference, return } + ctx, span := rtrace.Provider.Tracer("decomposedfs").Start(ctx, "ListFolder") + defer span.End() + if !n.Exists { err = errtypes.NotFound(filepath.Join(n.ParentID, n.Name)) return diff --git a/pkg/trace/trace.go b/pkg/trace/trace.go new file mode 100644 index 0000000000..c610131711 --- /dev/null +++ b/pkg/trace/trace.go @@ -0,0 +1,52 @@ +// Copyright 2018-2021 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package trace + +import ( + "go.opentelemetry.io/otel/exporters/jaeger" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.4.0" + "go.opentelemetry.io/otel/trace" +) + +var ( + // Propagator is the default Reva propagator. + Propagator = propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}) + + // Provider is the default Reva tracer provider. + Provider = trace.NewNoopTracerProvider() +) + +// SetTraceProvider sets the TracerProvider at a package level. +func SetTraceProvider(url string) { + exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) + if err != nil { + panic(err) + } + + Provider = sdktrace.NewTracerProvider( + sdktrace.WithBatcher(exp), + sdktrace.WithResource(resource.NewWithAttributes( + semconv.SchemaURL, + semconv.ServiceNameKey.String("reva"), + )), + ) +}