-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add context.Context support to StandardRouter message routing #286
Comments
Could you please add an example showing how this would work? My main question is "what An alternative would be for you to inject a
|
Thanks for reporting this issue. I'd like to clarify how tracing typically works in this context: The router.Route() usually serves as the entry point when messages are received. Here's a common pattern: func (svc *Service) onPublishReceived(p paho.PublishReceived) (bool, error) {
ctx, span := tracer.Start(context.Background(), "message_route") // root span
defer span.End()
m.router.Route(ctx, p.Packet.Packet())
return true, nil
}
func (svc *Service) defaultHandler(ctx context.Context, p *paho.Publish) {
ctx, span := tracer.Start(ctx, "default_handler")
defer span.End()
doWork(ctx) // continue propagating the span
} The flow works as follows:
The key point is that handlers have the flexibility to opt into tracing - the context parameter enables them to participate in the trace chain from the router's entry point through to completion, but they're not required to do so. This gives developers the freedom to integrate with tracing where it makes sense for their use case. Another important consideration is to distinguish between application-level and message dispatcher-level contexts. This distinction helps in understanding the scope and responsibility of context propagation through different layers of the system. We could potentially enhance the router's tracing support to make this pattern even more straightforward to implement. |
Thanks, that makes sense. I think my confusion re your PR was due to the changes needed due to As such, I think your change (as is) would need to be contingent upon us removing the depreciated We could do this, but it will break users code, and I'm not sure how beneficial it would be (given that |
Thanks for the explanation. I apologize for not considering the backward compatibility impact earlier. Let me think about how to adjust the approach - perhaps introducing a new Router interface, as you suggested, would be a better solution. |
Currently using paho.StandardRouter for message routing but it lacks context.Context support.
Adding context support would allow applications to integrate distributed tracing (OpenTelemetry) much easier.
The text was updated successfully, but these errors were encountered: