From 1575c7fe468771b7e6aa0df8922581a310f41cad Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 20 Dec 2024 13:26:33 -0500 Subject: [PATCH] Add additional tracing to relationship querying --- internal/datastore/common/relationships.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/datastore/common/relationships.go b/internal/datastore/common/relationships.go index f780dca876..a8f09569a9 100644 --- a/internal/datastore/common/relationships.go +++ b/internal/datastore/common/relationships.go @@ -62,14 +62,18 @@ func QueryRelationships[R Rows, C ~map[string]any](ctx context.Context, builder var integrityHash []byte var timestamp time.Time + span.AddEvent("Selecting columns") colsToSelect, err := ColumnsToSelect(builder, &resourceObjectType, &resourceObjectID, &resourceRelation, &subjectObjectType, &subjectObjectID, &subjectRelation, &caveatName, &caveatCtx, &expiration, &integrityKeyID, &integrityHash, ×tamp) if err != nil { return nil, fmt.Errorf(errUnableToQueryRels, err) } + span.AddEvent("Returning iterator", trace.WithAttributes(attribute.Int("column-count", len(colsToSelect)))) return func(yield func(tuple.Relationship, error) bool) { + span.AddEvent("Issuing query to database") err := tx.QueryFunc(ctx, func(ctx context.Context, rows R) error { span.AddEvent("Query issued to database") + var r Rows = rows if crwe, ok := r.(closeRowsWithError); ok { defer LogOnError(ctx, crwe.Close) @@ -87,6 +91,10 @@ func QueryRelationships[R Rows, C ~map[string]any](ctx context.Context, builder return fmt.Errorf(errUnableToQueryRels, fmt.Errorf("scan err: %w", err)) } + if relCount == 0 { + span.AddEvent("First row scanned") + } + var caveat *corev1.ContextualizedCaveat if !builder.SkipCaveats || builder.Schema.ColumnOptimization == ColumnOptimizationOptionNone { if caveatName.Valid { @@ -136,7 +144,7 @@ func QueryRelationships[R Rows, C ~map[string]any](ctx context.Context, builder } } - span.AddEvent("Rels loaded", trace.WithAttributes(attribute.Int("relCount", relCount))) + span.AddEvent("Relationships loaded", trace.WithAttributes(attribute.Int("relCount", relCount))) if err := rows.Err(); err != nil { return fmt.Errorf(errUnableToQueryRels, fmt.Errorf("rows err: %w", err)) }