1

I'm trying to write a Unit Of Work for NServiceBus that will be called before and after each message handler to measure the time it takes for that handler to run and write it in to a database.

I was able to successfully write the Unit Of Work, but at the Begin() method implementation, how can I tell which handler is being called?

developer82
  • 13,237
  • 21
  • 88
  • 153
  • Your unit of work should normally be independent of the handlers. Why do you need that information? Also, multiple handlers may be called for a single message, so what would you do in that case? – Chris Bednarski Oct 19 '14 at 22:45
  • What I would like to do is see which handler is being called for a message and measure the amount of time it takes to handle it. I would like to set s Stopwatch on start and stop it on end, and if the elapsed time is bigger than X log a message to my logger. Is this possible? – developer82 Oct 20 '14 at 05:30
  • 1
    I'm not sure that this is such a good idea. You will be slowing down the processing of your messages in your attempt to instrument your code. Also, why do you need handler level instrumentation rather than message-level performance measurements? – Udi Dahan Oct 20 '14 at 09:31

2 Answers2

0

You can use ServiceInsight to get this kind of information. See docs on ServiceControl and ServiceInsight for more info. another channel may be NServiceBus.Performance Counters.

Sean Farmar
  • 2,254
  • 13
  • 10
  • 1
    This would provide the information for the whole message (and if there was more than one handler which processed that message, would be the sum of all of them, plus infrastructure time). – Udi Dahan Oct 20 '14 at 09:30
0

I'd look into the decorator pattern and deal with this by dependency injection

example https://code.google.com/p/autofac/wiki/AdaptersAndDecorators

You could create a decorator for the IHandleMessages interface and configure all message handlers to return a proxy to the real message handler which adds the required instrumentation logic.

Chris Bednarski
  • 3,364
  • 25
  • 33