Skip to content

Commit

Permalink
chore: synchronize workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Sep 17, 2023
1 parent b734e39 commit b9e5c87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions session/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"encoding/json"
"time"

"go.opentelemetry.io/otel/trace"

"github.com/ory/kratos/x/events"

"github.com/gofrs/uuid"
"github.com/golang-jwt/jwt/v5"
"github.com/pkg/errors"
Expand Down Expand Up @@ -142,6 +146,7 @@ func (s *Tokenizer) TokenizeSession(ctx context.Context, template string, sessio
return errors.WithStack(herodot.ErrBadRequest.WithWrap(err).WithReasonf("Unable to sign JSON Web Token."))
}

trace.SpanFromContext(ctx).AddEvent(events.NewSessionJWTIssued(ctx, session.ID, session.IdentityID, tpl.TTL))
session.Tokenized = result
return nil
}
19 changes: 19 additions & 0 deletions x/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package events

import (
"context"
"time"

"github.com/gofrs/uuid"
otelattr "go.opentelemetry.io/otel/attribute"
Expand All @@ -17,6 +18,7 @@ const (
SessionIssued semconv.Event = "SessionIssued"
SessionChanged semconv.Event = "SessionChanged"
SessionRevoked semconv.Event = "SessionRevoked"
SessionTokenizedAsJWT semconv.Event = "SessionTokenizedAsJWT"
RegistrationFailed semconv.Event = "RegistrationFailed"
RegistrationSucceeded semconv.Event = "RegistrationSucceeded"
LoginFailed semconv.Event = "LoginFailed"
Expand All @@ -39,12 +41,17 @@ const (
attributeKeySelfServiceSSOProviderUsed semconv.AttributeKey = "SelfServiceSSOProviderUsed"
attributeKeyLoginRequestedAAL semconv.AttributeKey = "LoginRequestedAAL"
attributeKeyLoginRequestedPrivilegedSession semconv.AttributeKey = "LoginRequestedPrivilegedSession"
attributeKeyTokenizedSessionTTL semconv.AttributeKey = "TokenizedSessionTTL"
)

func attrSessionID(val uuid.UUID) otelattr.KeyValue {
return otelattr.String(attributeKeySessionID.String(), val.String())
}

func attrTokenizedSessionTTL(ttl time.Duration) otelattr.KeyValue {
return otelattr.String(attributeKeyTokenizedSessionTTL.String(), ttl.String())
}

func attrSessionAAL(val string) otelattr.KeyValue {
return otelattr.String(attributeKeySessionAAL.String(), val)
}
Expand Down Expand Up @@ -232,3 +239,15 @@ func NewSessionRevoked(ctx context.Context, sessionID, identityID uuid.UUID) (st
)...,
)
}

func NewSessionJWTIssued(ctx context.Context, sessionID, identityID uuid.UUID, ttl time.Duration) (string, trace.EventOption) {
return SessionTokenizedAsJWT.String(),
trace.WithAttributes(
append(
semconv.AttributesFromContext(ctx),
semconv.AttrIdentityID(identityID),
attrSessionID(sessionID),
attrTokenizedSessionTTL(ttl),
)...,
)
}

0 comments on commit b9e5c87

Please sign in to comment.