Basic span definitions (#49)

* use directly the trace middleware instead of the fancy tracing service

* cannot rely on mux middlewares

* add hops
This commit is contained in:
Alex Unger
2020-03-11 13:25:26 +01:00
committed by GitHub
parent 3229918f93
commit 3ff0e2fd47
2 changed files with 17 additions and 6 deletions

View File

@@ -3,6 +3,8 @@ package middleware
import (
"net/http"
"strings"
"go.opencensus.io/trace"
)
// Static is a middleware that serves static assets.
@@ -20,17 +22,32 @@ 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")
defer span.End()
r = r.WithContext(ctx)
// serve the static assets for the identifier web app
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",
})
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))
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)
})
}

View File

@@ -15,7 +15,6 @@ import (
logw "github.com/owncloud/ocis-konnectd/pkg/log"
"github.com/owncloud/ocis-konnectd/pkg/middleware"
"github.com/owncloud/ocis-pkg/v2/log"
"go.opencensus.io/trace"
"stash.kopano.io/kc/konnect/bootstrap"
kcconfig "stash.kopano.io/kc/konnect/config"
"stash.kopano.io/kc/konnect/server"
@@ -206,11 +205,6 @@ func (k Konnectd) Index() http.HandlerFunc {
indexHTML = bytes.Replace(indexHTML, []byte("__CSP_NONCE__"), []byte(nonce), 1)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if k.config.Tracing.Enabled {
_, span := trace.StartSpan(r.Context(), "/identifier/index.html")
defer span.End()
}
w.WriteHeader(http.StatusOK)
w.Write(indexHTML)
})