Create Custom Interceptors and Rules
Implement Your Instrumentation Logic
The iSDK provides a class called AGenericInterceptor
, which must be subclassed with the desired custom interceptor logic.
The agent examines .jar files deployed to the agent's sdk-plugins
directory and looks for classes that extend AGenericInterceptor
. These classes must implement the required abstract methods.
One key method all interceptors must implement is the initializeRules
method, which returns a list of objects that extend the IRule interface. These IRules represent where in the code you must apply a given interceptor (class name, method name, method params, and so on).
If interceptors need to perform reflection on any of the java objects used in the instrumented code, an interface, IReflector
, is provided to facilitate such reflection at runtime.
Important Methods to Implement in AGenericInterceptor
initializeRules
- Returns a list of objects that describe where in the code the interceptor must be placedonMethodBegin
- Any code in the body of this method is run before the execution of the instrumented methodonMethodEnd
- Any code in the body of this method is run after the execution of the instrumented method
AGenericInterceptors
can be combined with the Agent API to start or end transactions, add data to snapshots, and so on.These interceptors can be applied anywhere in the code, rather than just the beginning or end of a method. Also, they collect local variable information. Specific methods in the Rule builder, such as atLineNumber
, atField
, atLocalVariable
, and so on only apply to this variety of iSDK interceptor.
- jars placed directly in the top-level "sdk-plugins" directory are also loaded.
- You can use the manifest attribute "Plugin-Classes: <comma separated list of fully qualified class names>" in your plug-in jar to specify specific classes to load as plug-ins. This improves jar loading performance, if the plug-in jar contains many classes that are not plug-ins.