By default Retrace only tracks web transactions. However, it can be used to track non web transactions with some minor code changes. This article discusses tracking non web requests and could be applied to background work within a web app, a windows service, console app, or other types of service apps.
Note: You must first configure Retrace to know about and profile your application. By default Retrace only profiles IIS applications. Please review this article on how to tell it to profile your application: Enabling Retrace for non IIS applications
How it works
Tracking custom transactions is done by using the ProfilerTracer object within StackifyLib. This creates a defined operation from start to finish that can be named and tracked as a single operation.
Here is a simple code example:
Key considerations and potential problems
Stackify is designed to track individual transactions. So the transactions should be fairly short in length. Stackify's profiler works by tracking key methods within each thread of your application. If your application has a very long running thread in a loop that never finishes, it is possible that this collection of stack frames could grow continually and potentially use a lot of memory. A good example would be a section of code that is in a never ending loop that runs database queries.
We have built in upper limits to prevent memory from growing out of control. For some common libraries we have purposely added code around them to prevent and fix these endless loops. (Quartz and NServiceBus are good examples of this.) You can also prevent this in your own code by using our ProfileTracer object and creating operations. (ProfileTracer.CreateAsOperation) Anytime one of those operations ends, that section of collected stack frames will be processed and removed from memory.
If you are having problems getting profiling of a Windows Service to work correctly, feel free to reach out to our support team and will try to help. If the issue is in a 3rd party library we can also try and fix that too.
What can you track?
Retrace is great for web apps or background apps that do the same "transaction" continually. It isn't designed to track clicks in a desktop application. You can track events that run on a timer, events and more.
Note: You can also enable Retrace for self hosted WCF and Web API apps.
Job Scheduler like Quartz
At Stackify we use Quartz to process thousands of jobs an hour. Retrace gives us visibility in to knowing what the jobs are doing and how long they take. We automatically track some key methods around Quartz jobs so you don't need to StackifyLib.ProfileTracer for Quartz to define the scope of the operations. Instead, you only need to name the jobs by calling SetOperationName, otherwise we will show them all as "Quartz". We also recommend setting the CorrelationManager as shown below.
The below code example shows creating a base class that all of your jobs can use so you can put the code in a single place.
Processing queue messages
Processing messages off a queue is a perfect example where it makes sense to use Retrace. At Stackify we process millions of queue messages a day and Retrace keeps your queue processing from being a black box that you have no visibility to.
Below are code examples for using our ProfilerTracer with async code to process messages off a Azure Service Bus message pump.
Other event based transactions
There are a lot of scenarios of event based or scheduled services that could be tracked by Stackify. We have already covered a couple common ones like listening to a queue, or using a job scheduler like Quartz. However, there are many other types as well.
Some other examples:
- An app that waits for files to be dropped in a folder
- An app that utilizes some sort of custom sockets
- An SMTP mail server
- Azure Service Bus Relay