Catalog

Plug in function : Customize and enhance any method in any class , So as to realize the monitoring of any method in any class .

Use

for instance , There is a class , The definition is as follows :

1
2
3
4
5
6
public class TestService1 {
public static void staticMethod(String str0, int count, Map m, List l, Object[] os) {
// Business logic
}
...
}

that , Want to monitor this method , You can do the following :

Move jar package

take optional-plugins/apm-customize-enhance-plugin-6.5.0.jar Move to plugins Catalog

Write enhancement rules

Create a file , It's called, for example customize_enhance.xml , The contents are as follows :

1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<enhanced>
<class class_name="test.apache.skywalking.testcase.customize.service.TestService1">
<method method="staticMethod(java.lang.String,int.class,java.util.Map,java.util.List,[Ljava.lang.Object;)" operation_name="/is_static_method_args" static="true">
<operation_name_suffix>arg[0]</operation_name_suffix>
<operation_name_suffix>arg[1]</operation_name_suffix>
<operation_name_suffix>arg[3].[0]</operation_name_suffix>
<tag key="tag_1">arg[2].['k1']</tag>
<tag key="tag_2">arg[4].[1]</tag>
<log key="log_1">arg[4].[2]</log>
</method>
</class>
</enhanced>

Rule description :

To configure explain
class_name Class to be enhanced
method Class interceptor method
operation_name If configured , It will be used instead of the default operation_name
operation_name_suffix It means that operation_name Add dynamic data after
static Whether the method is static
tag Will be in local span Add a tag.key The value of must be in XML The node represents .
log Will be in local span Add a log.key The value of must be in XML The node represents .
arg[x] Represents the input parameter value . such as args[0] Represents the first parameter .
.[x] When the object being parsed is Array or List, You can use this expression to get the corresponding index On the object .
.[‘key’] When the object being parsed is Map, You can use this expression to get map Of key.

One thing in particular to note method Writing :

  • Basic types : Basic types .class , for example : int.class

  • Non basic type : Fully qualified name of the class , for example :java.lang.String

  • Array : You can write an array and print it , You'll know the format , for example :

    1
    2
    3
    4
    5
    6
    7
    public static void main(String[] args) {
    String[] s = new String[]{};
    System.out.println(s);

    int [] x = new int []{};
    System.out.println(x);
    }

    result :

    1
    2
    [Ljava.lang.String;@1b0375b3
    [[email protected]2f7c7260

    therefore , about String An array of types , I can write this as [Ljava.lang.String; ; about int An array of types , It's written as [I .

To configure

agent.config Add configuration in :

1
plugin.customize.enhance_file=customize_enhance.xml The absolute path of 

Bonus ^_^

apm-trace-ignore-plugin

Related articles