Skip to content

Commit

Permalink
trace uploads throug gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed May 12, 2023
1 parent da69ac8 commit b022f3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/http/services/datagateway/datagateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/rs/zerolog"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
)

const (
Expand All @@ -45,6 +46,9 @@ const (
UploadExpiresHeader = "Upload-Expires"
)

// name is the Tracer name used to identify this instrumentation library.
const tracerName = "datagateway"

func init() {
global.Register("datagateway", New)
}
Expand Down Expand Up @@ -116,6 +120,11 @@ func (s *svc) Unprotected() []string {

func (s *svc) setHandler() {
s.handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "HandlerFunc")
defer span.End()
span.SetAttributes(semconv.HTTPMethodKey.String(r.Method))
r = r.WithContext(ctx)
switch r.Method {
case "HEAD":
addCorsHeader(w)
Expand Down
2 changes: 2 additions & 0 deletions internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/rs/zerolog"
"go.opentelemetry.io/otel/propagation"
)

func sufferMacOSFinder(r *http.Request) bool {
Expand Down Expand Up @@ -306,6 +307,7 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ
w.WriteHeader(http.StatusInternalServerError)
return
}
Propagator.Inject(ctx, propagation.HeaderCarrier(httpReq.Header))
httpReq.Header.Set(datagateway.TokenTransportHeader, token)

httpRes, err := s.client.Do(httpReq)
Expand Down
8 changes: 8 additions & 0 deletions internal/http/services/owncloud/ocdav/tus.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ import (
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/rs/zerolog"
tusd "github.com/tus/tusd/pkg/handler"
"go.opentelemetry.io/otel/propagation"
)

// Propagator ensures the importer module uses the same trace propagation strategy.
var Propagator = propagation.NewCompositeTextMapPropagator(
propagation.Baggage{},
propagation.TraceContext{},
)

func (s *svc) handlePathTusPost(w http.ResponseWriter, r *http.Request, ns string) {
Expand Down Expand Up @@ -248,6 +255,7 @@ func (s *svc) handleTusPost(ctx context.Context, w http.ResponseWriter, r *http.
w.WriteHeader(http.StatusInternalServerError)
return
}
Propagator.Inject(ctx, propagation.HeaderCarrier(httpReq.Header))

httpReq.Header.Set(net.HeaderContentType, r.Header.Get(net.HeaderContentType))
httpReq.Header.Set(net.HeaderContentLength, r.Header.Get(net.HeaderContentLength))
Expand Down

0 comments on commit b022f3f

Please sign in to comment.