Skip to content

Commit 1f72a95

Browse files
committed
Add more spans
1 parent 891f355 commit 1f72a95

File tree

9 files changed

+232
-3
lines changed

9 files changed

+232
-3
lines changed

backend/internal/graph/api/quizzes.resolvers.go

Lines changed: 116 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/internal/loaders/quiz_answers_by_question.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import (
66
"github.com/bcc-media/wayfarer/internal/cache"
77
"github.com/bcc-media/wayfarer/internal/database"
88
"github.com/bcc-media/wayfarer/internal/graph/api/model"
9+
"github.com/bcc-media/wayfarer/internal/otel"
910
"github.com/graph-gophers/dataloader/v7"
1011
)
1112

1213
// quizAnswersByQuestionBatchFunc batches loading predefined answers by question IDs
1314
func quizAnswersByQuestionBatchFunc(db *database.DB, c *cache.CacheWithRegistry) func(context.Context, []string) []*dataloader.Result[[]*model.QuizPredefinedAnswer] {
1415
return func(ctx context.Context, questionIDs []string) []*dataloader.Result[[]*model.QuizPredefinedAnswer] {
16+
ctx, span := otel.StartDataloaderSpan(ctx, "QuizAnswersByQuestion", len(questionIDs))
17+
defer span.End()
18+
1519
// Check cache first for each question ID
1620
answersMap := make(map[string][]*model.QuizPredefinedAnswer)
1721
missingIDs := []string{}
@@ -27,6 +31,9 @@ func quizAnswersByQuestionBatchFunc(db *database.DB, c *cache.CacheWithRegistry)
2731
missingIDs = append(missingIDs, questionID)
2832
}
2933

34+
// Record cache statistics
35+
otel.RecordCacheHitMiss(span, len(questionIDs)-len(missingIDs), len(missingIDs))
36+
3037
// Query database only for cache misses
3138
if len(missingIDs) > 0 {
3239
rows, err := db.Queries.GetPredefinedAnswersByQuestionIDs(ctx, missingIDs)

0 commit comments

Comments
 (0)