From 0187487f269fba710ee89954a2c6c0d537a5dd2d Mon Sep 17 00:00:00 2001 From: Silvan Date: Thu, 26 Oct 2023 17:07:56 +0200 Subject: [PATCH] chore: correct tracing of trigger function (#6825) * chore: correct tracing of trigger function * refactor: remove import --- internal/eventstore/handler/v2/handler.go | 7 ------- internal/query/app.go | 2 ++ internal/query/auth_request.go | 2 ++ internal/query/authn_key.go | 2 ++ internal/query/domain_policy.go | 2 ++ internal/query/idp.go | 2 ++ internal/query/idp_template.go | 2 ++ internal/query/instance.go | 2 ++ internal/query/lockout_policy.go | 2 ++ internal/query/login_policy.go | 2 ++ internal/query/notification_policy.go | 4 ++++ internal/query/org.go | 2 ++ internal/query/org_metadata.go | 4 ++++ internal/query/password_age_policy.go | 4 ++++ internal/query/password_complexity_policy.go | 4 ++++ internal/query/privacy_policy.go | 4 ++++ internal/query/project.go | 2 ++ internal/query/project_grant.go | 2 ++ internal/query/project_role.go | 2 ++ internal/query/session.go | 2 ++ internal/query/user.go | 4 ++++ internal/query/user_grant.go | 4 ++++ internal/query/user_metadata.go | 4 ++++ internal/query/user_personal_access_token.go | 2 ++ 24 files changed, 62 insertions(+), 7 deletions(-) diff --git a/internal/eventstore/handler/v2/handler.go b/internal/eventstore/handler/v2/handler.go index 0903dcca7b..c03d695dd8 100644 --- a/internal/eventstore/handler/v2/handler.go +++ b/internal/eventstore/handler/v2/handler.go @@ -15,7 +15,6 @@ import ( "github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/eventstore" "github.com/zitadel/zitadel/internal/repository/pseudo" - "github.com/zitadel/zitadel/internal/telemetry/tracing" ) type EventStore interface { @@ -234,12 +233,6 @@ func WithAwaitRunning() triggerOpt { } func (h *Handler) Trigger(ctx context.Context, opts ...triggerOpt) (_ context.Context, err error) { - if authz.GetInstance(ctx).InstanceID() != "" { - var span *tracing.Span - ctx, span = tracing.NewSpan(ctx) - defer func() { span.EndWithError(err) }() - } - config := new(triggerConfig) for _, opt := range opts { opt(config) diff --git a/internal/query/app.go b/internal/query/app.go index 48c05bd15c..5289785893 100644 --- a/internal/query/app.go +++ b/internal/query/app.go @@ -254,8 +254,10 @@ func (q *Queries) AppByProjectAndAppID(ctx context.Context, shouldTriggerBulk bo defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerAppProjection") ctx, err = projection.AppProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } stmt, scan := prepareAppQuery(ctx, q.client) diff --git a/internal/query/auth_request.go b/internal/query/auth_request.go index 2f20ec387a..71766b8990 100644 --- a/internal/query/auth_request.go +++ b/internal/query/auth_request.go @@ -53,8 +53,10 @@ func (q *Queries) AuthRequestByID(ctx context.Context, shouldTriggerBulk bool, i defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerAuthRequestProjection") ctx, err = projection.AuthRequestProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } var ( diff --git a/internal/query/authn_key.go b/internal/query/authn_key.go index 2022a94ce9..a9ef61e0b9 100644 --- a/internal/query/authn_key.go +++ b/internal/query/authn_key.go @@ -193,8 +193,10 @@ func (q *Queries) GetAuthNKeyByID(ctx context.Context, shouldTriggerBulk bool, i defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerAuthNKeyProjection") ctx, err = projection.AuthNKeyProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } query, scan := prepareAuthNKeyQuery(ctx, q.client) diff --git a/internal/query/domain_policy.go b/internal/query/domain_policy.go index 59e75b9aae..bbe79a9daf 100644 --- a/internal/query/domain_policy.go +++ b/internal/query/domain_policy.go @@ -94,8 +94,10 @@ func (q *Queries) DomainPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerDomainPolicyProjection") ctx, err = projection.DomainPolicyProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.And{ sq.Eq{DomainPolicyColInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()}, diff --git a/internal/query/idp.go b/internal/query/idp.go index 90783c45db..6dc4d4783b 100644 --- a/internal/query/idp.go +++ b/internal/query/idp.go @@ -196,8 +196,10 @@ func (q *Queries) IDPByIDAndResourceOwner(ctx context.Context, shouldTriggerBulk defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerIDPProjection") ctx, err = projection.IDPProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.Eq{ diff --git a/internal/query/idp_template.go b/internal/query/idp_template.go index e8abb0d7af..39e68b8870 100644 --- a/internal/query/idp_template.go +++ b/internal/query/idp_template.go @@ -704,8 +704,10 @@ func (q *Queries) IDPTemplateByID(ctx context.Context, shouldTriggerBulk bool, i defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerIDPTemplateProjection") ctx, err = projection.IDPTemplateProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("unable to trigger") + traceSpan.EndWithError(err) } eq := sq.Eq{ diff --git a/internal/query/instance.go b/internal/query/instance.go index c80ae9085b..8a683d7f26 100644 --- a/internal/query/instance.go +++ b/internal/query/instance.go @@ -192,8 +192,10 @@ func (q *Queries) Instance(ctx context.Context, shouldTriggerBulk bool) (instanc defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerInstanceProjection") ctx, err = projection.InstanceProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } stmt, scan := prepareInstanceDomainQuery(ctx, q.client, authz.GetInstance(ctx).RequestedDomain()) diff --git a/internal/query/lockout_policy.go b/internal/query/lockout_policy.go index e993162577..d568427b24 100644 --- a/internal/query/lockout_policy.go +++ b/internal/query/lockout_policy.go @@ -89,8 +89,10 @@ func (q *Queries) LockoutPolicyByOrg(ctx context.Context, shouldTriggerBulk bool defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerLockoutPolicyProjection") ctx, err = projection.LockoutPolicyProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.Eq{ LockoutColInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(), diff --git a/internal/query/login_policy.go b/internal/query/login_policy.go index 1968f2f063..fc4b12bf4b 100644 --- a/internal/query/login_policy.go +++ b/internal/query/login_policy.go @@ -174,8 +174,10 @@ func (q *Queries) LoginPolicyByID(ctx context.Context, shouldTriggerBulk bool, o defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerLoginPolicyProjection") ctx, err = projection.LoginPolicyProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.Eq{LoginPolicyColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { diff --git a/internal/query/notification_policy.go b/internal/query/notification_policy.go index cd637ca592..ba0b2c549e 100644 --- a/internal/query/notification_policy.go +++ b/internal/query/notification_policy.go @@ -82,7 +82,9 @@ func (q *Queries) NotificationPolicyByOrg(ctx context.Context, shouldTriggerBulk defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerNotificationPolicyProjection") ctx, err = projection.NotificationPolicyProjection.Trigger(ctx, handler.WithAwaitRunning()) + traceSpan.EndWithError(err) if err != nil { return nil, err } @@ -117,7 +119,9 @@ func (q *Queries) DefaultNotificationPolicy(ctx context.Context, shouldTriggerBu defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerNotificationPolicyProjection") ctx, err = projection.NotificationPolicyProjection.Trigger(ctx, handler.WithAwaitRunning()) + traceSpan.EndWithError(err) if err != nil { return nil, err } diff --git a/internal/query/org.go b/internal/query/org.go index bd5a36d2ef..fcc53e6a08 100644 --- a/internal/query/org.go +++ b/internal/query/org.go @@ -97,8 +97,10 @@ func (q *Queries) OrgByID(ctx context.Context, shouldTriggerBulk bool, id string defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerOrgProjection") ctx, err = projection.OrgProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } stmt, scan := prepareOrgQuery(ctx, q.client) diff --git a/internal/query/org_metadata.go b/internal/query/org_metadata.go index 2d0311a90f..d0c0e04c11 100644 --- a/internal/query/org_metadata.go +++ b/internal/query/org_metadata.go @@ -85,8 +85,10 @@ func (q *Queries) GetOrgMetadataByKey(ctx context.Context, shouldTriggerBulk boo defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerOrgMetadataProjection") ctx, err = projection.OrgMetadataProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } query, scan := prepareOrgMetadataQuery(ctx, q.client) @@ -118,8 +120,10 @@ func (q *Queries) SearchOrgMetadata(ctx context.Context, shouldTriggerBulk bool, defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerOrgMetadataProjection") ctx, err = projection.OrgMetadataProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.Eq{ OrgMetadataOrgIDCol.identifier(): orgID, diff --git a/internal/query/password_age_policy.go b/internal/query/password_age_policy.go index 16104967c7..dd22ed7156 100644 --- a/internal/query/password_age_policy.go +++ b/internal/query/password_age_policy.go @@ -89,8 +89,10 @@ func (q *Queries) PasswordAgePolicyByOrg(ctx context.Context, shouldTriggerBulk defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerPasswordAgeProjection") ctx, err = projection.PasswordAgeProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.Eq{PasswordAgeColInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { @@ -123,8 +125,10 @@ func (q *Queries) DefaultPasswordAgePolicy(ctx context.Context, shouldTriggerBul defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerPasswordAgeProjection") ctx, err = projection.PasswordAgeProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } stmt, scan := preparePasswordAgePolicyQuery(ctx, q.client) diff --git a/internal/query/password_complexity_policy.go b/internal/query/password_complexity_policy.go index 4e1942038d..c72361f723 100644 --- a/internal/query/password_complexity_policy.go +++ b/internal/query/password_complexity_policy.go @@ -41,8 +41,10 @@ func (q *Queries) PasswordComplexityPolicyByOrg(ctx context.Context, shouldTrigg defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerPasswordComplexityProjection") ctx, err = projection.PasswordComplexityProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.Eq{PasswordComplexityColInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { @@ -75,8 +77,10 @@ func (q *Queries) DefaultPasswordComplexityPolicy(ctx context.Context, shouldTri defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerPasswordComplexityProjection") ctx, err = projection.PasswordComplexityProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } stmt, scan := preparePasswordComplexityPolicyQuery(ctx, q.client) diff --git a/internal/query/privacy_policy.go b/internal/query/privacy_policy.go index f37884ca17..1a08cfb020 100644 --- a/internal/query/privacy_policy.go +++ b/internal/query/privacy_policy.go @@ -99,8 +99,10 @@ func (q *Queries) PrivacyPolicyByOrg(ctx context.Context, shouldTriggerBulk bool defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerPrivacyPolicyProjection") ctx, err = projection.PrivacyPolicyProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.Eq{PrivacyColInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} if !withOwnerRemoved { @@ -132,8 +134,10 @@ func (q *Queries) DefaultPrivacyPolicy(ctx context.Context, shouldTriggerBulk bo defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerPrivacyPolicyProjection") ctx, err = projection.PrivacyPolicyProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } stmt, scan := preparePrivacyPolicyQuery(ctx, q.client) diff --git a/internal/query/project.go b/internal/query/project.go index 9c63016844..b999d22f17 100644 --- a/internal/query/project.go +++ b/internal/query/project.go @@ -108,8 +108,10 @@ func (q *Queries) ProjectByID(ctx context.Context, shouldTriggerBulk bool, id st defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerProjectProjection") ctx, err = projection.ProjectProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } stmt, scan := prepareProjectQuery(ctx, q.client) diff --git a/internal/query/project_grant.go b/internal/query/project_grant.go index 229d3b320e..bcd6592cda 100644 --- a/internal/query/project_grant.go +++ b/internal/query/project_grant.go @@ -119,8 +119,10 @@ func (q *Queries) ProjectGrantByID(ctx context.Context, shouldTriggerBulk bool, defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerProjectGrantProjection") ctx, err = projection.ProjectGrantProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } stmt, scan := prepareProjectGrantQuery(ctx, q.client) diff --git a/internal/query/project_role.go b/internal/query/project_role.go index c141ed9183..3549753141 100644 --- a/internal/query/project_role.go +++ b/internal/query/project_role.go @@ -91,8 +91,10 @@ func (q *Queries) SearchProjectRoles(ctx context.Context, shouldTriggerBulk bool defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerProjectRoleProjection") ctx, err = projection.ProjectRoleProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } eq := sq.Eq{ProjectRoleColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()} diff --git a/internal/query/session.go b/internal/query/session.go index c2921d235d..9f5bd15cd5 100644 --- a/internal/query/session.go +++ b/internal/query/session.go @@ -192,8 +192,10 @@ func (q *Queries) SessionByID(ctx context.Context, shouldTriggerBulk bool, id, s defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerSessionProjection") ctx, err = projection.SessionProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("unable to trigger") + traceSpan.EndWithError(err) } query, scan := prepareSessionQuery(ctx, q.client) diff --git a/internal/query/user.go b/internal/query/user.go index ea71a7d477..2bd2c6bccd 100644 --- a/internal/query/user.go +++ b/internal/query/user.go @@ -721,12 +721,16 @@ func triggerUserProjections(ctx context.Context) { wg := sync.WaitGroup{} wg.Add(2) func() { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerUserProjection") _, err := projection.UserProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) wg.Done() }() func() { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerLoginNameProjection") _, err := projection.LoginNameProjection.Trigger(ctx, handler.WithAwaitRunning()) + traceSpan.EndWithError(err) logging.OnError(err).Debug("trigger failed") wg.Done() }() diff --git a/internal/query/user_grant.go b/internal/query/user_grant.go index da36b0ef8c..026afbeb5e 100644 --- a/internal/query/user_grant.go +++ b/internal/query/user_grant.go @@ -240,8 +240,10 @@ func (q *Queries) UserGrant(ctx context.Context, shouldTriggerBulk bool, withOwn defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerUserGrantProjection") ctx, err = projection.UserGrantProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } query, scan := prepareUserGrantQuery(ctx, q.client) @@ -269,8 +271,10 @@ func (q *Queries) UserGrants(ctx context.Context, queries *UserGrantsQueries, sh defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerUserGrantProjection") ctx, err = projection.UserGrantProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("unable to trigger") + traceSpan.EndWithError(err) } query, scan := prepareUserGrantsQuery(ctx, q.client) diff --git a/internal/query/user_metadata.go b/internal/query/user_metadata.go index 6ee99735dd..7322b20920 100644 --- a/internal/query/user_metadata.go +++ b/internal/query/user_metadata.go @@ -85,8 +85,10 @@ func (q *Queries) GetUserMetadataByKey(ctx context.Context, shouldTriggerBulk bo defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerUserMetadataProjection") ctx, err = projection.UserMetadataProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } query, scan := prepareUserMetadataQuery(ctx, q.client) @@ -118,8 +120,10 @@ func (q *Queries) SearchUserMetadata(ctx context.Context, shouldTriggerBulk bool defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerUserMetadataProjection") ctx, err = projection.UserMetadataProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } query, scan := prepareUserMetadataListQuery(ctx, q.client) diff --git a/internal/query/user_personal_access_token.go b/internal/query/user_personal_access_token.go index e0a1fc90e8..17726a06ad 100644 --- a/internal/query/user_personal_access_token.go +++ b/internal/query/user_personal_access_token.go @@ -93,8 +93,10 @@ func (q *Queries) PersonalAccessTokenByID(ctx context.Context, shouldTriggerBulk defer func() { span.EndWithError(err) }() if shouldTriggerBulk { + _, traceSpan := tracing.NewNamedSpan(ctx, "TriggerPersonalAccessTokenProjection") ctx, err = projection.PersonalAccessTokenProjection.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).Debug("trigger failed") + traceSpan.EndWithError(err) } query, scan := preparePersonalAccessTokenQuery(ctx, q.client)