From a4c65684e9dca3516fcb9d96a13762d048c4c03c Mon Sep 17 00:00:00 2001 From: Vishal Raj Date: Tue, 26 May 2026 18:35:02 +0100 Subject: [PATCH] [receiver/elasticapm]Fix benchmarks to produce correct IDs --- .../receiver_bench_test.go | 33 ++++++++++++------- .../resource_grouping.go | 7 ++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/receiver/elasticapmintakereceiver/receiver_bench_test.go b/receiver/elasticapmintakereceiver/receiver_bench_test.go index d29dd028c..57c15a794 100644 --- a/receiver/elasticapmintakereceiver/receiver_bench_test.go +++ b/receiver/elasticapmintakereceiver/receiver_bench_test.go @@ -301,29 +301,38 @@ func generateMixedPayload(n int) []byte { for r := range repeat { base := uint64(r * 20) for i := range 8 { + txSeq := base + uint64(i) + 1 + txID := fmt.Sprintf("%016x", txSeq) + traceID := fmt.Sprintf("%032x", txSeq) fmt.Fprintf(&buf, `{"transaction": {"id": %q, "trace_id": %q, "name": "tx", "type": "request", "duration": 1, "timestamp": %d, "outcome": "success", "sampled": true, "span_count": {"started": 1}}}`+"\n", - fmt.Sprintf("tx%014x", base+uint64(i)), - fmt.Sprintf("tx%014xtx%014x", base+uint64(i), base+uint64(i)), - 1_000_000+(base+uint64(i))*1_000, + txID, + traceID, + 1_000_000+txSeq*1_000, ) } for i := range 8 { + txSeq := base + uint64(i) + 1 + spanSeq := base + uint64(i) + 0x1001 + txID := fmt.Sprintf("%016x", txSeq) fmt.Fprintf(&buf, `{"span": {"id": %q, "trace_id": %q, "transaction_id": %q, "parent_id": %q, "name": "SELECT *", "type": "db.postgresql.query", "start": 1, "duration": 2, "timestamp": %d}}`+"\n", - fmt.Sprintf("sp%014x", base+uint64(i)), - fmt.Sprintf("tx%014xtx%014x", base+uint64(i), base+uint64(i)), - fmt.Sprintf("tx%014x", base+uint64(i)), - fmt.Sprintf("tx%014x", base+uint64(i)), - 1_000_000+(base+uint64(i))*1_000+1, + fmt.Sprintf("%016x", spanSeq), + fmt.Sprintf("%032x", txSeq), + txID, + txID, + 1_000_000+txSeq*1_000+1, ) } + errSeq := base + 0x2001 + errTxSeq := base + 1 + errTxID := fmt.Sprintf("%016x", errTxSeq) fmt.Fprintf(&buf, `{"error": {"id": %q, "trace_id": %q, "transaction_id": %q, "parent_id": %q, "timestamp": %d, "log": {"message": "boom"}}}`+"\n", - fmt.Sprintf("er%014x", base), - fmt.Sprintf("tx%014xtx%014x", base, base), - fmt.Sprintf("tx%014x", base), - fmt.Sprintf("tx%014x", base), + fmt.Sprintf("%032x", errSeq), + fmt.Sprintf("%032x", errTxSeq), + errTxID, + errTxID, 1_000_000+base*1_000+2, ) fmt.Fprintf(&buf, diff --git a/receiver/elasticapmintakereceiver/resource_grouping.go b/receiver/elasticapmintakereceiver/resource_grouping.go index 2513fdb12..5fd17e3e4 100644 --- a/receiver/elasticapmintakereceiver/resource_grouping.go +++ b/receiver/elasticapmintakereceiver/resource_grouping.go @@ -87,9 +87,10 @@ func (g *signalGroups) recordLogScope(fp uint64, sl plog.ScopeLogs) { // fpKVSep separates a key from a value within a single attribute write. // fpEntrySep separates one attribute write from the next. // -// Including the key in the hash makes write order irrelevant for fields -// the visitor sees as Put*(key, value) — re-ordering the walker visits -// would produce the same fingerprint for the same set of attributes. +// Including the key prevents ambiguity between different key/value +// sequences, but the fingerprint still depends on write order because the +// hasher consumes a sequential byte stream. This therefore relies on +// WalkResourceAttributes visiting attributes in deterministic order. var ( fpKVSep = []byte{0x00} fpEntrySep = []byte{0x01}