From 4afa9a01b652d20cf9f0bf159a3d57b94ddc7d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Mon, 23 Oct 2023 23:55:49 +0200 Subject: [PATCH] Add named span for verify token --- authmw/token.go | 6 +++++- version.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/authmw/token.go b/authmw/token.go index 8d7ef01..304ee56 100644 --- a/authmw/token.go +++ b/authmw/token.go @@ -13,11 +13,15 @@ import ( "git.t-juice.club/microfilm/auth" "github.com/golang-jwt/jwt/v5" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" + "go.opentelemetry.io/otel" ) func VerifyToken(authURL string, permittedRoles []string) func(http.Handler) http.Handler { fn := func(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { + ctx, span := otel.GetTracerProvider().Tracer("").Start(r.Context(), "verify-token") + defer span.End() + authHeader := r.Header.Get("Authorization") if !strings.Contains(authHeader, "Bearer ") { // No token, pass if unathorized in permitted @@ -40,7 +44,7 @@ func VerifyToken(authURL string, permittedRoles []string) func(http.Handler) htt // Fetch current pubkey url := fmt.Sprintf("%s/key", authURL) - ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) diff --git a/version.go b/version.go index 2dbf174..1432796 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package auth -const Version = "v0.1.4" +const Version = "v0.1.5"