Custom instrumentation and exception tracking via the Ruby Agent API
APM Insight's Ruby Agent is capable of identifying default methods and classes from multiple application frameworks. The agent automatically tracks identified methods and additional metrics, but, in some cases, performance data on these methods may not be enough to debug issues. When you need additional application-specific information to resolve an issue, you can use our API to collect application-specific metrics.
Track additional methods:
By default, the Ruby Agent only captures framework classes like Controllers, DB queries, and Views. You can use custom instrumentation to monitor other application-specific methods.
To get started, specify the methods to be instrumented in the application initializer, as shown below. Then create a new file named s247_instrumentation.rb under config/initializers/.
This gives you in-depth details to troubleshoot and debug issues with your applications.
Syntax:
require 'agent/api/custom_tracker'
MyClass.class_eval do
include ::APMInsight::API::CustomTracker
track_method :my_method1
track_method :my_method2
end
Example:
require 'agent/api/custom_tracker'
ProjectsController.class_eval do
include ::APMInsight::API::CustomTracker
track_method :get_internal
end
Output:
APM > Application/Instance > Web transactions > Traces
Tracking exceptions via the API
The Ruby Agent is capable of capturing exceptions occurring in known framework methods. However, the agent can't track user-defined exceptions occurring in your application. In such cases, you can use the agent API to push exception data to Site24x7's server via the agent.
First, add the API in the application wherever necessary. Once the app server is started, the agent will capture the exceptions when they occur, automatically associate them with the current transaction, and push those exceptions to Site24x7's servers. This helps you track all exceptions from one place.
Syntax:
require 'agent/api/custom_tracker'
APMInsight::API::CustomTracker.trackException(exception_object)
Example:
require 'agent/api/custom_tracker'
... # Other declarations and definitions
def find_value
begin
.... # some instructions
rescue => ex
APMInsight::API::CustomTracker.trackException(ex)
.... # rescue operations
end
end
Output:
APM > Application/Instance > Web transactions > Traces