Skip to content

Commit

Permalink
chore: improve tracing on recovery and verification (#3586)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas authored Nov 13, 2023
1 parent f7c6767 commit b2b231e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion selfservice/strategy/code/strategy_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion selfservice/strategy/code/strategy_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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().
Expand Down
6 changes: 6 additions & 0 deletions selfservice/strategy/code/strategy_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions selfservice/strategy/link/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type (
x.CSRFTokenGeneratorProvider
x.WriterProvider
x.LoggingProvider
x.TracingProvider

config.Provider

Expand Down
6 changes: 6 additions & 0 deletions selfservice/strategy/link/strategy_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions selfservice/strategy/link/strategy_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b2b231e

Please sign in to comment.