@@ -2,6 +2,7 @@ package store
22
33import (
44 "context"
5+ "encoding/hex"
56
67 ds "github.com/ipfs/go-datastore"
78 "go.opentelemetry.io/otel"
@@ -60,7 +61,7 @@ func (t *tracedStore) GetBlockData(ctx context.Context, height uint64) (*types.S
6061
6162func (t * tracedStore ) GetBlockByHash (ctx context.Context , hash []byte ) (* types.SignedHeader , * types.Data , error ) {
6263 ctx , span := t .tracer .Start (ctx , "Store.GetBlockByHash" ,
63- trace .WithAttributes (attribute .String ("hash" , string (hash ))),
64+ trace .WithAttributes (attribute .String ("hash" , hex . EncodeToString (hash ))),
6465 )
6566 defer span .End ()
6667
@@ -95,7 +96,7 @@ func (t *tracedStore) GetSignature(ctx context.Context, height uint64) (*types.S
9596
9697func (t * tracedStore ) GetSignatureByHash (ctx context.Context , hash []byte ) (* types.Signature , error ) {
9798 ctx , span := t .tracer .Start (ctx , "Store.GetSignatureByHash" ,
98- trace .WithAttributes (attribute .String ("hash" , string (hash ))),
99+ trace .WithAttributes (attribute .String ("hash" , hex . EncodeToString (hash ))),
99100 )
100101 defer span .End ()
101102
@@ -229,6 +230,7 @@ func (t *tracedStore) NewBatch(ctx context.Context) (Batch, error) {
229230 return & tracedBatch {
230231 inner : batch ,
231232 tracer : t .tracer ,
233+ ctx : ctx ,
232234 }, nil
233235}
234236
@@ -237,10 +239,11 @@ var _ Batch = (*tracedBatch)(nil)
237239type tracedBatch struct {
238240 inner Batch
239241 tracer trace.Tracer
242+ ctx context.Context
240243}
241244
242245func (b * tracedBatch ) SaveBlockData (header * types.SignedHeader , data * types.Data , signature * types.Signature ) error {
243- _ , span := b .tracer .Start (context . Background () , "Batch.SaveBlockData" ,
246+ _ , span := b .tracer .Start (b . ctx , "Batch.SaveBlockData" ,
244247 trace .WithAttributes (attribute .Int64 ("height" , int64 (header .Height ()))),
245248 )
246249 defer span .End ()
@@ -256,7 +259,7 @@ func (b *tracedBatch) SaveBlockData(header *types.SignedHeader, data *types.Data
256259}
257260
258261func (b * tracedBatch ) SetHeight (height uint64 ) error {
259- _ , span := b .tracer .Start (context . Background () , "Batch.SetHeight" ,
262+ _ , span := b .tracer .Start (b . ctx , "Batch.SetHeight" ,
260263 trace .WithAttributes (attribute .Int64 ("height" , int64 (height ))),
261264 )
262265 defer span .End ()
@@ -272,7 +275,7 @@ func (b *tracedBatch) SetHeight(height uint64) error {
272275}
273276
274277func (b * tracedBatch ) UpdateState (state types.State ) error {
275- _ , span := b .tracer .Start (context . Background () , "Batch.UpdateState" ,
278+ _ , span := b .tracer .Start (b . ctx , "Batch.UpdateState" ,
276279 trace .WithAttributes (attribute .Int64 ("state.height" , int64 (state .LastBlockHeight ))),
277280 )
278281 defer span .End ()
@@ -288,7 +291,7 @@ func (b *tracedBatch) UpdateState(state types.State) error {
288291}
289292
290293func (b * tracedBatch ) Commit () error {
291- _ , span := b .tracer .Start (context . Background () , "Batch.Commit" )
294+ _ , span := b .tracer .Start (b . ctx , "Batch.Commit" )
292295 defer span .End ()
293296
294297 err := b .inner .Commit ()
@@ -302,7 +305,7 @@ func (b *tracedBatch) Commit() error {
302305}
303306
304307func (b * tracedBatch ) Put (key ds.Key , value []byte ) error {
305- _ , span := b .tracer .Start (context . Background () , "Batch.Put" ,
308+ _ , span := b .tracer .Start (b . ctx , "Batch.Put" ,
306309 trace .WithAttributes (
307310 attribute .String ("key" , key .String ()),
308311 attribute .Int ("value.size" , len (value )),
@@ -321,7 +324,7 @@ func (b *tracedBatch) Put(key ds.Key, value []byte) error {
321324}
322325
323326func (b * tracedBatch ) Delete (key ds.Key ) error {
324- _ , span := b .tracer .Start (context . Background () , "Batch.Delete" ,
327+ _ , span := b .tracer .Start (b . ctx , "Batch.Delete" ,
325328 trace .WithAttributes (attribute .String ("key" , key .String ())),
326329 )
327330 defer span .End ()
0 commit comments