From 28760ab4b3028a8a2b7a021603f1732a16c5cb6b Mon Sep 17 00:00:00 2001 From: Silvan Date: Thu, 1 Dec 2022 09:18:53 +0100 Subject: [PATCH] fix(query): add tracing for each method (#4777) * fix(query): add tracing for each method --- internal/query/action.go | 9 +++- internal/query/action_flow.go | 16 ++++-- internal/query/app.go | 56 ++++++++++++++++---- internal/query/authn_key.go | 18 +++++-- internal/query/certificate.go | 6 ++- internal/query/changes.go | 38 ++++++++----- internal/query/current_sequence.go | 9 +++- internal/query/custom_text.go | 23 ++++++-- internal/query/domain_policy.go | 12 +++-- internal/query/iam_member.go | 6 ++- internal/query/idp.go | 17 ++++-- internal/query/idp_login_policy_link.go | 4 ++ internal/query/idp_user_link.go | 4 ++ internal/query/instance.go | 14 ++++- internal/query/instance_domain.go | 7 +++ internal/query/key.go | 12 +++-- internal/query/label_policy.go | 21 ++++++-- internal/query/lockout_policy.go | 12 +++-- internal/query/login_policy.go | 31 ++++++++--- internal/query/mail_template.go | 11 +++- internal/query/message_text.go | 22 ++++++-- internal/query/notification_provider.go | 7 ++- internal/query/oidc_settings.go | 6 ++- internal/query/org.go | 26 +++++++-- internal/query/org_domain.go | 4 ++ internal/query/org_member.go | 10 ++-- internal/query/org_metadata.go | 11 +++- internal/query/password_age_policy.go | 11 +++- internal/query/password_complexity_policy.go | 11 +++- internal/query/privacy_policy.go | 11 +++- internal/query/project.go | 12 +++-- internal/query/project_grant.go | 20 +++++-- internal/query/project_grant_member.go | 1 - internal/query/project_member.go | 7 ++- internal/query/project_role.go | 7 +++ internal/query/secret_generators.go | 15 ++++-- internal/query/sms.go | 16 ++++-- internal/query/smtp.go | 10 ++-- internal/query/user.go | 46 ++++++++++++---- internal/query/user_auth_method.go | 4 ++ internal/query/user_grant.go | 11 +++- internal/query/user_membership.go | 6 ++- internal/query/user_metadata.go | 12 +++-- internal/query/user_otp.go | 12 +++-- internal/query/user_password.go | 14 +++-- internal/query/user_personal_access_token.go | 13 +++-- internal/query/zitadel_permission.go | 6 ++- 47 files changed, 519 insertions(+), 138 deletions(-) diff --git a/internal/query/action.go b/internal/query/action.go index 0aba5b6898..9e4246ca29 100644 --- a/internal/query/action.go +++ b/internal/query/action.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) const ( @@ -113,6 +114,9 @@ func (q *ActionSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder { } func (q *Queries) SearchActions(ctx context.Context, queries *ActionSearchQueries, withOwnerRemoved bool) (actions *Actions, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareActionsQuery() eq := sq.Eq{ ActionColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(), @@ -137,7 +141,10 @@ func (q *Queries) SearchActions(ctx context.Context, queries *ActionSearchQuerie return actions, err } -func (q *Queries) GetActionByID(ctx context.Context, id string, orgID string, withOwnerRemoved bool) (*Action, error) { +func (q *Queries) GetActionByID(ctx context.Context, id string, orgID string, withOwnerRemoved bool) (_ *Action, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareActionQuery() eq := sq.Eq{ ActionColumnID.identifier(): id, diff --git a/internal/query/action_flow.go b/internal/query/action_flow.go index 3313750e81..56a3771d3c 100644 --- a/internal/query/action_flow.go +++ b/internal/query/action_flow.go @@ -11,6 +11,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -65,7 +66,10 @@ type Flow struct { TriggerActions map[domain.TriggerType][]*Action } -func (q *Queries) GetFlow(ctx context.Context, flowType domain.FlowType, orgID string, withOwnerRemoved bool) (*Flow, error) { +func (q *Queries) GetFlow(ctx context.Context, flowType domain.FlowType, orgID string, withOwnerRemoved bool) (_ *Flow, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareFlowQuery(flowType) eq := sq.Eq{ FlowsTriggersColumnFlowType.identifier(): flowType, @@ -87,7 +91,10 @@ func (q *Queries) GetFlow(ctx context.Context, flowType domain.FlowType, orgID s return scan(rows) } -func (q *Queries) GetActiveActionsByFlowAndTriggerType(ctx context.Context, flowType domain.FlowType, triggerType domain.TriggerType, orgID string, withOwnerRemoved bool) ([]*Action, error) { +func (q *Queries) GetActiveActionsByFlowAndTriggerType(ctx context.Context, flowType domain.FlowType, triggerType domain.TriggerType, orgID string, withOwnerRemoved bool) (_ []*Action, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareTriggerActionsQuery() eq := sq.Eq{ FlowsTriggersColumnFlowType.identifier(): flowType, @@ -111,7 +118,10 @@ func (q *Queries) GetActiveActionsByFlowAndTriggerType(ctx context.Context, flow return scan(rows) } -func (q *Queries) GetFlowTypesOfActionID(ctx context.Context, actionID string, withOwnerRemoved bool) ([]domain.FlowType, error) { +func (q *Queries) GetFlowTypesOfActionID(ctx context.Context, actionID string, withOwnerRemoved bool) (_ []domain.FlowType, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareFlowTypesQuery() eq := sq.Eq{ FlowsTriggersColumnActionID.identifier(): actionID, diff --git a/internal/query/app.go b/internal/query/app.go index 8b58a9d351..5ce5dc7fb4 100644 --- a/internal/query/app.go +++ b/internal/query/app.go @@ -14,6 +14,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type Apps struct { @@ -241,7 +242,10 @@ var ( } ) -func (q *Queries) AppByProjectAndAppID(ctx context.Context, shouldTriggerBulk bool, projectID, appID string, withOwnerRemoved bool) (*App, error) { +func (q *Queries) AppByProjectAndAppID(ctx context.Context, shouldTriggerBulk bool, projectID, appID string, withOwnerRemoved bool) (_ *App, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.AppProjection.Trigger(ctx) } @@ -264,7 +268,10 @@ func (q *Queries) AppByProjectAndAppID(ctx context.Context, shouldTriggerBulk bo return scan(row) } -func (q *Queries) AppByID(ctx context.Context, appID string, withOwnerRemoved bool) (*App, error) { +func (q *Queries) AppByID(ctx context.Context, appID string, withOwnerRemoved bool) (_ *App, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareAppQuery() eq := sq.Eq{ AppColumnID.identifier(): appID, @@ -282,7 +289,10 @@ func (q *Queries) AppByID(ctx context.Context, appID string, withOwnerRemoved bo return scan(row) } -func (q *Queries) AppBySAMLEntityID(ctx context.Context, entityID string, withOwnerRemoved bool) (*App, error) { +func (q *Queries) AppBySAMLEntityID(ctx context.Context, entityID string, withOwnerRemoved bool) (_ *App, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareAppQuery() eq := sq.Eq{ AppSAMLConfigColumnEntityID.identifier(): entityID, @@ -300,7 +310,10 @@ func (q *Queries) AppBySAMLEntityID(ctx context.Context, entityID string, withOw return scan(row) } -func (q *Queries) ProjectByClientID(ctx context.Context, appID string, withOwnerRemoved bool) (*Project, error) { +func (q *Queries) ProjectByClientID(ctx context.Context, appID string, withOwnerRemoved bool) (_ *Project, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareProjectByAppQuery() eq := sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { @@ -322,7 +335,10 @@ func (q *Queries) ProjectByClientID(ctx context.Context, appID string, withOwner return scan(row) } -func (q *Queries) ProjectIDFromOIDCClientID(ctx context.Context, appID string, withOwnerRemoved bool) (string, error) { +func (q *Queries) ProjectIDFromOIDCClientID(ctx context.Context, appID string, withOwnerRemoved bool) (_ string, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareProjectIDByAppQuery() eq := sq.Eq{ AppOIDCConfigColumnClientID.identifier(): appID, @@ -340,7 +356,10 @@ func (q *Queries) ProjectIDFromOIDCClientID(ctx context.Context, appID string, w return scan(row) } -func (q *Queries) ProjectIDFromClientID(ctx context.Context, appID string, withOwnerRemoved bool) (string, error) { +func (q *Queries) ProjectIDFromClientID(ctx context.Context, appID string, withOwnerRemoved bool) (_ string, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareProjectIDByAppQuery() eq := sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { @@ -363,7 +382,10 @@ func (q *Queries) ProjectIDFromClientID(ctx context.Context, appID string, withO return scan(row) } -func (q *Queries) ProjectByOIDCClientID(ctx context.Context, id string, withOwnerRemoved bool) (*Project, error) { +func (q *Queries) ProjectByOIDCClientID(ctx context.Context, id string, withOwnerRemoved bool) (_ *Project, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareProjectByAppQuery() eq := sq.Eq{ AppOIDCConfigColumnClientID.identifier(): id, @@ -381,7 +403,10 @@ func (q *Queries) ProjectByOIDCClientID(ctx context.Context, id string, withOwne return scan(row) } -func (q *Queries) AppByOIDCClientID(ctx context.Context, clientID string, withOwnerRemoved bool) (*App, error) { +func (q *Queries) AppByOIDCClientID(ctx context.Context, clientID string, withOwnerRemoved bool) (_ *App, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareAppQuery() eq := sq.Eq{ AppOIDCConfigColumnClientID.identifier(): clientID, @@ -399,7 +424,10 @@ func (q *Queries) AppByOIDCClientID(ctx context.Context, clientID string, withOw return scan(row) } -func (q *Queries) AppByClientID(ctx context.Context, clientID string, withOwnerRemoved bool) (*App, error) { +func (q *Queries) AppByClientID(ctx context.Context, clientID string, withOwnerRemoved bool) (_ *App, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareAppQuery() var eq []sq.Sqlizer eq = append(eq, sq.And{ @@ -421,7 +449,10 @@ func (q *Queries) AppByClientID(ctx context.Context, clientID string, withOwnerR return scan(row) } -func (q *Queries) SearchApps(ctx context.Context, queries *AppSearchQueries, withOwnerRemoved bool) (*Apps, error) { +func (q *Queries) SearchApps(ctx context.Context, queries *AppSearchQueries, withOwnerRemoved bool) (_ *Apps, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareAppsQuery() eq := sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { @@ -444,7 +475,10 @@ func (q *Queries) SearchApps(ctx context.Context, queries *AppSearchQueries, wit return apps, err } -func (q *Queries) SearchClientIDs(ctx context.Context, queries *AppSearchQueries, withOwnerRemoved bool) ([]string, error) { +func (q *Queries) SearchClientIDs(ctx context.Context, queries *AppSearchQueries, withOwnerRemoved bool) (_ []string, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareClientIDsQuery() eq := sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/authn_key.go b/internal/query/authn_key.go index 01cb10bdf6..455a96db81 100644 --- a/internal/query/authn_key.go +++ b/internal/query/authn_key.go @@ -9,10 +9,10 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -126,6 +126,9 @@ func (q *AuthNKeySearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder } func (q *Queries) SearchAuthNKeys(ctx context.Context, queries *AuthNKeySearchQueries, withOwnerRemoved bool) (authNKeys *AuthNKeys, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareAuthNKeysQuery() query = queries.toQuery(query) eq := sq.Eq{ @@ -153,6 +156,9 @@ func (q *Queries) SearchAuthNKeys(ctx context.Context, queries *AuthNKeySearchQu } func (q *Queries) SearchAuthNKeysData(ctx context.Context, queries *AuthNKeySearchQueries, withOwnerRemoved bool) (authNKeys *AuthNKeysData, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareAuthNKeysDataQuery() query = queries.toQuery(query) eq := sq.Eq{ @@ -179,7 +185,10 @@ func (q *Queries) SearchAuthNKeysData(ctx context.Context, queries *AuthNKeySear return authNKeys, err } -func (q *Queries) GetAuthNKeyByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool, queries ...SearchQuery) (*AuthNKey, error) { +func (q *Queries) GetAuthNKeyByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool, queries ...SearchQuery) (_ *AuthNKey, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.AuthNKeyProjection.Trigger(ctx) } @@ -205,7 +214,10 @@ func (q *Queries) GetAuthNKeyByID(ctx context.Context, shouldTriggerBulk bool, i return scan(row) } -func (q *Queries) GetAuthNKeyPublicKeyByIDAndIdentifier(ctx context.Context, id string, identifier string, withOwnerRemoved bool) ([]byte, error) { +func (q *Queries) GetAuthNKeyPublicKeyByIDAndIdentifier(ctx context.Context, id string, identifier string, withOwnerRemoved bool) (_ []byte, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareAuthNKeyPublicKeyQuery() eq := sq.And{ sq.Eq{ diff --git a/internal/query/certificate.go b/internal/query/certificate.go index 5ecf053fc5..79a995959f 100644 --- a/internal/query/certificate.go +++ b/internal/query/certificate.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type Certificate interface { @@ -64,7 +65,10 @@ var ( } ) -func (q *Queries) ActiveCertificates(ctx context.Context, t time.Time, usage domain.KeyUsage) (*Certificates, error) { +func (q *Queries) ActiveCertificates(ctx context.Context, t time.Time, usage domain.KeyUsage) (_ *Certificates, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareCertificateQuery() if t.IsZero() { t = time.Now() diff --git a/internal/query/changes.go b/internal/query/changes.go index 27fc931775..77e23cfc87 100644 --- a/internal/query/changes.go +++ b/internal/query/changes.go @@ -6,15 +6,12 @@ import ( "github.com/zitadel/logging" - "github.com/zitadel/zitadel/internal/repository/user" - - "github.com/zitadel/zitadel/internal/repository/project" - - "github.com/zitadel/zitadel/internal/repository/org" - - "github.com/zitadel/zitadel/internal/eventstore" - "github.com/zitadel/zitadel/internal/errors" + "github.com/zitadel/zitadel/internal/eventstore" + "github.com/zitadel/zitadel/internal/repository/org" + "github.com/zitadel/zitadel/internal/repository/project" + "github.com/zitadel/zitadel/internal/repository/user" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type Changes struct { @@ -33,7 +30,10 @@ type Change struct { ModifierAvatarKey string } -func (q *Queries) OrgChanges(ctx context.Context, orgID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (*Changes, error) { +func (q *Queries) OrgChanges(ctx context.Context, orgID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (_ *Changes, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query := func(query *eventstore.SearchQuery) { query.AggregateTypes(org.AggregateType). AggregateIDs(orgID) @@ -42,7 +42,10 @@ func (q *Queries) OrgChanges(ctx context.Context, orgID string, lastSequence uin } -func (q *Queries) ProjectChanges(ctx context.Context, projectID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (*Changes, error) { +func (q *Queries) ProjectChanges(ctx context.Context, projectID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (_ *Changes, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query := func(query *eventstore.SearchQuery) { query.AggregateTypes(project.AggregateType). AggregateIDs(projectID) @@ -50,7 +53,10 @@ func (q *Queries) ProjectChanges(ctx context.Context, projectID string, lastSequ return q.changes(ctx, query, lastSequence, limit, sortAscending, auditLogRetention) } -func (q *Queries) ProjectGrantChanges(ctx context.Context, projectID, grantID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (*Changes, error) { +func (q *Queries) ProjectGrantChanges(ctx context.Context, projectID, grantID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (_ *Changes, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query := func(query *eventstore.SearchQuery) { query.AggregateTypes(project.AggregateType). AggregateIDs(projectID). @@ -61,7 +67,10 @@ func (q *Queries) ProjectGrantChanges(ctx context.Context, projectID, grantID st return q.changes(ctx, query, lastSequence, limit, sortAscending, auditLogRetention) } -func (q *Queries) ApplicationChanges(ctx context.Context, projectID, appID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (*Changes, error) { +func (q *Queries) ApplicationChanges(ctx context.Context, projectID, appID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (_ *Changes, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query := func(query *eventstore.SearchQuery) { query.AggregateTypes(project.AggregateType). AggregateIDs(projectID). @@ -72,7 +81,10 @@ func (q *Queries) ApplicationChanges(ctx context.Context, projectID, appID strin return q.changes(ctx, query, lastSequence, limit, sortAscending, auditLogRetention) } -func (q *Queries) UserChanges(ctx context.Context, userID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (*Changes, error) { +func (q *Queries) UserChanges(ctx context.Context, userID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (_ *Changes, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query := func(query *eventstore.SearchQuery) { query.AggregateTypes(user.AggregateType). AggregateIDs(userID) diff --git a/internal/query/current_sequence.go b/internal/query/current_sequence.go index 5b604dc8e7..ba784c6aba 100644 --- a/internal/query/current_sequence.go +++ b/internal/query/current_sequence.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) const ( @@ -55,6 +56,9 @@ func (q *CurrentSequencesSearchQueries) toQuery(query sq.SelectBuilder) sq.Selec } func (q *Queries) SearchCurrentSequences(ctx context.Context, queries *CurrentSequencesSearchQueries) (failedEvents *CurrentSequences, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareCurrentSequencesQuery() stmt, args, err := queries.toQuery(query).ToSql() if err != nil { @@ -68,7 +72,10 @@ func (q *Queries) SearchCurrentSequences(ctx context.Context, queries *CurrentSe return scan(rows) } -func (q *Queries) latestSequence(ctx context.Context, projections ...table) (*LatestSequence, error) { +func (q *Queries) latestSequence(ctx context.Context, projections ...table) (_ *LatestSequence, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareLatestSequence() or := make(sq.Or, len(projections)) for i, projection := range projections { diff --git a/internal/query/custom_text.go b/internal/query/custom_text.go index 99eb8b033f..4511d70ebd 100644 --- a/internal/query/custom_text.go +++ b/internal/query/custom_text.go @@ -13,11 +13,11 @@ import ( "sigs.k8s.io/yaml" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/eventstore/v1/models" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type CustomTexts struct { @@ -85,6 +85,9 @@ var ( ) func (q *Queries) CustomTextList(ctx context.Context, aggregateID, template, language string, withOwnerRemoved bool) (texts *CustomTexts, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareCustomTextsQuery() eq := sq.Eq{ CustomTextColAggregateID.identifier(): aggregateID, @@ -113,6 +116,9 @@ func (q *Queries) CustomTextList(ctx context.Context, aggregateID, template, lan } func (q *Queries) CustomTextListByTemplate(ctx context.Context, aggregateID, template string, withOwnerRemoved bool) (texts *CustomTexts, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareCustomTextsQuery() eq := sq.Eq{ CustomTextColAggregateID.identifier(): aggregateID, @@ -139,7 +145,10 @@ func (q *Queries) CustomTextListByTemplate(ctx context.Context, aggregateID, tem return texts, err } -func (q *Queries) GetDefaultLoginTexts(ctx context.Context, lang string) (*domain.CustomLoginText, error) { +func (q *Queries) GetDefaultLoginTexts(ctx context.Context, lang string) (_ *domain.CustomLoginText, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + contents, err := q.readLoginTranslationFile(ctx, lang) if err != nil { return nil, err @@ -153,7 +162,10 @@ func (q *Queries) GetDefaultLoginTexts(ctx context.Context, lang string) (*domai return loginText, nil } -func (q *Queries) GetCustomLoginTexts(ctx context.Context, aggregateID, lang string) (*domain.CustomLoginText, error) { +func (q *Queries) GetCustomLoginTexts(ctx context.Context, aggregateID, lang string) (_ *domain.CustomLoginText, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + texts, err := q.CustomTextList(ctx, aggregateID, domain.LoginCustomText, lang, false) if err != nil { return nil, err @@ -161,7 +173,10 @@ func (q *Queries) GetCustomLoginTexts(ctx context.Context, aggregateID, lang str return CustomTextsToLoginDomain(authz.GetInstance(ctx).InstanceID(), aggregateID, lang, texts), err } -func (q *Queries) IAMLoginTexts(ctx context.Context, lang string) (*domain.CustomLoginText, error) { +func (q *Queries) IAMLoginTexts(ctx context.Context, lang string) (_ *domain.CustomLoginText, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + contents, err := q.readLoginTranslationFile(ctx, lang) if err != nil { return nil, err diff --git a/internal/query/domain_policy.go b/internal/query/domain_policy.go index 175a8c6a7a..a5579ebffe 100644 --- a/internal/query/domain_policy.go +++ b/internal/query/domain_policy.go @@ -9,10 +9,10 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type DomainPolicy struct { @@ -85,7 +85,10 @@ var ( } ) -func (q *Queries) DomainPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (*DomainPolicy, error) { +func (q *Queries) DomainPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (_ *DomainPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.DomainPolicyProjection.Trigger(ctx) } @@ -120,7 +123,10 @@ func (q *Queries) DomainPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, return scan(row) } -func (q *Queries) DefaultDomainPolicy(ctx context.Context) (*DomainPolicy, error) { +func (q *Queries) DefaultDomainPolicy(ctx context.Context) (_ *DomainPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareDomainPolicyQuery() query, args, err := stmt.Where(sq.Eq{ DomainPolicyColID.identifier(): authz.GetInstance(ctx).InstanceID(), diff --git a/internal/query/iam_member.go b/internal/query/iam_member.go index 44e8031aa4..43905c7830 100644 --- a/internal/query/iam_member.go +++ b/internal/query/iam_member.go @@ -9,6 +9,7 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -73,7 +74,10 @@ func addIamMemberWithoutOwnerRemoved(eq map[string]interface{}) { eq[InstanceMemberOwnerRemovedUser.identifier()] = false } -func (q *Queries) IAMMembers(ctx context.Context, queries *IAMMembersQuery, withOwnerRemoved bool) (*Members, error) { +func (q *Queries) IAMMembers(ctx context.Context, queries *IAMMembersQuery, withOwnerRemoved bool) (_ *Members, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareInstanceMembersQuery() eq := sq.Eq{InstanceMemberInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/idp.go b/internal/query/idp.go index 115231e85e..f0996888c3 100644 --- a/internal/query/idp.go +++ b/internal/query/idp.go @@ -9,12 +9,12 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/database" - "github.com/zitadel/zitadel/internal/crypto" + "github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type IDP struct { @@ -187,7 +187,10 @@ var ( ) // IDPByIDAndResourceOwner searches for the requested id in the context of the resource owner and IAM -func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, shouldTriggerBulk bool, id, resourceOwner string, withOwnerRemoved bool) (*IDP, error) { +func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, shouldTriggerBulk bool, id, resourceOwner string, withOwnerRemoved bool) (_ *IDP, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.IDPProjection.Trigger(ctx) } @@ -218,6 +221,9 @@ func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, shouldTriggerBulk // IDPs searches idps matching the query func (q *Queries) IDPs(ctx context.Context, queries *IDPSearchQueries, withOwnerRemoved bool) (idps *IDPs, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareIDPsQuery() eq := sq.Eq{ IDPInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID(), @@ -512,7 +518,10 @@ func prepareIDPsQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPs, error)) { } } -func (q *Queries) GetOIDCIDPClientSecret(ctx context.Context, shouldRealTime bool, resourceowner, idpID string, withOwnerRemoved bool) (string, error) { +func (q *Queries) GetOIDCIDPClientSecret(ctx context.Context, shouldRealTime bool, resourceowner, idpID string, withOwnerRemoved bool) (_ string, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + idp, err := q.IDPByIDAndResourceOwner(ctx, shouldRealTime, idpID, resourceowner, withOwnerRemoved) if err != nil { return "", err diff --git a/internal/query/idp_login_policy_link.go b/internal/query/idp_login_policy_link.go index 17ec9c1c27..f6640cf3e6 100644 --- a/internal/query/idp_login_policy_link.go +++ b/internal/query/idp_login_policy_link.go @@ -10,6 +10,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type IDPLoginPolicyLink struct { @@ -80,6 +81,9 @@ var ( ) func (q *Queries) IDPLoginPolicyLinks(ctx context.Context, resourceOwner string, queries *IDPLoginPolicyLinksSearchQuery, withOwnerRemoved bool) (idps *IDPLoginPolicyLinks, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareIDPLoginPolicyLinksQuery() eq := sq.Eq{ IDPLoginPolicyLinkResourceOwnerCol.identifier(): resourceOwner, diff --git a/internal/query/idp_user_link.go b/internal/query/idp_user_link.go index 3138787f77..bd2f3eab80 100644 --- a/internal/query/idp_user_link.go +++ b/internal/query/idp_user_link.go @@ -10,6 +10,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type IDPUserLink struct { @@ -88,6 +89,9 @@ var ( ) func (q *Queries) IDPUserLinks(ctx context.Context, queries *IDPUserLinksSearchQuery, withOwnerRemoved bool) (idps *IDPUserLinks, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareIDPUserLinksQuery() eq := sq.Eq{IDPUserLinkInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/instance.go b/internal/query/instance.go index d411bca359..ab8c8a6451 100644 --- a/internal/query/instance.go +++ b/internal/query/instance.go @@ -13,6 +13,7 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) const ( @@ -141,6 +142,9 @@ func (q *InstanceSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder } func (q *Queries) SearchInstances(ctx context.Context, queries *InstanceSearchQueries) (instances *Instances, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + filter, query, scan := prepareInstancesQuery() stmt, args, err := query(queries.toQuery(filter)).ToSql() if err != nil { @@ -158,7 +162,10 @@ func (q *Queries) SearchInstances(ctx context.Context, queries *InstanceSearchQu return instances, err } -func (q *Queries) Instance(ctx context.Context, shouldTriggerBulk bool) (*Instance, error) { +func (q *Queries) Instance(ctx context.Context, shouldTriggerBulk bool) (_ *Instance, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.InstanceProjection.Trigger(ctx) } @@ -178,7 +185,10 @@ func (q *Queries) Instance(ctx context.Context, shouldTriggerBulk bool) (*Instan return scan(row) } -func (q *Queries) InstanceByHost(ctx context.Context, host string) (authz.Instance, error) { +func (q *Queries) InstanceByHost(ctx context.Context, host string) (_ authz.Instance, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareInstanceDomainQuery(host) host = strings.Split(host, ":")[0] //remove possible port query, args, err := stmt.Where(sq.Eq{ diff --git a/internal/query/instance_domain.go b/internal/query/instance_domain.go index c39a5f062b..ab7e217e07 100644 --- a/internal/query/instance_domain.go +++ b/internal/query/instance_domain.go @@ -10,6 +10,7 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type InstanceDomain struct { @@ -57,6 +58,9 @@ func NewInstanceDomainPrimarySearchQuery(primary bool) (SearchQuery, error) { } func (q *Queries) SearchInstanceDomains(ctx context.Context, queries *InstanceDomainSearchQueries) (domains *InstanceDomains, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareInstanceDomainsQuery() stmt, args, err := queries.toQuery(query). Where(sq.Eq{ @@ -70,6 +74,9 @@ func (q *Queries) SearchInstanceDomains(ctx context.Context, queries *InstanceDo } func (q *Queries) SearchInstanceDomainsGlobal(ctx context.Context, queries *InstanceDomainSearchQueries) (domains *InstanceDomains, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareInstanceDomainsQuery() stmt, args, err := queries.toQuery(query).ToSql() if err != nil { diff --git a/internal/query/key.go b/internal/query/key.go index 510c520c5b..103183e977 100644 --- a/internal/query/key.go +++ b/internal/query/key.go @@ -9,11 +9,11 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/crypto" "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type Key interface { @@ -176,7 +176,10 @@ var ( } ) -func (q *Queries) ActivePublicKeys(ctx context.Context, t time.Time) (*PublicKeys, error) { +func (q *Queries) ActivePublicKeys(ctx context.Context, t time.Time) (_ *PublicKeys, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := preparePublicKeysQuery() if t.IsZero() { t = time.Now() @@ -205,7 +208,10 @@ func (q *Queries) ActivePublicKeys(ctx context.Context, t time.Time) (*PublicKey return keys, nil } -func (q *Queries) ActivePrivateSigningKey(ctx context.Context, t time.Time) (*PrivateKeys, error) { +func (q *Queries) ActivePrivateSigningKey(ctx context.Context, t time.Time) (_ *PrivateKeys, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := preparePrivateKeysQuery() if t.IsZero() { t = time.Now() diff --git a/internal/query/label_policy.go b/internal/query/label_policy.go index 8ce611b24e..6c0293358a 100644 --- a/internal/query/label_policy.go +++ b/internal/query/label_policy.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type LabelPolicy struct { @@ -40,7 +41,10 @@ type Theme struct { IconURL string } -func (q *Queries) ActiveLabelPolicyByOrg(ctx context.Context, orgID string, withOwnerRemoved bool) (*LabelPolicy, error) { +func (q *Queries) ActiveLabelPolicyByOrg(ctx context.Context, orgID string, withOwnerRemoved bool) (_ *LabelPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareLabelPolicyQuery() eq := sq.Eq{ LabelPolicyColState.identifier(): domain.LabelPolicyStateActive, @@ -67,7 +71,10 @@ func (q *Queries) ActiveLabelPolicyByOrg(ctx context.Context, orgID string, with return scan(row) } -func (q *Queries) PreviewLabelPolicyByOrg(ctx context.Context, orgID string) (*LabelPolicy, error) { +func (q *Queries) PreviewLabelPolicyByOrg(ctx context.Context, orgID string) (_ *LabelPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareLabelPolicyQuery() query, args, err := stmt.Where( sq.And{ @@ -94,7 +101,10 @@ func (q *Queries) PreviewLabelPolicyByOrg(ctx context.Context, orgID string) (*L return scan(row) } -func (q *Queries) DefaultActiveLabelPolicy(ctx context.Context) (*LabelPolicy, error) { +func (q *Queries) DefaultActiveLabelPolicy(ctx context.Context) (_ *LabelPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareLabelPolicyQuery() query, args, err := stmt.Where(sq.Eq{ LabelPolicyColID.identifier(): authz.GetInstance(ctx).InstanceID(), @@ -111,7 +121,10 @@ func (q *Queries) DefaultActiveLabelPolicy(ctx context.Context) (*LabelPolicy, e return scan(row) } -func (q *Queries) DefaultPreviewLabelPolicy(ctx context.Context) (*LabelPolicy, error) { +func (q *Queries) DefaultPreviewLabelPolicy(ctx context.Context) (_ *LabelPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareLabelPolicyQuery() query, args, err := stmt.Where(sq.Eq{ LabelPolicyColID.identifier(): authz.GetInstance(ctx).InstanceID(), diff --git a/internal/query/lockout_policy.go b/internal/query/lockout_policy.go index 65f779317a..babda3bbb8 100644 --- a/internal/query/lockout_policy.go +++ b/internal/query/lockout_policy.go @@ -9,10 +9,10 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type LockoutPolicy struct { @@ -80,7 +80,10 @@ var ( } ) -func (q *Queries) LockoutPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (*LockoutPolicy, error) { +func (q *Queries) LockoutPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (_ *LockoutPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.LockoutPolicyProjection.Trigger(ctx) } @@ -110,7 +113,10 @@ func (q *Queries) LockoutPolicyByOrg(ctx context.Context, shouldTriggerBulk bool return scan(row) } -func (q *Queries) DefaultLockoutPolicy(ctx context.Context) (*LockoutPolicy, error) { +func (q *Queries) DefaultLockoutPolicy(ctx context.Context) (_ *LockoutPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareLockoutPolicyQuery() query, args, err := stmt.Where(sq.Eq{ LockoutColID.identifier(): authz.GetInstance(ctx).InstanceID(), diff --git a/internal/query/login_policy.go b/internal/query/login_policy.go index f468da8003..d8c34067b7 100644 --- a/internal/query/login_policy.go +++ b/internal/query/login_policy.go @@ -13,6 +13,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type LoginPolicy struct { @@ -159,7 +160,10 @@ var ( } ) -func (q *Queries) LoginPolicyByID(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (*LoginPolicy, error) { +func (q *Queries) LoginPolicyByID(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (_ *LoginPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.LoginPolicyProjection.Trigger(ctx) } @@ -204,7 +208,10 @@ func (q *Queries) scanAndAddLinksToLoginPolicy(ctx context.Context, rows *sql.Ro return policy, nil } -func (q *Queries) DefaultLoginPolicy(ctx context.Context) (*LoginPolicy, error) { +func (q *Queries) DefaultLoginPolicy(ctx context.Context) (_ *LoginPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareLoginPolicyQuery() stmt, args, err := query.Where(sq.Eq{ LoginPolicyColumnOrgID.identifier(): authz.GetInstance(ctx).InstanceID(), @@ -221,7 +228,10 @@ func (q *Queries) DefaultLoginPolicy(ctx context.Context) (*LoginPolicy, error) return q.scanAndAddLinksToLoginPolicy(ctx, rows, scan) } -func (q *Queries) SecondFactorsByOrg(ctx context.Context, orgID string) (*SecondFactors, error) { +func (q *Queries) SecondFactorsByOrg(ctx context.Context, orgID string) (_ *SecondFactors, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareLoginPolicy2FAsQuery() stmt, args, err := query.Where( sq.And{ @@ -252,7 +262,10 @@ func (q *Queries) SecondFactorsByOrg(ctx context.Context, orgID string) (*Second return factors, err } -func (q *Queries) DefaultSecondFactors(ctx context.Context) (*SecondFactors, error) { +func (q *Queries) DefaultSecondFactors(ctx context.Context) (_ *SecondFactors, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareLoginPolicy2FAsQuery() stmt, args, err := query.Where(sq.Eq{ LoginPolicyColumnOrgID.identifier(): authz.GetInstance(ctx).InstanceID(), @@ -271,7 +284,10 @@ func (q *Queries) DefaultSecondFactors(ctx context.Context) (*SecondFactors, err return factors, err } -func (q *Queries) MultiFactorsByOrg(ctx context.Context, orgID string) (*MultiFactors, error) { +func (q *Queries) MultiFactorsByOrg(ctx context.Context, orgID string) (_ *MultiFactors, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareLoginPolicyMFAsQuery() stmt, args, err := query.Where( sq.And{ @@ -302,7 +318,10 @@ func (q *Queries) MultiFactorsByOrg(ctx context.Context, orgID string) (*MultiFa return factors, err } -func (q *Queries) DefaultMultiFactors(ctx context.Context) (*MultiFactors, error) { +func (q *Queries) DefaultMultiFactors(ctx context.Context) (_ *MultiFactors, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareLoginPolicyMFAsQuery() stmt, args, err := query.Where(sq.Eq{ LoginPolicyColumnOrgID.identifier(): authz.GetInstance(ctx).InstanceID(), diff --git a/internal/query/mail_template.go b/internal/query/mail_template.go index 4ea256a854..0cabf46c09 100644 --- a/internal/query/mail_template.go +++ b/internal/query/mail_template.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type MailTemplate struct { @@ -68,7 +69,10 @@ var ( } ) -func (q *Queries) MailTemplateByOrg(ctx context.Context, orgID string, withOwnerRemoved bool) (*MailTemplate, error) { +func (q *Queries) MailTemplateByOrg(ctx context.Context, orgID string, withOwnerRemoved bool) (_ *MailTemplate, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareMailTemplateQuery() eq := sq.Eq{MailTemplateColInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { @@ -92,7 +96,10 @@ func (q *Queries) MailTemplateByOrg(ctx context.Context, orgID string, withOwner return scan(row) } -func (q *Queries) DefaultMailTemplate(ctx context.Context) (*MailTemplate, error) { +func (q *Queries) DefaultMailTemplate(ctx context.Context) (_ *MailTemplate, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareMailTemplateQuery() query, args, err := stmt.Where(sq.Eq{ MailTemplateColAggregateID.identifier(): authz.GetInstance(ctx).InstanceID(), diff --git a/internal/query/message_text.go b/internal/query/message_text.go index 7a49abf0a2..9fa7ffabdd 100644 --- a/internal/query/message_text.go +++ b/internal/query/message_text.go @@ -16,10 +16,10 @@ import ( "sigs.k8s.io/yaml" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type MessageTexts struct { @@ -122,7 +122,10 @@ var ( } ) -func (q *Queries) DefaultMessageText(ctx context.Context) (*MessageText, error) { +func (q *Queries) DefaultMessageText(ctx context.Context) (_ *MessageText, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareMessageTextQuery() query, args, err := stmt.Where(sq.Eq{ MessageTextColAggregateID.identifier(): authz.GetInstance(ctx).InstanceID(), @@ -137,7 +140,10 @@ func (q *Queries) DefaultMessageText(ctx context.Context) (*MessageText, error) return scan(row) } -func (q *Queries) DefaultMessageTextByTypeAndLanguageFromFileSystem(ctx context.Context, messageType, language string) (*MessageText, error) { +func (q *Queries) DefaultMessageTextByTypeAndLanguageFromFileSystem(ctx context.Context, messageType, language string) (_ *MessageText, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + contents, err := q.readNotificationTextMessages(ctx, language) if err != nil { return nil, err @@ -149,7 +155,10 @@ func (q *Queries) DefaultMessageTextByTypeAndLanguageFromFileSystem(ctx context. return messageTexts.GetMessageTextByType(messageType), nil } -func (q *Queries) CustomMessageTextByTypeAndLanguage(ctx context.Context, aggregateID, messageType, language string, withOwnerRemoved bool) (*MessageText, error) { +func (q *Queries) CustomMessageTextByTypeAndLanguage(ctx context.Context, aggregateID, messageType, language string, withOwnerRemoved bool) (_ *MessageText, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareMessageTextQuery() eq := sq.Eq{ MessageTextColLanguage.identifier(): language, @@ -174,7 +183,10 @@ func (q *Queries) CustomMessageTextByTypeAndLanguage(ctx context.Context, aggreg return msg, err } -func (q *Queries) IAMMessageTextByTypeAndLanguage(ctx context.Context, messageType, language string) (*MessageText, error) { +func (q *Queries) IAMMessageTextByTypeAndLanguage(ctx context.Context, messageType, language string) (_ *MessageText, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + contents, err := q.readNotificationTextMessages(ctx, language) if err != nil { return nil, err diff --git a/internal/query/notification_provider.go b/internal/query/notification_provider.go index 9a3b104309..2179629c25 100644 --- a/internal/query/notification_provider.go +++ b/internal/query/notification_provider.go @@ -9,10 +9,10 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type DebugNotificationProvider struct { @@ -69,7 +69,10 @@ var ( } ) -func (q *Queries) NotificationProviderByIDAndType(ctx context.Context, aggID string, providerType domain.NotificationProviderType) (*DebugNotificationProvider, error) { +func (q *Queries) NotificationProviderByIDAndType(ctx context.Context, aggID string, providerType domain.NotificationProviderType) (_ *DebugNotificationProvider, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareDebugNotificationProviderQuery() stmt, args, err := query.Where( sq.And{ diff --git a/internal/query/oidc_settings.go b/internal/query/oidc_settings.go index 59106a64c2..aaab9b1a58 100644 --- a/internal/query/oidc_settings.go +++ b/internal/query/oidc_settings.go @@ -11,6 +11,7 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -73,7 +74,10 @@ type OIDCSettings struct { RefreshTokenExpiration time.Duration } -func (q *Queries) OIDCSettingsByAggID(ctx context.Context, aggregateID string) (*OIDCSettings, error) { +func (q *Queries) OIDCSettingsByAggID(ctx context.Context, aggregateID string) (_ *OIDCSettings, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareOIDCSettingsQuery() query, args, err := stmt.Where(sq.Eq{ OIDCSettingsColumnAggregateID.identifier(): aggregateID, diff --git a/internal/query/org.go b/internal/query/org.go index c2e2255b19..4ddd71a023 100644 --- a/internal/query/org.go +++ b/internal/query/org.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -87,7 +88,10 @@ func (q *OrgSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuilder { return query } -func (q *Queries) OrgByID(ctx context.Context, shouldTriggerBulk bool, id string) (*Org, error) { +func (q *Queries) OrgByID(ctx context.Context, shouldTriggerBulk bool, id string) (_ *Org, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.OrgProjection.Trigger(ctx) } @@ -105,7 +109,10 @@ func (q *Queries) OrgByID(ctx context.Context, shouldTriggerBulk bool, id string return scan(row) } -func (q *Queries) OrgByPrimaryDomain(ctx context.Context, domain string) (*Org, error) { +func (q *Queries) OrgByPrimaryDomain(ctx context.Context, domain string) (_ *Org, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareOrgQuery() query, args, err := stmt.Where(sq.Eq{ OrgColumnDomain.identifier(): domain, @@ -119,7 +126,10 @@ func (q *Queries) OrgByPrimaryDomain(ctx context.Context, domain string) (*Org, return scan(row) } -func (q *Queries) OrgByVerifiedDomain(ctx context.Context, domain string) (*Org, error) { +func (q *Queries) OrgByVerifiedDomain(ctx context.Context, domain string) (_ *Org, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareOrgWithDomainsQuery() query, args, err := stmt.Where(sq.Eq{ OrgDomainDomainCol.identifier(): domain, @@ -135,6 +145,9 @@ func (q *Queries) OrgByVerifiedDomain(ctx context.Context, domain string) (*Org, } func (q *Queries) IsOrgUnique(ctx context.Context, name, domain string) (isUnique bool, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if name == "" && domain == "" { return false, errors.ThrowInvalidArgument(nil, "QUERY-DGqfd", "Errors.Query.InvalidRequest") } @@ -162,10 +175,17 @@ func (q *Queries) IsOrgUnique(ctx context.Context, name, domain string) (isUniqu } func (q *Queries) ExistsOrg(ctx context.Context, id string) (err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + _, err = q.OrgByID(ctx, true, id) return err } + func (q *Queries) SearchOrgs(ctx context.Context, queries *OrgSearchQueries) (orgs *Orgs, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareOrgsQuery() stmt, args, err := queries.toQuery(query). Where(sq.Eq{ diff --git a/internal/query/org_domain.go b/internal/query/org_domain.go index bdb1a345ad..e9ca4edaa5 100644 --- a/internal/query/org_domain.go +++ b/internal/query/org_domain.go @@ -11,6 +11,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type Domain struct { @@ -55,6 +56,9 @@ func NewOrgDomainVerifiedSearchQuery(verified bool) (SearchQuery, error) { } func (q *Queries) SearchOrgDomains(ctx context.Context, queries *OrgDomainSearchQueries, withOwnerRemoved bool) (domains *Domains, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareDomainsQuery() eq := sq.Eq{OrgDomainInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/org_member.go b/internal/query/org_member.go index e04232f6b9..c203f540c9 100644 --- a/internal/query/org_member.go +++ b/internal/query/org_member.go @@ -4,11 +4,12 @@ import ( "context" "database/sql" + sq "github.com/Masterminds/squirrel" + "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" - - sq "github.com/Masterminds/squirrel" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -75,7 +76,10 @@ func addOrgMemberWithoutOwnerRemoved(eq map[string]interface{}) { eq[OrgMemberOwnerRemovedUser.identifier()] = false } -func (q *Queries) OrgMembers(ctx context.Context, queries *OrgMembersQuery, withOwnerRemoved bool) (*Members, error) { +func (q *Queries) OrgMembers(ctx context.Context, queries *OrgMembersQuery, withOwnerRemoved bool) (_ *Members, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareOrgMembersQuery() eq := sq.Eq{OrgMemberInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/org_metadata.go b/internal/query/org_metadata.go index 4b0f20b0a2..77bb9e5739 100644 --- a/internal/query/org_metadata.go +++ b/internal/query/org_metadata.go @@ -11,6 +11,7 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type OrgMetadataList struct { @@ -75,7 +76,10 @@ var ( } ) -func (q *Queries) GetOrgMetadataByKey(ctx context.Context, shouldTriggerBulk bool, orgID string, key string, withOwnerRemoved bool, queries ...SearchQuery) (*OrgMetadata, error) { +func (q *Queries) GetOrgMetadataByKey(ctx context.Context, shouldTriggerBulk bool, orgID string, key string, withOwnerRemoved bool, queries ...SearchQuery) (_ *OrgMetadata, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.OrgMetadataProjection.Trigger(ctx) } @@ -101,7 +105,10 @@ func (q *Queries) GetOrgMetadataByKey(ctx context.Context, shouldTriggerBulk boo return scan(row) } -func (q *Queries) SearchOrgMetadata(ctx context.Context, shouldTriggerBulk bool, orgID string, queries *OrgMetadataSearchQueries, withOwnerRemoved bool) (*OrgMetadataList, error) { +func (q *Queries) SearchOrgMetadata(ctx context.Context, shouldTriggerBulk bool, orgID string, queries *OrgMetadataSearchQueries, withOwnerRemoved bool) (_ *OrgMetadataList, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.OrgMetadataProjection.Trigger(ctx) } diff --git a/internal/query/password_age_policy.go b/internal/query/password_age_policy.go index 60bb7e46af..522d761507 100644 --- a/internal/query/password_age_policy.go +++ b/internal/query/password_age_policy.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type PasswordAgePolicy struct { @@ -79,7 +80,10 @@ var ( } ) -func (q *Queries) PasswordAgePolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (*PasswordAgePolicy, error) { +func (q *Queries) PasswordAgePolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (_ *PasswordAgePolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.PasswordAgeProjection.Trigger(ctx) } @@ -106,7 +110,10 @@ func (q *Queries) PasswordAgePolicyByOrg(ctx context.Context, shouldTriggerBulk return scan(row) } -func (q *Queries) DefaultPasswordAgePolicy(ctx context.Context, shouldTriggerBulk bool) (*PasswordAgePolicy, error) { +func (q *Queries) DefaultPasswordAgePolicy(ctx context.Context, shouldTriggerBulk bool) (_ *PasswordAgePolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.PasswordAgeProjection.Trigger(ctx) } diff --git a/internal/query/password_complexity_policy.go b/internal/query/password_complexity_policy.go index 1af16092b3..e952332c08 100644 --- a/internal/query/password_complexity_policy.go +++ b/internal/query/password_complexity_policy.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type PasswordComplexityPolicy struct { @@ -31,7 +32,10 @@ type PasswordComplexityPolicy struct { IsDefault bool } -func (q *Queries) PasswordComplexityPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (*PasswordComplexityPolicy, error) { +func (q *Queries) PasswordComplexityPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (_ *PasswordComplexityPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.PasswordComplexityProjection.Trigger(ctx) } @@ -58,7 +62,10 @@ func (q *Queries) PasswordComplexityPolicyByOrg(ctx context.Context, shouldTrigg return scan(row) } -func (q *Queries) DefaultPasswordComplexityPolicy(ctx context.Context, shouldTriggerBulk bool) (*PasswordComplexityPolicy, error) { +func (q *Queries) DefaultPasswordComplexityPolicy(ctx context.Context, shouldTriggerBulk bool) (_ *PasswordComplexityPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.PasswordComplexityProjection.Trigger(ctx) } diff --git a/internal/query/privacy_policy.go b/internal/query/privacy_policy.go index 2d52f5a7ac..83be590f15 100644 --- a/internal/query/privacy_policy.go +++ b/internal/query/privacy_policy.go @@ -12,6 +12,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type PrivacyPolicy struct { @@ -84,7 +85,10 @@ var ( } ) -func (q *Queries) PrivacyPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (*PrivacyPolicy, error) { +func (q *Queries) PrivacyPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (_ *PrivacyPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.PrivacyPolicyProjection.Trigger(ctx) } @@ -110,7 +114,10 @@ func (q *Queries) PrivacyPolicyByOrg(ctx context.Context, shouldTriggerBulk bool return scan(row) } -func (q *Queries) DefaultPrivacyPolicy(ctx context.Context, shouldTriggerBulk bool) (*PrivacyPolicy, error) { +func (q *Queries) DefaultPrivacyPolicy(ctx context.Context, shouldTriggerBulk bool) (_ *PrivacyPolicy, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.PrivacyPolicyProjection.Trigger(ctx) } diff --git a/internal/query/project.go b/internal/query/project.go index 56e9bf0d64..b1a2749869 100644 --- a/internal/query/project.go +++ b/internal/query/project.go @@ -9,10 +9,10 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/query/projection" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" + "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -99,7 +99,10 @@ type ProjectSearchQueries struct { Queries []SearchQuery } -func (q *Queries) ProjectByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool) (*Project, error) { +func (q *Queries) ProjectByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool) (_ *Project, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.ProjectProjection.Trigger(ctx) } @@ -122,6 +125,9 @@ func (q *Queries) ProjectByID(ctx context.Context, shouldTriggerBulk bool, id st } func (q *Queries) SearchProjects(ctx context.Context, queries *ProjectSearchQueries, withOwnerRemoved bool) (projects *Projects, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareProjectsQuery() eq := sq.Eq{ProjectColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/project_grant.go b/internal/query/project_grant.go index 04f3558fa9..441b27b923 100644 --- a/internal/query/project_grant.go +++ b/internal/query/project_grant.go @@ -10,10 +10,10 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/database" - "github.com/zitadel/zitadel/internal/query/projection" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" + "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) const ( @@ -110,7 +110,10 @@ type ProjectGrantSearchQueries struct { Queries []SearchQuery } -func (q *Queries) ProjectGrantByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool) (*ProjectGrant, error) { +func (q *Queries) ProjectGrantByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool) (_ *ProjectGrant, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.ProjectGrantProjection.Trigger(ctx) } @@ -133,7 +136,10 @@ func (q *Queries) ProjectGrantByID(ctx context.Context, shouldTriggerBulk bool, return scan(row) } -func (q *Queries) ProjectGrantByIDAndGrantedOrg(ctx context.Context, id, grantedOrg string, withOwnerRemoved bool) (*ProjectGrant, error) { +func (q *Queries) ProjectGrantByIDAndGrantedOrg(ctx context.Context, id, grantedOrg string, withOwnerRemoved bool) (_ *ProjectGrant, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareProjectGrantQuery() eq := sq.Eq{ ProjectGrantColumnGrantID.identifier(): id, @@ -154,6 +160,9 @@ func (q *Queries) ProjectGrantByIDAndGrantedOrg(ctx context.Context, id, granted } func (q *Queries) SearchProjectGrants(ctx context.Context, queries *ProjectGrantSearchQueries, withOwnerRemoved bool) (projects *ProjectGrants, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareProjectGrantsQuery() eq := sq.Eq{ ProjectGrantColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(), @@ -180,6 +189,9 @@ func (q *Queries) SearchProjectGrants(ctx context.Context, queries *ProjectGrant } func (q *Queries) SearchProjectGrantsByProjectIDAndRoleKey(ctx context.Context, projectID, roleKey string, withOwnerRemoved bool) (projects *ProjectGrants, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + searchQuery := &ProjectGrantSearchQueries{ SearchRequest: SearchRequest{}, Queries: make([]SearchQuery, 2), diff --git a/internal/query/project_grant_member.go b/internal/query/project_grant_member.go index 6a43e298da..0397b045e3 100644 --- a/internal/query/project_grant_member.go +++ b/internal/query/project_grant_member.go @@ -7,7 +7,6 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" ) diff --git a/internal/query/project_member.go b/internal/query/project_member.go index 22ca200ade..4b80d9b594 100644 --- a/internal/query/project_member.go +++ b/internal/query/project_member.go @@ -7,9 +7,9 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -76,7 +76,10 @@ func addProjectMemberWithoutOwnerRemoved(eq map[string]interface{}) { eq[ProjectMemberOwnerRemovedUser.identifier()] = false } -func (q *Queries) ProjectMembers(ctx context.Context, queries *ProjectMembersQuery, withOwnerRemoved bool) (*Members, error) { +func (q *Queries) ProjectMembers(ctx context.Context, queries *ProjectMembersQuery, withOwnerRemoved bool) (_ *Members, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareProjectMembersQuery() eq := sq.Eq{ProjectMemberInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/project_role.go b/internal/query/project_role.go index a40fabd10c..4fe83a39c7 100644 --- a/internal/query/project_role.go +++ b/internal/query/project_role.go @@ -10,6 +10,7 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -82,6 +83,9 @@ type ProjectRoleSearchQueries struct { } func (q *Queries) SearchProjectRoles(ctx context.Context, shouldTriggerBulk bool, queries *ProjectRoleSearchQueries, withOwnerRemoved bool) (projects *ProjectRoles, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.ProjectRoleProjection.Trigger(ctx) } @@ -110,6 +114,9 @@ func (q *Queries) SearchProjectRoles(ctx context.Context, shouldTriggerBulk bool } func (q *Queries) SearchGrantedProjectRoles(ctx context.Context, grantID, grantedOrg string, queries *ProjectRoleSearchQueries, withOwnerRemoved bool) (projects *ProjectRoles, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + grant, err := q.ProjectGrantByIDAndGrantedOrg(ctx, grantID, grantedOrg, withOwnerRemoved) if err != nil { return nil, err diff --git a/internal/query/secret_generators.go b/internal/query/secret_generators.go index 35b36914ee..e5dc1b5378 100644 --- a/internal/query/secret_generators.go +++ b/internal/query/secret_generators.go @@ -9,12 +9,11 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/domain" - "github.com/zitadel/zitadel/internal/crypto" - "github.com/zitadel/zitadel/internal/query/projection" - + "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" + "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -134,7 +133,10 @@ func (q *Queries) InitHashGenerator(ctx context.Context, generatorType domain.Se return crypto.NewHashGenerator(cryptoConfig, algorithm), nil } -func (q *Queries) SecretGeneratorByType(ctx context.Context, generatorType domain.SecretGeneratorType) (*SecretGenerator, error) { +func (q *Queries) SecretGeneratorByType(ctx context.Context, generatorType domain.SecretGeneratorType) (_ *SecretGenerator, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareSecretGeneratorQuery() query, args, err := stmt.Where(sq.Eq{ SecretGeneratorColumnGeneratorType.identifier(): generatorType, @@ -149,6 +151,9 @@ func (q *Queries) SecretGeneratorByType(ctx context.Context, generatorType domai } func (q *Queries) SearchSecretGenerators(ctx context.Context, queries *SecretGeneratorSearchQueries) (secretGenerators *SecretGenerators, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareSecretGeneratorsQuery() stmt, args, err := queries.toQuery(query). Where(sq.Eq{ diff --git a/internal/query/sms.go b/internal/query/sms.go index 3111a732bb..40eb75576e 100644 --- a/internal/query/sms.go +++ b/internal/query/sms.go @@ -13,6 +13,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type SMSConfigs struct { @@ -113,7 +114,10 @@ var ( } ) -func (q *Queries) SMSProviderConfigByID(ctx context.Context, id string) (*SMSConfig, error) { +func (q *Queries) SMSProviderConfigByID(ctx context.Context, id string) (_ *SMSConfig, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareSMSConfigQuery() stmt, args, err := query.Where( sq.Eq{ @@ -129,7 +133,10 @@ func (q *Queries) SMSProviderConfigByID(ctx context.Context, id string) (*SMSCon return scan(row) } -func (q *Queries) SMSProviderConfig(ctx context.Context, queries ...SearchQuery) (*SMSConfig, error) { +func (q *Queries) SMSProviderConfig(ctx context.Context, queries ...SearchQuery) (_ *SMSConfig, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareSMSConfigQuery() for _, searchQuery := range queries { query = searchQuery.toQuery(query) @@ -147,7 +154,10 @@ func (q *Queries) SMSProviderConfig(ctx context.Context, queries ...SearchQuery) return scan(row) } -func (q *Queries) SearchSMSConfigs(ctx context.Context, queries *SMSConfigsSearchQueries) (*SMSConfigs, error) { +func (q *Queries) SearchSMSConfigs(ctx context.Context, queries *SMSConfigsSearchQueries) (_ *SMSConfigs, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareSMSConfigsQuery() stmt, args, err := queries.toQuery(query). Where(sq.Eq{ diff --git a/internal/query/smtp.go b/internal/query/smtp.go index bbd927a26f..f8614e8b86 100644 --- a/internal/query/smtp.go +++ b/internal/query/smtp.go @@ -9,11 +9,10 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/crypto" - "github.com/zitadel/zitadel/internal/query/projection" - "github.com/zitadel/zitadel/internal/errors" + "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -91,7 +90,10 @@ type SMTPConfig struct { Password *crypto.CryptoValue } -func (q *Queries) SMTPConfigByAggregateID(ctx context.Context, aggregateID string) (*SMTPConfig, error) { +func (q *Queries) SMTPConfigByAggregateID(ctx context.Context, aggregateID string) (_ *SMTPConfig, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + stmt, scan := prepareSMTPConfigQuery() query, args, err := stmt.Where(sq.Eq{ SMTPConfigColumnAggregateID.identifier(): aggregateID, diff --git a/internal/query/user.go b/internal/query/user.go index 2cd1828c89..7d722f14d4 100644 --- a/internal/query/user.go +++ b/internal/query/user.go @@ -14,6 +14,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type Users struct { @@ -316,7 +317,10 @@ func addUserWithoutOwnerRemoved(eq map[string]interface{}) { eq[userPreferredLoginNameOwnerRemovedDomainCol.identifier()] = false } -func (q *Queries) GetUserByID(ctx context.Context, shouldTriggerBulk bool, userID string, withOwnerRemoved bool, queries ...SearchQuery) (*User, error) { +func (q *Queries) GetUserByID(ctx context.Context, shouldTriggerBulk bool, userID string, withOwnerRemoved bool, queries ...SearchQuery) (_ *User, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.UserProjection.Trigger(ctx) projection.LoginNameProjection.Trigger(ctx) @@ -342,7 +346,10 @@ func (q *Queries) GetUserByID(ctx context.Context, shouldTriggerBulk bool, userI return scan(row) } -func (q *Queries) GetUser(ctx context.Context, shouldTriggerBulk bool, withOwnerRemoved bool, queries ...SearchQuery) (*User, error) { +func (q *Queries) GetUser(ctx context.Context, shouldTriggerBulk bool, withOwnerRemoved bool, queries ...SearchQuery) (_ *User, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.UserProjection.Trigger(ctx) projection.LoginNameProjection.Trigger(ctx) @@ -367,7 +374,10 @@ func (q *Queries) GetUser(ctx context.Context, shouldTriggerBulk bool, withOwner return scan(row) } -func (q *Queries) GetHumanProfile(ctx context.Context, userID string, withOwnerRemoved bool, queries ...SearchQuery) (*Profile, error) { +func (q *Queries) GetHumanProfile(ctx context.Context, userID string, withOwnerRemoved bool, queries ...SearchQuery) (_ *Profile, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareProfileQuery() for _, q := range queries { query = q.toQuery(query) @@ -388,7 +398,10 @@ func (q *Queries) GetHumanProfile(ctx context.Context, userID string, withOwnerR return scan(row) } -func (q *Queries) GetHumanEmail(ctx context.Context, userID string, withOwnerRemoved bool, queries ...SearchQuery) (*Email, error) { +func (q *Queries) GetHumanEmail(ctx context.Context, userID string, withOwnerRemoved bool, queries ...SearchQuery) (_ *Email, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareEmailQuery() for _, q := range queries { query = q.toQuery(query) @@ -409,7 +422,10 @@ func (q *Queries) GetHumanEmail(ctx context.Context, userID string, withOwnerRem return scan(row) } -func (q *Queries) GetHumanPhone(ctx context.Context, userID string, withOwnerRemoved bool, queries ...SearchQuery) (*Phone, error) { +func (q *Queries) GetHumanPhone(ctx context.Context, userID string, withOwnerRemoved bool, queries ...SearchQuery) (_ *Phone, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := preparePhoneQuery() for _, q := range queries { query = q.toQuery(query) @@ -430,7 +446,10 @@ func (q *Queries) GetHumanPhone(ctx context.Context, userID string, withOwnerRem return scan(row) } -func (q *Queries) GetNotifyUserByID(ctx context.Context, shouldTriggered bool, userID string, withOwnerRemoved bool, queries ...SearchQuery) (*NotifyUser, error) { +func (q *Queries) GetNotifyUserByID(ctx context.Context, shouldTriggered bool, userID string, withOwnerRemoved bool, queries ...SearchQuery) (_ *NotifyUser, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggered { projection.UserProjection.Trigger(ctx) projection.LoginNameProjection.Trigger(ctx) @@ -456,7 +475,10 @@ func (q *Queries) GetNotifyUserByID(ctx context.Context, shouldTriggered bool, u return scan(row) } -func (q *Queries) GetNotifyUser(ctx context.Context, shouldTriggered bool, withOwnerRemoved bool, queries ...SearchQuery) (*NotifyUser, error) { +func (q *Queries) GetNotifyUser(ctx context.Context, shouldTriggered bool, withOwnerRemoved bool, queries ...SearchQuery) (_ *NotifyUser, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggered { projection.UserProjection.Trigger(ctx) projection.LoginNameProjection.Trigger(ctx) @@ -481,7 +503,10 @@ func (q *Queries) GetNotifyUser(ctx context.Context, shouldTriggered bool, withO return scan(row) } -func (q *Queries) SearchUsers(ctx context.Context, queries *UserSearchQueries, withOwnerRemoved bool) (*Users, error) { +func (q *Queries) SearchUsers(ctx context.Context, queries *UserSearchQueries, withOwnerRemoved bool) (_ *Users, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareUsersQuery() eq := sq.Eq{UserInstanceIDCol.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { @@ -505,7 +530,10 @@ func (q *Queries) SearchUsers(ctx context.Context, queries *UserSearchQueries, w return users, err } -func (q *Queries) IsUserUnique(ctx context.Context, username, email, resourceOwner string, withOwnerRemoved bool) (bool, error) { +func (q *Queries) IsUserUnique(ctx context.Context, username, email, resourceOwner string, withOwnerRemoved bool) (_ bool, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareUserUniqueQuery() queries := make([]SearchQuery, 0, 3) if username != "" { diff --git a/internal/query/user_auth_method.go b/internal/query/user_auth_method.go index 9c97b5aa5c..3fca2a43e3 100644 --- a/internal/query/user_auth_method.go +++ b/internal/query/user_auth_method.go @@ -11,6 +11,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -87,6 +88,9 @@ type UserAuthMethodSearchQueries struct { } func (q *Queries) SearchUserAuthMethods(ctx context.Context, queries *UserAuthMethodSearchQueries, withOwnerRemoved bool) (userAuthMethods *AuthMethods, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareUserAuthMethodsQuery() eq := sq.Eq{UserAuthMethodColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/user_grant.go b/internal/query/user_grant.go index 9d806e36d0..9258388c7b 100644 --- a/internal/query/user_grant.go +++ b/internal/query/user_grant.go @@ -13,6 +13,7 @@ import ( "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type UserGrant struct { @@ -216,7 +217,10 @@ func addUserGrantWithoutOwnerRemoved(eq map[string]interface{}) { addLoginNameWithoutOwnerRemoved(eq) } -func (q *Queries) UserGrant(ctx context.Context, shouldTriggerBulk bool, withOwnerRemoved bool, queries ...SearchQuery) (*UserGrant, error) { +func (q *Queries) UserGrant(ctx context.Context, shouldTriggerBulk bool, withOwnerRemoved bool, queries ...SearchQuery) (_ *UserGrant, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.UserGrantProjection.Trigger(ctx) } @@ -238,7 +242,10 @@ func (q *Queries) UserGrant(ctx context.Context, shouldTriggerBulk bool, withOwn return scan(row) } -func (q *Queries) UserGrants(ctx context.Context, queries *UserGrantsQueries, withOwnerRemoved bool) (*UserGrants, error) { +func (q *Queries) UserGrants(ctx context.Context, queries *UserGrantsQueries, withOwnerRemoved bool) (_ *UserGrants, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := prepareUserGrantsQuery() eq := sq.Eq{UserGrantInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/user_membership.go b/internal/query/user_membership.go index 3620e95f8c..dfeeda9cc2 100644 --- a/internal/query/user_membership.go +++ b/internal/query/user_membership.go @@ -11,6 +11,7 @@ import ( "github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type Memberships struct { @@ -103,7 +104,10 @@ func (q *MembershipSearchQuery) toQuery(query sq.SelectBuilder) sq.SelectBuilder return query } -func (q *Queries) Memberships(ctx context.Context, queries *MembershipSearchQuery, withOwnerRemoved bool) (*Memberships, error) { +func (q *Queries) Memberships(ctx context.Context, queries *MembershipSearchQuery, withOwnerRemoved bool) (_ *Memberships, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, queryArgs, scan := prepareMembershipsQuery(withOwnerRemoved) eq := sq.Eq{membershipInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} stmt, args, err := queries.toQuery(query).Where(eq).ToSql() diff --git a/internal/query/user_metadata.go b/internal/query/user_metadata.go index 4dc5812511..20afb6fe89 100644 --- a/internal/query/user_metadata.go +++ b/internal/query/user_metadata.go @@ -9,9 +9,9 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/zitadel/zitadel/internal/api/authz" - "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type UserMetadataList struct { @@ -76,7 +76,10 @@ var ( } ) -func (q *Queries) GetUserMetadataByKey(ctx context.Context, shouldTriggerBulk bool, userID, key string, withOwnerRemoved bool, queries ...SearchQuery) (*UserMetadata, error) { +func (q *Queries) GetUserMetadataByKey(ctx context.Context, shouldTriggerBulk bool, userID, key string, withOwnerRemoved bool, queries ...SearchQuery) (_ *UserMetadata, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.UserMetadataProjection.Trigger(ctx) } @@ -102,7 +105,10 @@ func (q *Queries) GetUserMetadataByKey(ctx context.Context, shouldTriggerBulk bo return scan(row) } -func (q *Queries) SearchUserMetadata(ctx context.Context, shouldTriggerBulk bool, userID string, queries *UserMetadataSearchQueries, withOwnerRemoved bool) (*UserMetadataList, error) { +func (q *Queries) SearchUserMetadata(ctx context.Context, shouldTriggerBulk bool, userID string, queries *UserMetadataSearchQueries, withOwnerRemoved bool) (_ *UserMetadataList, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.UserMetadataProjection.Trigger(ctx) } diff --git a/internal/query/user_otp.go b/internal/query/user_otp.go index 9e1029a511..6d480610f8 100644 --- a/internal/query/user_otp.go +++ b/internal/query/user_otp.go @@ -2,24 +2,28 @@ package query import ( "context" + "github.com/zitadel/zitadel/internal/crypto" "github.com/zitadel/zitadel/internal/domain" - caos_errs "github.com/zitadel/zitadel/internal/errors" + "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/eventstore" "github.com/zitadel/zitadel/internal/repository/user" "github.com/zitadel/zitadel/internal/telemetry/tracing" ) -func (q *Queries) GetHumanOTPSecret(ctx context.Context, userID, resourceowner string) (string, error) { +func (q *Queries) GetHumanOTPSecret(ctx context.Context, userID, resourceowner string) (_ string, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if userID == "" { - return "", caos_errs.ThrowPreconditionFailed(nil, "QUERY-8N9ds", "Errors.User.UserIDMissing") + return "", errors.ThrowPreconditionFailed(nil, "QUERY-8N9ds", "Errors.User.UserIDMissing") } existingOTP, err := q.otpWriteModelByID(ctx, userID, resourceowner) if err != nil { return "", err } if existingOTP.State != domain.MFAStateReady { - return "", caos_errs.ThrowNotFound(nil, "QUERY-01982h", "Errors.User.NotFound") + return "", errors.ThrowNotFound(nil, "QUERY-01982h", "Errors.User.NotFound") } return crypto.DecryptString(existingOTP.Secret, q.multifactors.OTP.CryptoMFA) diff --git a/internal/query/user_password.go b/internal/query/user_password.go index 7fd48564bc..66cebb6148 100644 --- a/internal/query/user_password.go +++ b/internal/query/user_password.go @@ -2,13 +2,14 @@ package query import ( "context" + "time" + "github.com/zitadel/zitadel/internal/crypto" "github.com/zitadel/zitadel/internal/domain" - caos_errs "github.com/zitadel/zitadel/internal/errors" + "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/eventstore" "github.com/zitadel/zitadel/internal/repository/user" "github.com/zitadel/zitadel/internal/telemetry/tracing" - "time" ) type HumanPasswordWriteModel struct { @@ -26,15 +27,18 @@ type HumanPasswordWriteModel struct { } func (q *Queries) GetHumanPassword(ctx context.Context, orgID, userID string) (passwordHash []byte, algorithm string, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if userID == "" { - return nil, "", caos_errs.ThrowInvalidArgument(nil, "QUERY-4Mfsf", "Errors.User.UserIDMissing") + return nil, "", errors.ThrowInvalidArgument(nil, "QUERY-4Mfsf", "Errors.User.UserIDMissing") } existingPassword, err := q.passwordWriteModel(ctx, userID, orgID) if err != nil { - return nil, "", caos_errs.ThrowInternal(nil, "QUERY-p1k1n2i", "Errors.User.NotFound") + return nil, "", errors.ThrowInternal(nil, "QUERY-p1k1n2i", "Errors.User.NotFound") } if existingPassword.UserState == domain.UserStateUnspecified || existingPassword.UserState == domain.UserStateDeleted { - return nil, "", caos_errs.ThrowPreconditionFailed(nil, "QUERY-3n77z", "Errors.User.NotFound") + return nil, "", errors.ThrowPreconditionFailed(nil, "QUERY-3n77z", "Errors.User.NotFound") } if existingPassword.Secret != nil && existingPassword.Secret.Crypted != nil { diff --git a/internal/query/user_personal_access_token.go b/internal/query/user_personal_access_token.go index 9cff5a4368..b16d75a005 100644 --- a/internal/query/user_personal_access_token.go +++ b/internal/query/user_personal_access_token.go @@ -10,10 +10,9 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/database" - - "github.com/zitadel/zitadel/internal/query/projection" - "github.com/zitadel/zitadel/internal/errors" + "github.com/zitadel/zitadel/internal/query/projection" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) var ( @@ -85,7 +84,10 @@ type PersonalAccessTokenSearchQueries struct { Queries []SearchQuery } -func (q *Queries) PersonalAccessTokenByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool, queries ...SearchQuery) (*PersonalAccessToken, error) { +func (q *Queries) PersonalAccessTokenByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool, queries ...SearchQuery) (_ *PersonalAccessToken, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + if shouldTriggerBulk { projection.PersonalAccessTokenProjection.Trigger(ctx) } @@ -111,6 +113,9 @@ func (q *Queries) PersonalAccessTokenByID(ctx context.Context, shouldTriggerBulk } func (q *Queries) SearchPersonalAccessTokens(ctx context.Context, queries *PersonalAccessTokenSearchQueries, withOwnerRemoved bool) (personalAccessTokens *PersonalAccessTokens, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + query, scan := preparePersonalAccessTokensQuery() eq := sq.Eq{ PersonalAccessTokenColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(), diff --git a/internal/query/zitadel_permission.go b/internal/query/zitadel_permission.go index fdcde7bc13..b44ac4d85b 100644 --- a/internal/query/zitadel_permission.go +++ b/internal/query/zitadel_permission.go @@ -5,9 +5,13 @@ import ( "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/domain" + "github.com/zitadel/zitadel/internal/telemetry/tracing" ) -func (q *Queries) MyZitadelPermissions(ctx context.Context, orgID, userID string) (*domain.Permissions, error) { +func (q *Queries) MyZitadelPermissions(ctx context.Context, orgID, userID string) (_ *domain.Permissions, err error) { + ctx, span := tracing.NewSpan(ctx) + defer func() { span.EndWithError(err) }() + userIDQuery, err := NewMembershipUserIDQuery(userID) if err != nil { return nil, err