From b2b231ee58978c020e9123f194af67713e1f98a8 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Mon, 13 Nov 2023 11:10:04 +0100 Subject: [PATCH] chore: improve tracing on recovery and verification (#3586) --- selfservice/strategy/code/strategy_login.go | 2 +- selfservice/strategy/code/strategy_recovery.go | 7 ++++++- selfservice/strategy/code/strategy_verification.go | 6 ++++++ selfservice/strategy/link/strategy.go | 1 + selfservice/strategy/link/strategy_recovery.go | 6 ++++++ selfservice/strategy/link/strategy_verification.go | 7 +++++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/selfservice/strategy/code/strategy_login.go b/selfservice/strategy/code/strategy_login.go index e837e6f7756d..64a3ab13a325 100644 --- a/selfservice/strategy/code/strategy_login.go +++ b/selfservice/strategy/code/strategy_login.go @@ -101,7 +101,7 @@ func (s *Strategy) PopulateLoginMethod(r *http.Request, requestedAAL identity.Au // the identity through other credentials matching the identifier. // the fallback mechanism is used for migration purposes of old accounts that do not have a code credential. func (s *Strategy) findIdentityByIdentifier(ctx context.Context, identifier string) (_ *identity.Identity, isFallback bool, err error) { - ctx, span := s.deps.Tracer(ctx).Tracer().Start(ctx, "selfservice.strategy.code.strategy.getIdentity") + ctx, span := s.deps.Tracer(ctx).Tracer().Start(ctx, "selfservice.strategy.code.strategy.findIdentityByIdentifier") defer otelx.End(span, &err) id, cred, err := s.deps.PrivilegedIdentityPool().FindByCredentialsIdentifier(ctx, s.ID(), identifier) diff --git a/selfservice/strategy/code/strategy_recovery.go b/selfservice/strategy/code/strategy_recovery.go index 0bdc2d603801..6d75e065e7d1 100644 --- a/selfservice/strategy/code/strategy_recovery.go +++ b/selfservice/strategy/code/strategy_recovery.go @@ -11,9 +11,11 @@ import ( "github.com/gofrs/uuid" "github.com/julienschmidt/httprouter" "github.com/pkg/errors" + "go.opentelemetry.io/otel/attribute" "github.com/ory/herodot" "github.com/ory/x/decoderx" + "github.com/ory/x/otelx" "github.com/ory/x/sqlcon" "github.com/ory/x/sqlxx" "github.com/ory/x/urlx" @@ -285,6 +287,10 @@ func (s Strategy) isCodeFlow(f *recovery.Flow) bool { } func (s *Strategy) Recover(w http.ResponseWriter, r *http.Request, f *recovery.Flow) (err error) { + ctx, span := s.deps.Tracer(r.Context()).Tracer().Start(r.Context(), "selfservice.strategy.code.strategy.Recover") + span.SetAttributes(attribute.String("selfservice_flows_recovery_use", s.deps.Config().SelfServiceFlowRecoveryUse(ctx))) + defer otelx.End(span, &err) + if !s.isCodeFlow(f) { return errors.WithStack(flow.ErrStrategyNotResponsible) } @@ -293,7 +299,6 @@ func (s *Strategy) Recover(w http.ResponseWriter, r *http.Request, f *recovery.F if err != nil { return s.HandleRecoveryError(w, r, nil, body, err) } - ctx := r.Context() if f.DangerousSkipCSRFCheck { s.deps.Logger(). diff --git a/selfservice/strategy/code/strategy_verification.go b/selfservice/strategy/code/strategy_verification.go index c02e89105116..28e21456323e 100644 --- a/selfservice/strategy/code/strategy_verification.go +++ b/selfservice/strategy/code/strategy_verification.go @@ -9,6 +9,7 @@ import ( "time" "github.com/pkg/errors" + "go.opentelemetry.io/otel/attribute" "github.com/ory/kratos/identity" "github.com/ory/kratos/schema" @@ -19,6 +20,7 @@ import ( "github.com/ory/kratos/ui/node" "github.com/ory/kratos/x" "github.com/ory/x/decoderx" + "github.com/ory/x/otelx" "github.com/ory/x/sqlxx" ) @@ -123,6 +125,10 @@ func (body *updateVerificationFlowWithCodeMethod) getMethod() verification.Verif } func (s *Strategy) Verify(w http.ResponseWriter, r *http.Request, f *verification.Flow) (err error) { + ctx, span := s.deps.Tracer(r.Context()).Tracer().Start(r.Context(), "selfservice.strategy.code.strategy.Verify") + span.SetAttributes(attribute.String("selfservice_flows_verification_use", s.deps.Config().SelfServiceFlowVerificationUse(ctx))) + defer otelx.End(span, &err) + body, err := s.decodeVerification(r) if err != nil { return s.handleVerificationError(w, r, nil, body, err) diff --git a/selfservice/strategy/link/strategy.go b/selfservice/strategy/link/strategy.go index f5a0326b9d0b..8188b7e9e873 100644 --- a/selfservice/strategy/link/strategy.go +++ b/selfservice/strategy/link/strategy.go @@ -42,6 +42,7 @@ type ( x.CSRFTokenGeneratorProvider x.WriterProvider x.LoggingProvider + x.TracingProvider config.Provider diff --git a/selfservice/strategy/link/strategy_recovery.go b/selfservice/strategy/link/strategy_recovery.go index da4f40ac9516..326a35c7bfe0 100644 --- a/selfservice/strategy/link/strategy_recovery.go +++ b/selfservice/strategy/link/strategy_recovery.go @@ -11,9 +11,11 @@ import ( "github.com/gofrs/uuid" "github.com/julienschmidt/httprouter" "github.com/pkg/errors" + "go.opentelemetry.io/otel/attribute" "github.com/ory/herodot" "github.com/ory/x/decoderx" + "github.com/ory/x/otelx" "github.com/ory/x/sqlcon" "github.com/ory/x/sqlxx" "github.com/ory/x/urlx" @@ -231,6 +233,10 @@ type updateRecoveryFlowWithLinkMethod struct { } func (s *Strategy) Recover(w http.ResponseWriter, r *http.Request, f *recovery.Flow) (err error) { + ctx, span := s.d.Tracer(r.Context()).Tracer().Start(r.Context(), "selfservice.strategy.link.strategy.Recover") + span.SetAttributes(attribute.String("selfservice_flows_recovery_use", s.d.Config().SelfServiceFlowRecoveryUse(ctx))) + defer otelx.End(span, &err) + body, err := s.decodeRecovery(r) if err != nil { return s.HandleRecoveryError(w, r, nil, body, err) diff --git a/selfservice/strategy/link/strategy_verification.go b/selfservice/strategy/link/strategy_verification.go index 47271cd7191d..0db56233fa3f 100644 --- a/selfservice/strategy/link/strategy_verification.go +++ b/selfservice/strategy/link/strategy_verification.go @@ -10,6 +10,7 @@ import ( "time" "github.com/pkg/errors" + "go.opentelemetry.io/otel/attribute" "github.com/ory/kratos/identity" "github.com/ory/kratos/schema" @@ -20,6 +21,7 @@ import ( "github.com/ory/kratos/ui/node" "github.com/ory/kratos/x" "github.com/ory/x/decoderx" + "github.com/ory/x/otelx" "github.com/ory/x/sqlcon" "github.com/ory/x/sqlxx" "github.com/ory/x/urlx" @@ -116,6 +118,11 @@ type updateVerificationFlowWithLinkMethod struct { } func (s *Strategy) Verify(w http.ResponseWriter, r *http.Request, f *verification.Flow) (err error) { + ctx, span := s.d.Tracer(r.Context()).Tracer().Start(r.Context(), "selfservice.strategy.link.strategy.Verify") + span.SetAttributes(attribute.String("selfservice_flows_verification_use", s.d.Config().SelfServiceFlowVerificationUse(ctx))) + defer otelx.End(span, &err) + r = r.WithContext(ctx) + body, err := s.decodeVerification(r) if err != nil { return s.handleVerificationError(w, r, nil, body, err)