Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking specific method calls

Currently I'm writing a program that can estimate the costs of an Azure application. For this I have the idea to intercept all the methods that will do (indirectly) a call to the (Azure) server. And for each of the methods decide to which aspect of the costs it belongs to (for example (storage-transactions, servicebus-transactions, token-requests etc.))

One of the difficulties of this is that I also want to intercept a method call when the class/method is mocked, so the program can also be used in (unit-)tests during the development of an Azure application.

So I was wondering if there is a way to 'subscribe' on a method of a class. And when this method is called an event will be fired. Or are there other (better) solutions to intercept storage-transactions, servicebus-transactions, token-request etc. also for classes that send for example a storage-transactions but are mocked?

Thanks in advance

EDIT 1: Does anyone know if there are some (helper) classes/libraries or references that contains/knows all the classes/methods that influences the Costs of an Azure application?

EDIT 2 Is this a good approach to achieve above problem? Or are there alternatives?

like image 765
mrtentje Avatar asked Dec 19 '12 21:12

mrtentje


2 Answers

Create an HTTP proxy and have your application go through that proxy. That way you can really intercept each request to Windows Azure Storage / Service Bus / ...

While AOP is a good solution, it won't fit your needs. Take the CloudBlob.UploadFile method for example. From an AOP perspective this is a single call, but if you look at the number of HTTP transactions this can be a lot more than 1 call (large files are chunked and sent over multiple HTTP requests).

That's why you need to use something low level like an HTTP proxy if you want to monitor all calls to Windows Azure services.

like image 125
Sandrino Di Mattia Avatar answered Oct 12 '22 11:10

Sandrino Di Mattia


You're referring to Aspect Oriented Programming (AOP.) AOP deals with intercepting dispatch messages between objects and their methods and properties. Logic may be executed that depends on the content of the calls.

Here's a question on AOP frameworks in .NET:

What is the best implementation for AOP in .Net?

like image 26
Dave Swersky Avatar answered Oct 12 '22 13:10

Dave Swersky