Skip to content

Commit 4d1d3ff

Browse files
committed
chore: adding hex encoded namespace
1 parent d3bdb1e commit 4d1d3ff

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

block/internal/da/tracing.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package da
22

33
import (
44
"context"
5+
"encoding/hex"
56

67
"go.opentelemetry.io/otel"
78
"go.opentelemetry.io/otel/attribute"
@@ -31,7 +32,7 @@ func (t *tracedClient) Submit(ctx context.Context, data [][]byte, gasPrice float
3132
trace.WithAttributes(
3233
attribute.Int("blob.count", len(data)),
3334
attribute.Int("blob.total_size_bytes", total),
34-
attribute.String("da.namespace", string(namespace)),
35+
attribute.String("da.namespace", hex.EncodeToString(namespace)),
3536
),
3637
)
3738
defer span.End()
@@ -50,7 +51,7 @@ func (t *tracedClient) Retrieve(ctx context.Context, height uint64, namespace []
5051
ctx, span := t.tracer.Start(ctx, "DA.Retrieve",
5152
trace.WithAttributes(
5253
attribute.Int("ns.length", len(namespace)),
53-
attribute.String("da.namespace", string(namespace)),
54+
attribute.String("da.namespace", hex.EncodeToString(namespace)),
5455
),
5556
)
5657
defer span.End()
@@ -70,7 +71,7 @@ func (t *tracedClient) Get(ctx context.Context, ids []datypes.ID, namespace []by
7071
ctx, span := t.tracer.Start(ctx, "DA.Get",
7172
trace.WithAttributes(
7273
attribute.Int("id.count", len(ids)),
73-
attribute.String("da.namespace", string(namespace)),
74+
attribute.String("da.namespace", hex.EncodeToString(namespace)),
7475
),
7576
)
7677
defer span.End()
@@ -89,7 +90,7 @@ func (t *tracedClient) GetProofs(ctx context.Context, ids []datypes.ID, namespac
8990
ctx, span := t.tracer.Start(ctx, "DA.GetProofs",
9091
trace.WithAttributes(
9192
attribute.Int("id.count", len(ids)),
92-
attribute.String("da.namespace", string(namespace)),
93+
attribute.String("da.namespace", hex.EncodeToString(namespace)),
9394
),
9495
)
9596
defer span.End()
@@ -108,7 +109,7 @@ func (t *tracedClient) Validate(ctx context.Context, ids []datypes.ID, proofs []
108109
ctx, span := t.tracer.Start(ctx, "DA.Validate",
109110
trace.WithAttributes(
110111
attribute.Int("id.count", len(ids)),
111-
attribute.String("da.namespace", string(namespace)),
112+
attribute.String("da.namespace", hex.EncodeToString(namespace)),
112113
),
113114
)
114115
defer span.End()

block/internal/da/tracing_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,22 @@ func TestTracedDA_Submit_Success(t *testing.T) {
8383
spans := sr.Ended()
8484
require.Len(t, spans, 1)
8585
span := spans[0]
86-
require.Equal(t, "DA.Submit", span.Name())
86+
require.Equal(t, "DA.Submit", span.Name())
8787
require.Equal(t, codes.Unset, span.Status().Code)
8888

89-
attrs := span.Attributes()
90-
requireAttribute(t, attrs, "blob.count", 2)
91-
requireAttribute(t, attrs, "blob.total_size_bytes", 3)
92-
// namespace length assertion for local behavior
93-
// look for da.namespace and assert byte-length
94-
foundNS := false
95-
for _, a := range attrs {
96-
if string(a.Key) == "da.namespace" {
97-
foundNS = true
98-
require.Equal(t, 2, len(a.Value.AsString()))
99-
}
100-
}
101-
require.True(t, foundNS, "attribute da.namespace not found")
89+
attrs := span.Attributes()
90+
requireAttribute(t, attrs, "blob.count", 2)
91+
requireAttribute(t, attrs, "blob.total_size_bytes", 3)
92+
// namespace hex string length assertion
93+
// 2 bytes = 4 hex characters
94+
foundNS := false
95+
for _, a := range attrs {
96+
if string(a.Key) == "da.namespace" {
97+
foundNS = true
98+
require.Equal(t, 4, len(a.Value.AsString()))
99+
}
100+
}
101+
require.True(t, foundNS, "attribute da.namespace not found")
102102
}
103103

104104
func TestTracedDA_Submit_Error(t *testing.T) {
@@ -132,10 +132,10 @@ func TestTracedDA_Retrieve_Success(t *testing.T) {
132132
spans := sr.Ended()
133133
require.Len(t, spans, 1)
134134
span := spans[0]
135-
require.Equal(t, "DA.Retrieve", span.Name())
136-
attrs := span.Attributes()
137-
requireAttribute(t, attrs, "ns.length", 1)
138-
requireAttribute(t, attrs, "blob.count", 2)
135+
require.Equal(t, "DA.Retrieve", span.Name())
136+
attrs := span.Attributes()
137+
requireAttribute(t, attrs, "ns.length", 1)
138+
requireAttribute(t, attrs, "blob.count", 2)
139139
}
140140

141141
func TestTracedDA_Retrieve_Error(t *testing.T) {
@@ -172,7 +172,7 @@ func TestTracedDA_Get_Success(t *testing.T) {
172172
spans := sr.Ended()
173173
require.Len(t, spans, 1)
174174
span := spans[0]
175-
require.Equal(t, "DA.Get", span.Name())
175+
require.Equal(t, "DA.Get", span.Name())
176176
attrs := span.Attributes()
177177
requireAttribute(t, attrs, "id.count", 2)
178178
requireAttribute(t, attrs, "blob.count", 2)

0 commit comments

Comments
 (0)