diff --git a/consumer/push_consumer.go b/consumer/push_consumer.go index 1a3d2336..db6a37e3 100644 --- a/consumer/push_consumer.go +++ b/consumer/push_consumer.go @@ -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, }) } diff --git a/internal/remote/remote_client.go b/internal/remote/remote_client.go index eabfb756..55a26469 100644 --- a/internal/remote/remote_client.go +++ b/internal/remote/remote_client.go @@ -21,6 +21,7 @@ import ( "bytes" "context" "encoding/binary" + "github.com/apache/rocketmq-client-go/v2/internal/utils" "io" "net" "sync" @@ -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), }) } }() diff --git a/internal/utils/errors.go b/internal/utils/errors.go index 0887a371..b7c30c2f 100644 --- a/internal/utils/errors.go +++ b/internal/utils/errors.go @@ -19,6 +19,7 @@ package utils import ( "github.com/apache/rocketmq-client-go/v2/rlog" + "runtime" ) func CheckError(action string, err error) { @@ -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]) +} diff --git a/rlog/log.go b/rlog/log.go index 5c99e2d9..253dd6b2 100644 --- a/rlog/log.go +++ b/rlog/log.go @@ -44,6 +44,7 @@ const ( LogKeyQueueId = "queueId" LogKeyQueueOffset = "queueOffset" LogKeyMessages = "messages" + LogKeyStack = "stack" ) type Logger interface {