Skip to content

Commit

Permalink
added traceId to logging messages if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
kopaygorodsky committed Sep 16, 2021
1 parent 07b799c commit 7ee3e58
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pubsub/message/execution/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package execution

import (
"context"
"fmt"

"github.com/go-foreman/foreman/log"
"github.com/go-foreman/foreman/pubsub/endpoint"
Expand Down Expand Up @@ -59,7 +60,7 @@ func (m messageExecutionCtx) Return(options ...endpoint.DeliveryOption) error {
m.message.Headers().RegisterReturn()
if err := m.Send(outComingMsg, options...); err != nil {
m.logger.Logf(log.ErrorLevel, "error when returning a message %s", outComingMsg.UID())
return errors.Wrapf(err, "error when returning a message %s", outComingMsg.UID())
return errors.Wrapf(err, "returning message %s", outComingMsg.UID())
}

return nil
Expand All @@ -70,6 +71,11 @@ func (m messageExecutionCtx) Message() *message.ReceivedMessage {
}

func (m messageExecutionCtx) LogMessage(lvl log.Level, msg string) {
if traceID, exists := m.Message().Headers()["traceId"]; exists {
m.logger.Log(lvl, fmt.Sprintf("TraceID: %s. %s", traceID, msg))
return
}

m.logger.Log(lvl, msg)
}

Expand Down

0 comments on commit 7ee3e58

Please sign in to comment.