Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions gbus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"database/sql"
"errors"
"fmt"

"runtime/debug"
"sync"
"time"

"github.com/opentracing-contrib/go-amqp/amqptracer"
"github.com/opentracing/opentracing-go"
slog "github.com/opentracing/opentracing-go/log"
"github.com/rs/xid"
log "github.com/sirupsen/logrus"
"github.com/streadway/amqp"
Expand Down Expand Up @@ -550,16 +552,21 @@ func (b *DefaultBus) monitorAMQPErrors() {
func (b *DefaultBus) sendImpl(ctx context.Context, tx *sql.Tx, toService, replyTo, exchange, topic string, message *BusMessage, policies ...MessagePolicy) (er error) {
b.SenderLock.Lock()
defer b.SenderLock.Unlock()

span, ctx := opentracing.StartSpanFromContext(ctx, "sendImpl")
defer func() {
if err := recover(); err != nil {

errMsg := fmt.Sprintf("panic recovered panicking err:\n%v\n%s", err, debug.Stack())
er = errors.New(errMsg)
span.LogFields(slog.Error(er))
}
span.Finish()
}()

headers := message.GetAMQPHeaders()
err := amqptracer.Inject(span, headers)
if err != nil {
b.log().WithError(err).Error("could not inject headers")
}

buffer, err := b.Serializer.Encode(message.Payload)
if err != nil {
Expand All @@ -575,17 +582,8 @@ func (b *DefaultBus) sendImpl(ctx context.Context, tx *sql.Tx, toService, replyT
ContentEncoding: b.Serializer.Name(),
Headers: headers,
}
span.LogFields(message.GetTraceLog()...)

/* TODO:FIX Opentracing context
sp := opentracing.SpanFromContext(ctx)
if sp != nil {
defer sp.Finish()
}
// Inject the span context into the AMQP header.
if err := amqptracer.Inject(sp, msg.Headers); err != nil {
return err
}
*/
for _, defaultPolicy := range b.DefaultPolicies {
defaultPolicy.Apply(&msg)
}
Expand All @@ -609,7 +607,7 @@ func (b *DefaultBus) sendImpl(ctx context.Context, tx *sql.Tx, toService, replyT
b.log().WithField("message_id", msg.MessageId).Info("sending message to outbox")
saveErr := b.Outbox.Save(tx, exchange, key, msg)
if saveErr != nil {
log.Printf("fialed to save to transactional outbox\n%v", saveErr)
log.WithError(saveErr).Error("failed to save to transactional outbox")
}
return saveErr
}
Expand Down
13 changes: 13 additions & 0 deletions gbus/messages.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gbus

import (
"github.com/opentracing/opentracing-go/log"
"github.com/rs/xid"
"github.com/streadway/amqp"
)
Expand Down Expand Up @@ -60,6 +61,18 @@ func (bm *BusMessage) SetPayload(payload Message) {
bm.Payload = payload
}

func (bm *BusMessage) GetTraceLog() (fields []log.Field) {
return []log.Field{
log.String("message", bm.PayloadFQN),
log.String("ID", bm.ID),
log.String("SagaID", bm.SagaID),
log.String("CorrelationID", bm.CorrelationID),
log.String("SagaCorrelationID", bm.SagaCorrelationID),
log.String("Semantics", bm.Semantics),
log.String("RPCID", bm.RPCID),
}
}

func castToString(i interface{}) string {
v, ok := i.(string)
if !ok {
Expand Down
1 change: 0 additions & 1 deletion gbus/saga/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package saga
import (
"database/sql"
"fmt"

"reflect"
"strings"
"sync"
Expand Down
7 changes: 0 additions & 7 deletions gbus/saga/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/sirupsen/logrus"

"github.com/wework/grabbit/gbus"
)

Expand All @@ -25,12 +24,6 @@ func (tm *TimeoutManager) RequestTimeout(svcName, sagaID string, duration time.D
SagaID: sagaID}
msg := gbus.NewBusMessage(reuqestTimeout)
msg.SagaCorrelationID = sagaID
/* TODO:FIX Opentracing
span := opentracing.GlobalTracer().StartSpan("timeout")
if span != nil {
defer span.Finish()
}
*/
if err := tm.bus.Send(context.Background(), svcName, msg); err != nil {
//TODO: add logger
logrus.WithError(err).Error("could not send timeout to bus")
Expand Down
1 change: 0 additions & 1 deletion gbus/serialization/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/golang/protobuf/proto"
"github.com/sirupsen/logrus"

"github.com/wework/grabbit/gbus"
)

Expand Down
2 changes: 0 additions & 2 deletions gbus/tx/mysql/sagastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"fmt"

log "github.com/sirupsen/logrus"

"github.com/wework/grabbit/gbus"

"github.com/wework/grabbit/gbus/saga"
"github.com/wework/grabbit/gbus/tx"
)
Expand Down
3 changes: 1 addition & 2 deletions gbus/tx/mysql/txoutbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
"strings"
"time"

log "github.com/sirupsen/logrus"

"github.com/rs/xid"
log "github.com/sirupsen/logrus"
"github.com/streadway/amqp"
"github.com/wework/grabbit/gbus"
)
Expand Down
Loading