Skip to content
This repository was archived by the owner on Jun 4, 2026. It is now read-only.

Commit 1416fb9

Browse files
committed
meta: add basic spans
1 parent 57ea8f5 commit 1416fb9

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

internal/search/service.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ import (
99
"github.com/moov-io/ach"
1010
"github.com/moov-io/ach/cmd/achcli/describe/mask"
1111
"github.com/moov-io/base/log"
12+
"github.com/moov-io/base/telemetry"
1213
railmsgsql "github.com/moov-io/rail-msg-sql"
1314
"github.com/moov-io/rail-msg-sql/internal/achhelp"
1415
"github.com/moov-io/rail-msg-sql/internal/storage"
1516

1617
_ "github.com/ncruces/go-sqlite3/driver"
1718
_ "github.com/ncruces/go-sqlite3/embed"
19+
"go.opentelemetry.io/otel/attribute"
20+
"go.opentelemetry.io/otel/trace"
1821
)
1922

2023
type Service interface {
@@ -71,19 +74,24 @@ func (s *service) Close() error {
7174
}
7275

7376
func (s *service) IngestACHFiles(ctx context.Context, params storage.FilterParams) error {
77+
ctx, span := telemetry.StartSpan(ctx, "ingest-ach-files")
78+
defer span.End()
79+
7480
files, err := s.fileStorage.ListAchFiles(ctx, params)
7581
if err != nil {
7682
return fmt.Errorf("ingesting ach files: %w", err)
7783
}
7884

7985
for idx := range files {
80-
if files[idx].File == nil {
86+
file := files[idx]
87+
88+
if file.File == nil {
8189
continue
8290
}
8391

84-
err := s.IngestACHFile(ctx, files[idx].Filename, files[idx].File)
92+
err := s.IngestACHFile(ctx, file.Filename, file.File)
8593
if err != nil {
86-
return fmt.Errorf("ingesting %s failed: %w", files[idx].Filename, err)
94+
return fmt.Errorf("ingesting %s failed: %w", file.Filename, err)
8795
}
8896
}
8997

@@ -92,6 +100,11 @@ func (s *service) IngestACHFiles(ctx context.Context, params storage.FilterParam
92100

93101
// insertFile inserts an ACH file's header and control into ach_files.
94102
func (s *service) insertFile(ctx context.Context, tx *sql.Tx, filename string, file *ach.File) error {
103+
ctx, span := telemetry.StartSpan(ctx, "sql-insert-file", trace.WithAttributes(
104+
attribute.String("filename", filename),
105+
))
106+
defer span.End()
107+
95108
query := `
96109
INSERT OR IGNORE INTO ach_files (
97110
file_id,
@@ -412,6 +425,11 @@ func (s *service) IngestACHFile(ctx context.Context, filename string, file *ach.
412425
return errors.New("nil File")
413426
}
414427

428+
ctx, span := telemetry.StartSpan(ctx, "ingest-ach-file", trace.WithAttributes(
429+
attribute.String("filename", filename),
430+
))
431+
defer span.End()
432+
415433
// Make sure to normalize the IDs
416434
file = achhelp.PopulateIDs(file)
417435

@@ -493,6 +511,11 @@ func (s *service) Search(ctx context.Context, query string, params storage.Filte
493511
return nil, fmt.Errorf("query cannot be empty")
494512
}
495513

514+
ctx, span := telemetry.StartSpan(ctx, "search-files", trace.WithAttributes(
515+
attribute.String("sql.query", query),
516+
))
517+
defer span.End()
518+
496519
rows, err := s.db.QueryContext(ctx, query)
497520
if err != nil {
498521
return nil, fmt.Errorf("failed to execute query: %w", err)

internal/storage/repository.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import (
44
"context"
55
"fmt"
66
"path/filepath"
7+
"time"
78

89
"github.com/moov-io/ach"
910
"github.com/moov-io/ach-web-viewer/pkg/filelist"
11+
"github.com/moov-io/base/telemetry"
12+
13+
"go.opentelemetry.io/otel/attribute"
14+
"go.opentelemetry.io/otel/trace"
1015
)
1116

1217
type Repository struct {
@@ -32,6 +37,13 @@ func NewRepository(config Config) (*Repository, error) {
3237
}
3338

3439
func (r *Repository) ListAchFiles(ctx context.Context, params FilterParams) ([]File, error) {
40+
_, span := telemetry.StartSpan(ctx, "list-ach-files", trace.WithAttributes(
41+
attribute.String("filter.start", params.StartDate.Format(time.RFC3339)),
42+
attribute.String("filter.end", params.EndDate.Format(time.RFC3339)),
43+
attribute.String("filter.pattern", params.Pattern),
44+
))
45+
defer span.End()
46+
3547
resp, err := r.ach.GetFiles(filelist.ListOpts{
3648
StartDate: params.StartDate,
3749
EndDate: params.EndDate,

0 commit comments

Comments
 (0)