Code Instrumentation Tips

Many developers these days tend to neglect the importance of writing production-aware code, which could come back to bite them somewhere down the road. After all, programs are always written to run somewhere into production. We don’t want to delve too much into advanced topics such as aspect-oriented programming or aspect weaving, so we’re going to tackle four of the basic dimensions of code instrumentation, which also serve as examples of the best practices that should be followed by all software developers:

1. Tracing

Tracing is the first important element of code instrumentation. Adding traces to your code might be frowned upon by some developers because it could impact performance in some scenarios, but this is easily solved by adding different tracing levels that can be configured at runtime. Additionally, the benefit will outweigh the minimal performance hit.

Many developers favor debugging over tracing, but the problem with debugging is that the effort is rendered for naught once they close their development tool. Tracing, on the other hand, will allow developers to leverage the trace information and understand as well as address issues even well into production. Additionally, tracing’s benefits can be leveraged even by different developers who wish to contribute into a project somewhere down the line.

Click here and get FREE 6 MONTHS HOSTING. No credit card required.

2. Exception Handling

Exception handling is important in code instrumentation because exceptions usually occur in unanticipated scenarios or scenarios that require immediate attention. Addressing exceptions when they occur and providing information about data values is critical when supporting an application during production. So it is important to learn how to juggle the two priorities.

One good example of this is in Microsoft’s .NET framework, where exception handling will usually result in the loss of the stack trace information, which means there are cases where simply doing nothing is much wiser than catching the exception at the cost of reducing available information.

3. Performance Monitoring

Windows, for all the flak it gets, actually has a way of providing usual information with regard to performance and production time. There are performance counters directly integrated in the operating system since the days of Windows NT, and developers have the option of developing their own counters to monitor the relevant information via the associated Windows Event Viewer.

Investing in a performance counter is an easy yet practical way of gauging key areas for improvement over the various releases of your applications.

4. Data Gathering and Logging

Lastly, you can make it easier for people to support your project during production via logging some application-related data. A developer will generally know which critical data elements will be valuable when analyzing issues in production, so it is a smart move to log said data in a relevant place for the application.

At the end of the day, these four code instrumentation tips are not really that complex and can be understood even by novices. The only things preventing most developers from adopting them has more to do with discipline than skill.


Leave a Reply

You must be logged in to post a comment.