Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): add trace to outgoing payment lifecycle #2884

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions packages/backend/src/open_payments/payment/outgoing/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OutgoingPayment, OutgoingPaymentState } from './model'
import { LifecycleError, PaymentError } from './errors'
import * as lifecycle from './lifecycle'
import { PaymentMethodHandlerError } from '../../../payment-method/handler/errors'
import { trace, Span } from '@opentelemetry/api'

// First retry waits 10 seconds, second retry waits 20 (more) seconds, etc.
export const RETRY_BACKOFF_SECONDS = 10
Expand All @@ -15,23 +16,33 @@ const MAX_STATE_ATTEMPTS = 5
export async function processPendingPayment(
deps_: ServiceDependencies
): Promise<string | undefined> {
return deps_.knex.transaction(async (trx) => {
const payment = await getPendingPayment(trx)
if (!payment) return

await handlePaymentLifecycle(
{
...deps_,
knex: trx,
logger: deps_.logger.child({
payment: payment.id,
from_state: payment.state
})
},
payment
)
return payment.id
})
const tracer = trace.getTracer('outgoing_payment_worker')

return tracer.startActiveSpan(
'outgoingPaymentLifecycle',
async (span: Span) => {
const paymentId = await deps_.knex.transaction(async (trx) => {
const payment = await getPendingPayment(trx)
if (!payment) return

await handlePaymentLifecycle(
{
...deps_,
knex: trx,
logger: deps_.logger.child({
payment: payment.id,
from_state: payment.state
})
},
payment
)
return payment.id
})

span.end()
return paymentId
}
)
}

// Fetch (and lock) a payment for work.
Expand Down
Loading