Skip to content

Commit b9be601

Browse files
njliemkurapov
andauthored
feat(backend): add trace to outgoing payment lifecycle (#2884)
* feat(backend): add trace to outgoing payment lifecycle * feat(backend): encapsulate query lookup in trace * chore(localenv): remove traces from default localenv --------- Co-authored-by: Max Kurapov <[email protected]>
1 parent 3bc368a commit b9be601

File tree

1 file changed

+28
-17
lines changed
  • packages/backend/src/open_payments/payment/outgoing

1 file changed

+28
-17
lines changed

packages/backend/src/open_payments/payment/outgoing/worker.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { OutgoingPayment, OutgoingPaymentState } from './model'
55
import { LifecycleError, PaymentError } from './errors'
66
import * as lifecycle from './lifecycle'
77
import { PaymentMethodHandlerError } from '../../../payment-method/handler/errors'
8+
import { trace, Span } from '@opentelemetry/api'
89

910
// First retry waits 10 seconds, second retry waits 20 (more) seconds, etc.
1011
export const RETRY_BACKOFF_SECONDS = 10
@@ -15,23 +16,33 @@ const MAX_STATE_ATTEMPTS = 5
1516
export async function processPendingPayment(
1617
deps_: ServiceDependencies
1718
): Promise<string | undefined> {
18-
return deps_.knex.transaction(async (trx) => {
19-
const payment = await getPendingPayment(trx)
20-
if (!payment) return
21-
22-
await handlePaymentLifecycle(
23-
{
24-
...deps_,
25-
knex: trx,
26-
logger: deps_.logger.child({
27-
payment: payment.id,
28-
from_state: payment.state
29-
})
30-
},
31-
payment
32-
)
33-
return payment.id
34-
})
19+
const tracer = trace.getTracer('outgoing_payment_worker')
20+
21+
return tracer.startActiveSpan(
22+
'outgoingPaymentLifecycle',
23+
async (span: Span) => {
24+
const paymentId = await deps_.knex.transaction(async (trx) => {
25+
const payment = await getPendingPayment(trx)
26+
if (!payment) return
27+
28+
await handlePaymentLifecycle(
29+
{
30+
...deps_,
31+
knex: trx,
32+
logger: deps_.logger.child({
33+
payment: payment.id,
34+
from_state: payment.state
35+
})
36+
},
37+
payment
38+
)
39+
return payment.id
40+
})
41+
42+
span.end()
43+
return paymentId
44+
}
45+
)
3546
}
3647

3748
// Fetch (and lock) a payment for work.

0 commit comments

Comments
 (0)