Search code examples
c#instrumentationcastle-dynamicproxy

Instrumentation C# across Rabbit MQ


I have a WPF application and a worker process that picks up messages on the queue from the client application.

There are several users who could click on multiple items thus sending multiple processes on to the queue, therefore I need some kind of unique ID for each.

I would like to implement instrumentation logging for this but am finding it extremely difficult to have a single primary key or ID for the process. I have message ID that can be used as an ID but that is lost when the methods are called and I don't want to have to pass it into every method.

For example if the process went as follows:

  1. User clicks data retrieve button
  2. Create message with Message Id -> Log in instrumentation the Message ID
  3. Worker picks up message with Message Id -> Log in instrumentation with the same message ID
  4. Data retrieval method called (No message ID) -> Can't log

Essentially I don't want to pass the message ID into every method (for example step 4) as that gets very messy.

I am using Castle Proxies to handle the logging but again can't find a nice way of having just a common ID for the log so I can log a request all the way through and how long each part is taking.

I have something very similar to this: Instrumentation With Interceptors

But as well as the ID for each method being called, I need an overall ID to group the entire request together.


Solution

  • Two options as far as I can see: 1. I'm not sure how your logger implemented. You may need to inject into the logger factory. or, 2. consider user a ThreadStatic if no parallel code. or CallContext.GetLogicalData for TPL. But it looks bit messy, especially for TPL you will need to maintain an context.