Skip to content

Commit

Permalink
chore: improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jul 3, 2024
1 parent 393587f commit f2de70c
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ func (svc *Service) PublishHandler(c echo.Context) error {
}

svc.Logger.WithFields(logrus.Fields{
"eventId": requestData.SignedEvent.ID,
"relayUrl": requestData.RelayUrl,
"eventId": requestData.SignedEvent.ID,
"relayUrl": requestData.RelayUrl,
}).Info("Publishing event")

err = relay.Publish(ctx, *requestData.SignedEvent)
Expand All @@ -265,8 +265,8 @@ func (svc *Service) PublishHandler(c echo.Context) error {
}

svc.Logger.WithFields(logrus.Fields{
"eventId": requestData.SignedEvent.ID,
"relayUrl": requestData.RelayUrl,
"eventId": requestData.SignedEvent.ID,
"relayUrl": requestData.RelayUrl,
}).Info("Published event")

return c.JSON(http.StatusOK, PublishResponse{
Expand Down Expand Up @@ -300,9 +300,10 @@ func (svc *Service) NIP47Handler(c echo.Context) error {
}

svc.Logger.WithFields(logrus.Fields{
"requestEventId": requestData.SignedEvent.ID,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
"requestEventId": requestData.SignedEvent.ID,
"connectionPubkey": requestData.SignedEvent.PubKey,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
}).Info("Processing request event")

if svc.db.Where("nostr_id = ?", requestData.SignedEvent.ID).Find(&RequestEvent{}).RowsAffected != 0 {
Expand Down Expand Up @@ -336,9 +337,10 @@ func (svc *Service) NIP47Handler(c echo.Context) error {
select {
case <-ctx.Done():
svc.Logger.WithFields(logrus.Fields{
"requestEventId": requestData.SignedEvent.ID,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
"requestEventId": requestData.SignedEvent.ID,
"connectionPubkey": requestData.SignedEvent.PubKey,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
}).Info("Stopped subscription without receiving event")
if ctx.Err() == context.DeadlineExceeded {
return c.JSON(http.StatusGatewayTimeout, ErrorResponse{
Expand All @@ -352,10 +354,11 @@ func (svc *Service) NIP47Handler(c echo.Context) error {
})
case event := <-subscription.EventChan:
svc.Logger.WithFields(logrus.Fields{
"requestEventId": requestData.SignedEvent.ID,
"responseEventId": event.ID,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
"requestEventId": requestData.SignedEvent.ID,
"connectionPubkey": requestData.SignedEvent.PubKey,
"responseEventId": event.ID,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
}).Info("Received response event")
return c.JSON(http.StatusOK, NIP47Response{
Event: event,
Expand Down Expand Up @@ -395,10 +398,11 @@ func (svc *Service) NIP47WebhookHandler(c echo.Context) error {
}

svc.Logger.WithFields(logrus.Fields{
"requestEventId": requestData.SignedEvent.ID,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
"webhookUrl": requestData.WebhookUrl,
"requestEventId": requestData.SignedEvent.ID,
"connectionPubkey": requestData.SignedEvent.PubKey,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
"webhookUrl": requestData.WebhookUrl,
}).Info("Processing request event")

if svc.db.Where("nostr_id = ?", requestData.SignedEvent.ID).First(&RequestEvent{}).RowsAffected != 0 {
Expand Down Expand Up @@ -478,6 +482,13 @@ func (svc *Service) NIP47NotificationHandler(c echo.Context) error {
})
}

svc.Logger.WithFields(logrus.Fields{
"connectionPubkey": requestData.ConnPubkey,
"walletPubkey": requestData.WalletPubkey,
"relayUrl": requestData.RelayUrl,
"webhookUrl": requestData.WebhookUrl,
}).Info("Subscribing to notifications")

subscription := Subscription{
RelayUrl: requestData.RelayUrl,
WebhookUrl: requestData.WebhookUrl,
Expand Down Expand Up @@ -727,18 +738,20 @@ func (svc *Service) publishEvent(ctx context.Context, subscription *Subscription
sub.Unsub()
} else {
svc.Logger.WithFields(logrus.Fields{
"status": REQUEST_EVENT_PUBLISH_CONFIRMED,
"eventId": subscription.RequestEvent.ID,
"status": REQUEST_EVENT_PUBLISH_CONFIRMED,
"eventId": subscription.RequestEvent.ID,
"connectionPubkey": subscription.RequestEvent.PubKey,
}).Info("Published request event successfully")
subscription.RequestEventDB.State = REQUEST_EVENT_PUBLISH_CONFIRMED
}
}

func (svc *Service) handleResponseEvent(event *nostr.Event, subscription *Subscription) {
svc.Logger.WithFields(logrus.Fields{
"eventId": event.ID,
"eventKind": event.Kind,
"requestEventId": subscription.RequestEvent.ID,
"eventId": event.ID,
"eventKind": event.Kind,
"requestEventId": subscription.RequestEvent.ID,
"connectionPubkey": subscription.RequestEvent.PubKey,
}).Info("Received response event")
responseEvent := ResponseEvent{
NostrId: event.ID,
Expand Down

0 comments on commit f2de70c

Please sign in to comment.