Skip to content

Commit b97ec46

Browse files
committed
Monitors DB queries for metadata
1 parent 1b4dfe0 commit b97ec46

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

db/postgres.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,12 @@ func (p *PostgreSQL) GetCompany(id string) (string, error) {
128128
if err != nil {
129129
return "", fmt.Errorf("error converting cnpj %s to integer: %w", id, err)
130130
}
131-
132131
ctx := context.Background()
133132
if p.newRelic != nil {
134133
txn := p.newRelic.StartTransaction("GetCompany")
135134
ctx = newrelic.NewContext(ctx, txn)
136135
defer txn.End()
137136
}
138-
139137
rows, err := p.pool.Query(ctx, p.sql["get"], n)
140138
if err != nil {
141139
return "", fmt.Errorf("error looking for cnpj %d: %w", n, err)
@@ -178,7 +176,13 @@ func (p *PostgreSQL) MetaSave(k, v string) error {
178176

179177
// MetaRead reads a key/value pair from the metadata table.
180178
func (p *PostgreSQL) MetaRead(k string) (string, error) {
181-
rows, err := p.pool.Query(context.Background(), p.sql["meta_read"], k)
179+
ctx := context.Background()
180+
if p.newRelic != nil {
181+
txn := p.newRelic.StartTransaction("MetaRead")
182+
ctx = newrelic.NewContext(ctx, txn)
183+
defer txn.End()
184+
}
185+
rows, err := p.pool.Query(ctx, p.sql["meta_read"], k)
182186
if err != nil {
183187
return "", fmt.Errorf("error looking for metadata key %s: %w", k, err)
184188
}

0 commit comments

Comments
 (0)