Skip to content

Commit

Permalink
Log incoming subscription messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault authored and lukanus committed Aug 9, 2023
1 parent 694994a commit 21c6f8f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
8 changes: 6 additions & 2 deletions stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ func subscribe(ctx context.Context, log log.Logger, ps PubSub, handle func(conte
s := ps.Subscribe(ctx)
defer s.Close()

log = log.WithField("topic", ps.String())

for {
msg, err := s.Next(ctx)
if err != nil {
Expand All @@ -146,10 +148,12 @@ func subscribe(ctx context.Context, log log.Logger, ps PubSub, handle func(conte
return
}

log.WithError(err).
WithField("topic", ps.String()).
log.With(msg).
WithError(err).
Warn("failed to handle subscription event")
}

log.With(msg).Debug("handled subscription event")
}
}

Expand Down
25 changes: 25 additions & 0 deletions stream/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,37 @@ type Subscription interface {

type ForkVersionFormat uint64

func (f ForkVersionFormat) String() string {
switch f {
case Unknown:
return "none"
case AltairJson:
return "altair/json"
case BellatrixJson:
return "bellatrix/json"
case CapellaJson:
return "capella/json"
case CapellaSSZ:
return "capella/ssz"
}

return fmt.Sprintf("invalid: %d", f)
}

type Message struct {
Source uuid.UUID
ForkEncoding ForkVersionFormat
Payload []byte
}

func (m Message) Loggable() map[string]any {
return map[string]any{
"source": m.Source,
"fork_encoding": m.ForkEncoding,
"n_bytes": len(m.Payload),
}
}

func Encode(m Message) ([]byte, error) {
rawItem, err := json.Marshal(m)
if err != nil {
Expand Down

0 comments on commit 21c6f8f

Please sign in to comment.