replace opencensus everywhere
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"go.opencensus.io/trace"
|
||||
idpTracing "github.com/owncloud/ocis/idp/pkg/tracing"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
)
|
||||
|
||||
// Static is a middleware that serves static assets.
|
||||
@@ -22,7 +24,7 @@ func Static(root string, fs http.FileSystem) func(http.Handler) http.Handler {
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, span := trace.StartSpan(r.Context(), "serve static asset")
|
||||
ctx, span := idpTracing.TraceProvider.Tracer("idp").Start(r.Context(), "serve static asset")
|
||||
defer span.End()
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
@@ -30,25 +32,18 @@ func Static(root string, fs http.FileSystem) func(http.Handler) http.Handler {
|
||||
if strings.HasPrefix(r.URL.Path, "/signin/v1/static/") {
|
||||
if strings.HasSuffix(r.URL.Path, "/") {
|
||||
// but no listing of folders
|
||||
span.AddAttributes(trace.StringAttribute("asset not found", r.URL.Path))
|
||||
span.SetStatus(trace.Status{
|
||||
Code: 1,
|
||||
Message: "asset not found",
|
||||
})
|
||||
span.SetAttributes(attribute.KeyValue{Key: "path", Value: attribute.StringValue(r.URL.Path)})
|
||||
span.SetStatus(codes.Error, "asset not found")
|
||||
http.NotFound(w, r)
|
||||
} else {
|
||||
r.URL.Path = strings.Replace(r.URL.Path, "/signin/v1/static/", "/signin/v1/identifier/static/", 1)
|
||||
span.AddAttributes(trace.StringAttribute("served", r.URL.Path))
|
||||
span.SetAttributes(attribute.KeyValue{Key: "server", Value: attribute.StringValue(r.URL.Path)})
|
||||
static.ServeHTTP(w, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
span.AddAttributes(trace.StringAttribute("served", r.URL.Path))
|
||||
span.SetStatus(trace.Status{
|
||||
Code: 0,
|
||||
Message: "ok",
|
||||
})
|
||||
next.ServeHTTP(w, r)
|
||||
span.SetAttributes(attribute.KeyValue{Key: "path", Value: attribute.StringValue(r.URL.Path)})
|
||||
span.SetStatus(codes.Ok, "ok")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user