Using Tags to catch unexpected bugs


Leo Ertuna - January 28, 2018 - 0 comments

MoSKito has many powerful features, it can monitor almost every aspect of your application, it is the worlds best open-source APM for Java. But sometimes all this functionality can be a bit overwhelming to the user, and you might run into some issues figuring out how monitor your app efficiently. To address this, and give you an example of problem solving with MoSKito, today we will give you an insight on a real life case of tracing bugs and optimizing your application using MoSKito.

Execution Tagging

MoSKito 2.8.5 release brings in some new and exciting tools! One of the newest features is the ability to tag an execution.

Tags can be auto-assigned like user-agent or IP. They can also be picked up from session or request attributes and parameters. By default when using tracers MoSKito will produce the following tags:

Now the really cool stuff with tags is that we can use almost anything as a tag! You can tag any parameter to any java method call by simply using @TagParameter(name = “tagName”) annotation in method declaration, right before the tagged parameter’s type. Of course you can do the same thing with any method’s return values as well, just use @TagReturnValue(name = “tagName”) before the method declaration. Here’s an example of how such annotated method might look like:

@TagReturnValue(name = "notificationId")
public String sendNotificationAboutOrder(String customerId, @TagParameter(name = "email") String email, String message)

Both the e-mail parameter and the notification id return value will be monitored by MoSKito and available in the system, auto-associated with any Journey or Error.

Don’t assume that you can use only strings as tags, you can tag any java object, for example Order.

@TagReturnValue(name = "order")
public Order placeOrder(@TagParameter(name = "customerId") String customerId, String... items)

This method will result in following tags when monitored with Tracer:

With the upcoming MoSKito 2.8.6 release we will bring even more robustness into tags. We will present you all the available tags in a nice UI overview, along with the tag values and its occurrences. And you will be able to add new tags on the fly as well.

If you currently have an older version of MoSKito Inspect you can still try out this new UI. You will have to edit moskito-inspect.json of your MoSKito Inspect and set betaMode parameter to true.

Catching Bugs with Tags

When tags are combined with tracers you can see not only where the peak loads in your application originate from, but you can observe what causes them. As programmers we unavoidably make mistakes, and the ability to see details of each method call proves to be highly useful when tracking down unexpected bugs.

In a recent case we run into an issue when some requests were causing huge CPU usage and taking up lots of execution time. After inspecting tags of these long-running requests we found that they all had one similarity – the used the same invalid zip-code. It turns out that the system was trying to find the best delivery options for a zip-code that simply doesn’t exist. And the possibility of having such invalid zip-codes was not exactly well tested.

Monitoring your app with MoSKito will not prevent you from having unexpected bugs sneak into your application, but it will sure make catching them a lot easier!

Post a Comment

Your email address will not be published.