magistrala icon indicating copy to clipboard operation
magistrala copied to clipboard

Add message tracing over NATS using open tracing standard

Open anovakovic01 opened this issue 5 years ago • 7 comments

FEATURE REQUEST

  1. Is there an open issue addressing this request? If it does, please add a "+1" reaction to the existing issue, otherwise proceed to step 2. No.

  2. Describe the feature you are requesting, as well as the possible use case(s) for it. After adding open tracing support to the existing gRPC and HTTP endpoints in Users and Things service, we should add support for tracing async messages that are sent over Mainflux.

  3. Indicate the importance of this feature to you (must-have, should-have, nice-to-have). This is a must-have.

anovakovic01 avatar Jul 15 '19 16:07 anovakovic01

After doing the previous tracing issue, I figured I would grab this one as well.

I'm going to take a little time to read up on NATS before starting but I see that there is a NATS publisher in a number of services. I could see the implementation of this being similar to the tracing middleware in users and things.

nwneisen avatar Oct 07 '19 19:10 nwneisen

Great! Thanks @nwneisen.

drasko avatar Oct 07 '19 19:10 drasko

@anovakovic01 I took another look at this based on the not.go repo. I believe the tracing middleware I create was on the right track but I needed to transfer the span over a NATS message rather than a context.

The publish messages look like I can write the mainflux.RawMessage payload to a not.TraceMsg and save the result as the new payload. The span's context is then injected into this not.TraceMsg.

The subscriber side will be trickier due to messages coming in over a channel. I believe the tracing middleware should receive the message from this channel and extract the span context from this message. The remainder of the not.TraceMsg will be the payload that can be passed to the NATS broker on a separate channel.

Does this sound more like what you had in mind?

nwneisen avatar Oct 21 '19 04:10 nwneisen

@nwneisen You're right, you can write context data and raw msg payload into the not.TraceMsg. Think about maybe embedding this info in the RawMessage, and avoid using TraceMsg, because, if we at some point change broker, we'll have to replace this not package for something else too. mainflux.RawMessage already contains metadata related to the message.

anovakovic01 avatar Oct 21 '19 09:10 anovakovic01

@anovakovic01 I started taking a look at this again. This draft PR adds tracing for publishing the way we described above. I'm still trying to wrap my head around how this can be done for subscribing.

nwneisen avatar Nov 25 '19 23:11 nwneisen

@nwneisen thank you for the PR. It looks to me like it's the step in the right direction.

anovakovic01 avatar Nov 27 '19 13:11 anovakovic01

@nwneisen We recently created a broker package that wee use in all services to publish and subscribe. I guess that now it should be simpler to resolve this one. Would you like to take this one again?

manuio avatar Apr 08 '20 09:04 manuio