Skip to content

Commit

Permalink
log stack info when consume fail
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerweili committed Sep 4, 2024
1 parent 6afaab0 commit e8a909a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions consumer/push_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ func (pc *pushConsumer) consumeMessageConcurrently(pq *processQueue, mq *primiti
if err := recover(); err != nil {
rlog.Error("consumeMessageConcurrently panic", map[string]interface{}{
rlog.LogKeyUnderlayError: err,
rlog.LogKeyStack: utils.GetStackAsString(false),
rlog.LogKeyConsumerGroup: pc.consumerGroup,
})
}
Expand Down
4 changes: 3 additions & 1 deletion internal/remote/remote_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bytes"
"context"
"encoding/binary"
"github.com/apache/rocketmq-client-go/v2/internal/utils"
"io"
"net"
"sync"
Expand Down Expand Up @@ -286,7 +287,8 @@ func (c *remotingClient) createScanner(r io.Reader) *bufio.Scanner {
defer func() {
if err := recover(); err != nil {
rlog.Error("scanner split panic", map[string]interface{}{
"panic": err,
rlog.LogKeyUnderlayError: err,
rlog.LogKeyStack: utils.GetStackAsString(false),
})
}
}()
Expand Down
6 changes: 6 additions & 0 deletions internal/utils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package utils

import (
"github.com/apache/rocketmq-client-go/v2/rlog"
"runtime"
)

func CheckError(action string, err error) {
Expand All @@ -28,3 +29,8 @@ func CheckError(action string, err error) {
})
}
}
func GetStackAsString(all bool) string {
buf := make([]byte, 1<<10)
stackSize := runtime.Stack(buf, all)
return string(buf[:stackSize])
}
1 change: 1 addition & 0 deletions rlog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
LogKeyQueueId = "queueId"
LogKeyQueueOffset = "queueOffset"
LogKeyMessages = "messages"
LogKeyStack = "stack"
)

type Logger interface {
Expand Down

0 comments on commit e8a909a

Please sign in to comment.