From 5fc6ef592f1592e906bce640c7e561bae01e0774 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 10 Mar 2026 11:27:20 +0300 Subject: [PATCH] api/handler: document request ID size Signed-off-by: NotAShelf Change-Id: Ia4c92c2e7f3a4d68252a41cf9bc5c9c86a6a6964 --- internal/api/handler.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/api/handler.go b/internal/api/handler.go index aa8aeba..ff068da 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -341,8 +341,12 @@ func (h *IngestionHandler) classifyDevice(width int, userAgent string) string { return "unknown" } -// generateRequestID creates a unique request ID for tracing +// Creates a unique request ID for tracing. +// Uses 8 bytes (64 bits) of randomness which produces 16 hex characters. +// 2^64 possible IDs (~18 quintillion) provides sufficient uniqueness for +// request tracing while keeping IDs reasonably short in logs and headers. func generateRequestID() string { + // 8 bytes = 64 bits = 16 hex chars = 2^64 possible IDs b := make([]byte, 8) if _, err := rand.Read(b); err != nil { // Fallback to timestamp if crypto/rand fails