[feature] Add a request ID and include it in logs (#1476)

This adds a lightweight form of tracing to GTS. Each incoming request is
assigned a Request ID which we then pass on and log in all our log
lines. Any function that gets called downstream from an HTTP handler
should now emit a requestID=value pair whenever it logs something.

Co-authored-by: kim <grufwub@gmail.com>
This commit is contained in:
Daenney
2023-02-17 12:02:29 +01:00
committed by GitHub
parent b5993095fa
commit 68e6d08c76
118 changed files with 813 additions and 591 deletions

View File

@@ -33,23 +33,23 @@ func (i *idp) HandleCallback(ctx context.Context, code string) (*Claims, gtserro
return nil, gtserror.NewErrorBadRequest(err, err.Error())
}
log.Debug("exchanging code for oauth2token")
log.Debug(ctx, "exchanging code for oauth2token")
oauth2Token, err := i.oauth2Config.Exchange(ctx, code)
if err != nil {
err := fmt.Errorf("error exchanging code for oauth2token: %s", err)
return nil, gtserror.NewErrorInternalError(err)
}
log.Debug("extracting id_token")
log.Debug(ctx, "extracting id_token")
rawIDToken, ok := oauth2Token.Extra("id_token").(string)
if !ok {
err := errors.New("no id_token in oauth2token")
return nil, gtserror.NewErrorBadRequest(err, err.Error())
}
log.Debugf("raw id token: %s", rawIDToken)
log.Debugf(ctx, "raw id token: %s", rawIDToken)
// Parse and verify ID Token payload.
log.Debug("verifying id_token")
log.Debug(ctx, "verifying id_token")
idTokenVerifier := i.provider.Verifier(i.oidcConf)
idToken, err := idTokenVerifier.Verify(ctx, rawIDToken)
if err != nil {
@@ -57,7 +57,7 @@ func (i *idp) HandleCallback(ctx context.Context, code string) (*Claims, gtserro
return nil, gtserror.NewErrorUnauthorized(err, err.Error())
}
log.Debug("extracting claims from id_token")
log.Debug(ctx, "extracting claims from id_token")
claims := &Claims{}
if err := idToken.Claims(claims); err != nil {
err := fmt.Errorf("could not parse claims from idToken: %s", err)