@@ -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
2023type Service interface {
@@ -71,19 +74,24 @@ func (s *service) Close() error {
7174}
7275
7376func (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.
94102func (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 )
0 commit comments