Skip to content

Commit

Permalink
add latency and amount to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiidb committed Aug 10, 2023
1 parent 5b9e8b6 commit 2b6719b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func (svc *Service) ProcessPayment(ctx context.Context, payment *lnrpc.Payment)
//if the payment was in the database as final then we already published it
//and we only publish completed payments
if notInflight && !alreadyPublished {
startTime := time.Now()
err := svc.PublishPayload(ctx, payment, LNDPaymentExchange, routingKey)
if err != nil {
logrus.WithFields(
Expand All @@ -316,6 +317,8 @@ func (svc *Service) ProcessPayment(ctx context.Context, payment *lnrpc.Payment)
logrus.Fields{
"payload_type": "payment",
"status": fmt.Sprintf("%s", payment.Status),
"latency": time.Since(startTime).Seconds(),
"amount": payment.ValueSat,
"payment_hash": payment.PaymentHash,
}).Info("published payment")
}
Expand All @@ -325,6 +328,7 @@ func (svc *Service) ProcessPayment(ctx context.Context, payment *lnrpc.Payment)

func (svc *Service) ProcessInvoice(ctx context.Context, invoice *lnrpc.Invoice) error {
if invoice.State == lnrpc.Invoice_SETTLED {
startTime := time.Now()
err := svc.PublishPayload(ctx, invoice, LNDInvoiceExchange, LNDInvoiceRoutingKey)
if err != nil {
logrus.WithFields(
Expand All @@ -337,6 +341,8 @@ func (svc *Service) ProcessInvoice(ctx context.Context, invoice *lnrpc.Invoice)
logrus.WithFields(
logrus.Fields{
"payload_type": "invoice",
"latency": time.Since(startTime).Seconds(),
"amount": invoice.AmtPaidSat,
"payment_hash": hex.EncodeToString(invoice.RHash),
}).Info("published invoice")
//add it to the database if we have one
Expand All @@ -356,7 +362,6 @@ func (svc *Service) PublishPayload(ctx context.Context, payload interface{}, exc

timeoutCtx, cancel := context.WithTimeout(ctx, time.Duration(svc.cfg.RabbitMQTimeoutSeconds)*time.Second)
defer cancel()
logrus.Info("Publishing message")
conf, err := svc.rabbitChannel.PublishWithDeferredConfirmWithContext(
timeoutCtx,
//todo from config
Expand Down

0 comments on commit 2b6719b

Please sign in to comment.