github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/middleware/opentracing/sendermiddleware.go (about) 1 package opentracing 2 3 import ( 4 "github.com/asynkron/protoactor-go/actor" 5 "github.com/opentracing/opentracing-go" 6 "log/slog" 7 ) 8 9 func SenderMiddleware() actor.SenderMiddleware { 10 return func(next actor.SenderFunc) actor.SenderFunc { 11 return func(c actor.SenderContext, target *actor.PID, envelope *actor.MessageEnvelope) { 12 span := getActiveSpan(c.Self()) 13 14 if span == nil { 15 c.Logger().Debug("OUTBOUND No active span", slog.Any("self", c.Self()), slog.Any("actor", c.Actor()), slog.Any("message", envelope.Message)) 16 next(c, target, envelope) 17 return 18 } 19 20 err := opentracing.GlobalTracer().Inject(span.Context(), opentracing.TextMap, opentracing.TextMapWriter(&messageEnvelopeWriter{MessageEnvelope: envelope})) 21 if err != nil { 22 c.Logger().Debug("OUTBOUND Error injecting", slog.Any("self", c.Self()), slog.Any("actor", c.Actor()), slog.Any("message", envelope.Message)) 23 next(c, target, envelope) 24 return 25 } 26 27 c.Logger().Debug("OUTBOUND Successfully injected", slog.Any("self", c.Self()), slog.Any("actor", c.Actor()), slog.Any("message", envelope.Message)) 28 next(c, target, envelope) 29 } 30 } 31 }