Conversation
This attribute is standardize and setting it with a string messes with signoz. Signed-off-by: Sylvain Rabot <sylvain@formance.com>
WalkthroughImport section reordered with collection utilities and features repositioned. InsertTransaction method's tracing attributes updated: ID attribute changed from Int to String type with "transaction." prefix, timestamp attribute renamed with prefix, and new transaction.reference attribute added. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@internal/storage/ledger/transactions.go`:
- Around line 158-160: The trace is currently logging the pointer address
because attribute.String("transaction.id", fmt.Sprint(tx.ID)) is stringifying a
pointer; in the code around where transaction attributes are set (look for
attribute.String calls in transactions.go that reference tx.ID and
tx.Timestamp), dereference tx.ID before converting to string and guard for nil
(e.g., if tx.ID == nil use a fallback like "nil" or empty string), so the
attribute records the numeric ID value rather than the pointer address.
| attribute.String("transaction.id", fmt.Sprint(tx.ID)), | ||
| attribute.String("transaction.timestamp", tx.Timestamp.Format(time.RFC3339Nano)), | ||
| attribute.String("transaction.reference", tx.Reference), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find the Transaction struct definition in the ledger package
rg -nP --type=go 'type\s+Transaction\s+struct' internal/storage/ledger/Repository: formancehq/ledger
Length of output: 43
🏁 Script executed:
#!/bin/bash
# Once we find the struct, let's inspect its fields
# First, find the transactions.go file and look at the struct
fd 'transactions\.go$' --type f | head -5Repository: formancehq/ledger
Length of output: 285
🏁 Script executed:
#!/bin/bash
# Search for the Transaction struct definition more broadly
ast-grep --pattern 'type Transaction struct { $$$ }'Repository: formancehq/ledger
Length of output: 2666
🏁 Script executed:
#!/bin/bash
# Read the transactions.go file around lines 158-160
cat -n internal/storage/ledger/transactions.go | sed -n '150,170p'Repository: formancehq/ledger
Length of output: 959
🏁 Script executed:
#!/bin/bash
# Let's also look for the transaction struct definition in the ledger package specifically
cat -n internal/storage/ledger/transactions.go | head -100Repository: formancehq/ledger
Length of output: 3819
Fix transaction.id to avoid pointer addresses in traces.
fmt.Sprint(tx.ID) stringifies the pointer (e.g., 0xc000...) rather than the numeric ID. Dereference (and guard nil if necessary) before setting the attribute.
🔧 Proposed fix
- trace.SpanFromContext(ctx).SetAttributes(
- attribute.String("transaction.id", fmt.Sprint(tx.ID)),
+ id := ""
+ if tx.ID != nil {
+ id = fmt.Sprint(*tx.ID)
+ }
+ trace.SpanFromContext(ctx).SetAttributes(
+ attribute.String("transaction.id", id),
attribute.String("transaction.timestamp", tx.Timestamp.Format(time.RFC3339Nano)),
attribute.String("transaction.reference", tx.Reference),
)🤖 Prompt for AI Agents
In `@internal/storage/ledger/transactions.go` around lines 158 - 160, The trace is
currently logging the pointer address because attribute.String("transaction.id",
fmt.Sprint(tx.ID)) is stringifying a pointer; in the code around where
transaction attributes are set (look for attribute.String calls in
transactions.go that reference tx.ID and tx.Timestamp), dereference tx.ID before
converting to string and guard for nil (e.g., if tx.ID == nil use a fallback
like "nil" or empty string), so the attribute records the numeric ID value
rather than the pointer address.
There was a problem hiding this comment.
Good point from coderabbit no ?
There was a problem hiding this comment.
@paul-nicolas Yes, absolutely! CodeRabbit caught a real bug here.
The issue is that tx.ID is a pointer (*int), and fmt.Sprint(tx.ID) will convert the pointer address to a string (like "0xc0001234567"), not the actual ID value.
The original code had attribute.Int("id", *tx.ID) which correctly dereferenced the pointer with *tx.ID. The new code fmt.Sprint(tx.ID) is missing that dereference operator.
The fix should be:
attribute.String("transaction.id", fmt.Sprint(*tx.ID))Since this callback executes after the database insert with Returning("id, ..."), the tx.ID should always be populated at this point, so a nil check may not be strictly necessary. However, CodeRabbit's suggested defensive nil guard is still good practice for robustness.
This attribute is standardize and setting it with a string messes with signoz.