mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-24 08:27:27 -04:00
feat: include additional metadata for tracing the collaboration service
This commit is contained in:
@@ -15,9 +15,11 @@ import (
|
||||
providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/middleware"
|
||||
"github.com/rs/zerolog"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
)
|
||||
|
||||
// ContentConnectorService is the interface to implement the "File contents"
|
||||
@@ -143,6 +145,8 @@ func (c *ContentConnector) GetFile(ctx context.Context, writer io.Writer) error
|
||||
} else {
|
||||
httpReq.Header.Add("X-Access-Token", wopiContext.AccessToken)
|
||||
}
|
||||
tracingProp := tracing.GetPropagator()
|
||||
tracingProp.Inject(ctx, propagation.HeaderCarrier(httpReq.Header))
|
||||
|
||||
httpResp, err := httpClient.Do(httpReq)
|
||||
if err != nil {
|
||||
@@ -341,6 +345,8 @@ func (c *ContentConnector) PutFile(ctx context.Context, stream io.Reader, stream
|
||||
//if lockID, ok := ctxpkg.ContextGetLockID(ctx); ok {
|
||||
// httpReq.Header.Add("X-Lock-Id", lockID)
|
||||
//}
|
||||
tracingProp := tracing.GetPropagator()
|
||||
tracingProp.Inject(ctx, propagation.HeaderCarrier(httpReq.Header))
|
||||
|
||||
httpResp, err := httpClient.Do(httpReq)
|
||||
if err != nil {
|
||||
|
||||
39
services/collaboration/pkg/middleware/tracing.go
Normal file
39
services/collaboration/pkg/middleware/tracing.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
func CollaborationTracingMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
wopiContext, err := WopiContextFromCtx(r.Context())
|
||||
if err != nil {
|
||||
// if we can't get the context, skip this middleware
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
span := trace.SpanFromContext(r.Context())
|
||||
|
||||
wopiMethod := r.Header.Get("X-WOPI-Override")
|
||||
|
||||
wopiFile := wopiContext.FileReference
|
||||
wopiUser := wopiContext.User.GetId()
|
||||
|
||||
attrs := []attribute.KeyValue{
|
||||
attribute.String("ocis.wopi.method", wopiMethod),
|
||||
attribute.String("ocis.wopi.resource.id.storage", wopiFile.GetResourceId().GetStorageId()),
|
||||
attribute.String("ocis.wopi.resource.id.opaque", wopiFile.GetResourceId().GetOpaqueId()),
|
||||
attribute.String("ocis.wopi.resource.id.space", wopiFile.GetResourceId().GetSpaceId()),
|
||||
attribute.String("ocis.wopi.resource.path", wopiFile.GetPath()),
|
||||
attribute.String("ocis.wopi.user.idp", wopiUser.GetIdp()),
|
||||
attribute.String("ocis.wopi.user.opaque", wopiUser.GetOpaqueId()),
|
||||
attribute.String("ocis.wopi.user.type", wopiUser.GetType().String()),
|
||||
}
|
||||
span.SetAttributes(attrs...)
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
@@ -73,6 +73,7 @@ func Server(opts ...Option) (http.Service, error) {
|
||||
otelchi.WithChiRoutes(mux),
|
||||
otelchi.WithTracerProvider(options.TracerProvider),
|
||||
otelchi.WithPropagators(tracing.GetPropagator()),
|
||||
otelchi.WithRequestMethodInSpanName(true),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -115,10 +116,13 @@ func prepareRoutes(r *chi.Mux, options Options) {
|
||||
|
||||
r.Route("/files/{fileid}", func(r chi.Router) {
|
||||
|
||||
r.Use(func(h stdhttp.Handler) stdhttp.Handler {
|
||||
// authentication and wopi context
|
||||
return colabmiddleware.WopiContextAuthMiddleware(options.Config, h)
|
||||
})
|
||||
r.Use(
|
||||
func(h stdhttp.Handler) stdhttp.Handler {
|
||||
// authentication and wopi context
|
||||
return colabmiddleware.WopiContextAuthMiddleware(options.Config, h)
|
||||
},
|
||||
colabmiddleware.CollaborationTracingMiddleware,
|
||||
)
|
||||
|
||||
// check whether we should check for proof keys
|
||||
if !options.Config.App.ProofKeys.Disable {
|
||||
|
||||
@@ -32,6 +32,8 @@ func (m tracer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
span trace.Span
|
||||
)
|
||||
|
||||
ctx = pkgtrace.Propagator.Extract(ctx, propagation.HeaderCarrier(r.Header))
|
||||
|
||||
tracer := m.traceProvider.Tracer("proxy")
|
||||
spanOpts := []trace.SpanStartOption{
|
||||
trace.WithSpanKind(trace.SpanKindServer),
|
||||
|
||||
Reference in New Issue
Block a user