@@ -5,6 +5,7 @@ import { OutgoingPayment, OutgoingPaymentState } from './model'
5
5
import { LifecycleError , PaymentError } from './errors'
6
6
import * as lifecycle from './lifecycle'
7
7
import { PaymentMethodHandlerError } from '../../../payment-method/handler/errors'
8
+ import { trace , Span } from '@opentelemetry/api'
8
9
9
10
// First retry waits 10 seconds, second retry waits 20 (more) seconds, etc.
10
11
export const RETRY_BACKOFF_SECONDS = 10
@@ -15,23 +16,33 @@ const MAX_STATE_ATTEMPTS = 5
15
16
export async function processPendingPayment (
16
17
deps_ : ServiceDependencies
17
18
) : 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
+ )
35
46
}
36
47
37
48
// Fetch (and lock) a payment for work.
0 commit comments