skywalking-java/docs/en/setup/service-agent/java-agent
Gong Dewei 267aba8fad
Improve bytebuddy class enhance for retransform classes (#561)
* SWAuxiliaryTypeNamingStrategy
Auxiliary type name pattern: <origin_class_name>$<name_trait>$auxiliary$<auxiliary_type_instance_hash>

* DelegateNamingResolver
Interceptor delegate field name pattern: <name_trait>$delegate$<class_name_hash>$<plugin_define_hash>$<intercept_point_hash>

* SWMethodNameTransformer
Renamed origin method pattern: <name_trait>$original$<method_name>$<method_description_hash>

* SWImplementationContextFactory
Method cache value field pattern: cachedValue$<name_trait>$<origin_class_name_hash>$<field_value_hash>
Accessor method name pattern:  <renamed_origin_method>$accessor$<name_trait>$<origin_class_name_hash>

Here is an example of manipulated enhanced class with new naming policies of auxiliary classes, fields, and methods

```java
 import sample.mybatis.controller.HotelController$sw$auxiliary$19cja42;
 import sample.mybatis.controller.HotelController$sw$auxiliary$p257su0;
 import sample.mybatis.domain.Hotel;
 import sample.mybatis.service.HotelService;

 @RequestMapping(value={"/hotel"})
 @RestController
 public class HotelController
 implements EnhancedInstance {
     @Autowired
     @Lazy
     private HotelService hotelService;
     private volatile Object _$EnhancedClassField_ws;

     // Interceptor delegate fields
     public static volatile /* synthetic */ InstMethodsInter sw$delegate$td03673$ain2do0$8im5jm1;
     public static volatile /* synthetic */ InstMethodsInter sw$delegate$td03673$ain2do0$edkmf61;
     public static volatile /* synthetic */ ConstructorInter sw$delegate$td03673$ain2do0$qs9unv1;
     public static volatile /* synthetic */ InstMethodsInter sw$delegate$td03673$fl4lnk1$m3ia3a2;
     public static volatile /* synthetic */ InstMethodsInter sw$delegate$td03673$fl4lnk1$sufrvp1;
     public static volatile /* synthetic */ ConstructorInter sw$delegate$td03673$fl4lnk1$cteu7s1;

     // Origin method cache value field
     private static final /* synthetic */ Method cachedValue$sw$td03673$g5sobj1;

     public HotelController() {
         this(null);
         sw$delegate$td03673$ain2do0$qs9unv1.intercept(this, new Object[0]);
     }

     private /* synthetic */ HotelController(sw.auxiliary.p257su0 p257su02) {
     }

     @GetMapping(value={"city/{cityId}"})
     public Hotel selectByCityId(@PathVariable(value="cityId") int n) {
         // call interceptor with auxiliary type and parameters and origin method object
         return (Hotel)sw$delegate$td03673$ain2do0$8im5jm1.intercept(this, new Object[]{n}, new HotelController$sw$auxiliary$19cja42(this, n), cachedValue$sw$td03673$g5sobj1);
     }

     // Renamed origin method
     private /* synthetic */ Hotel sw$origin$selectByCityId$a8458p3(int cityId) {
/*22*/         return this.hotelService.selectByCityId(cityId);
     }

     // Accessor of renamed origin method, calling from auxiliary type
     final /* synthetic */ Hotel sw$origin$selectByCityId$a8458p3$accessor$sw$td03673(int n) {
         // Calling renamed origin method
         return this.sw$origin$selectByCityId$a8458p3(n);
     }

     @Override
     public Object getSkyWalkingDynamicField() {
         return this._$EnhancedClassField_ws;
     }

     @Override
     public void setSkyWalkingDynamicField(Object object) {
         this._$EnhancedClassField_ws = object;
     }

     static {
         ClassLoader.getSystemClassLoader().loadClass("org.apache.skywalking.apm.dependencies.net.bytebuddy.dynamic.Nexus").getMethod("initialize", Class.class, Integer.TYPE).invoke(null, HotelController.class, -1072476370);
         // Method object
         cachedValue$sw$td03673$g5sobj1 = HotelController.class.getMethod("selectByCityId", Integer.TYPE);
     }
 }
```

Auxiliary type of Constructor : 
```java
class HotelController$sw$auxiliary$p257su0 {
}
```

Auxiliary type of  `selectByCityId` method: 
```java
class HotelController$sw$auxiliary$19cja42
implements Runnable,
Callable {
    private HotelController argument0;
    private int argument1;

    public Object call() throws Exception {
        return this.argument0.sw$origin$selectByCityId$a8458p3$accessor$sw$td03673(this.argument1);
    }

    @Override
    public void run() {
        this.argument0.sw$origin$selectByCityId$a8458p3$accessor$sw$td03673(this.argument1);
    }

    HotelController$sw$auxiliary$19cja42(HotelController hotelController, int n) {
        this.argument0 = hotelController;
        this.argument1 = n;
    }
}
```
2023-06-24 20:50:10 +08:00
..
agent-optional-plugins Update trace-ignore-plugin.md (#452) 2023-02-07 12:00:31 +08:00
Application-toolkit-dependency.md Polish docs for preparing release. (#490) 2023-03-29 11:21:50 +08:00
Application-toolkit-kafka.md Support mannual propagation of tracing context to next stream for webflux. (#371) 2022-11-03 14:41:45 +08:00
Application-toolkit-log4j-1.x.md Add Kafka LogReporter and make grpc log reporter sharing grpc channel with reporters (#20) 2021-09-23 10:50:34 +08:00
Application-toolkit-log4j-2.x.md Support `-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector` in gRPC log report. (#182) 2022-05-22 13:56:29 +08:00
Application-toolkit-logback-1.x.md Add Kafka LogReporter and make grpc log reporter sharing grpc channel with reporters (#20) 2021-09-23 10:50:34 +08:00
Application-toolkit-meter.md Doc polish, remove unrelated documents and fix source code LICENSE (#5) 2021-08-27 10:08:36 +08:00
Application-toolkit-micrometer-1.10.md Adds Micrometer Observation instrumentation (#401) 2022-12-06 18:51:12 +08:00
Application-toolkit-micrometer.md Adds Micrometer Observation instrumentation (#401) 2022-12-06 18:51:12 +08:00
Application-toolkit-trace-annotation.md Expose complete Tracing APIs in the tracing toolkit (#442) 2023-01-24 08:01:18 +08:00
Application-toolkit-trace-correlation-context.md Polish docs for preparing release. (#490) 2023-03-29 11:21:50 +08:00
Application-toolkit-trace-cross-thread.md Polish docs for preparing release. (#490) 2023-03-29 11:21:50 +08:00
Application-toolkit-trace-read-context.md Polish docs for preparing release. (#490) 2023-03-29 11:21:50 +08:00
Application-toolkit-trace.md Correct missing package name in native manual API docs. (#449) 2023-02-03 22:09:56 +08:00
Application-toolkit-tracer.md Correct missing package name in native manual API docs. (#449) 2023-02-03 22:09:56 +08:00
Application-toolkit-webflux.md Support mannual propagation of tracing context to next stream for webflux. (#371) 2022-11-03 14:41:45 +08:00
Bootstrap-plugins.md Support forkjoinpool plugin (#505) 2023-04-17 17:45:09 +08:00
Customize-enhance-trace.md Enhance `returnedObj` expression to support Array, List and Map (#84) 2021-12-15 15:00:22 +08:00
How-to-disable-plugin.md Finish the new document structure. 2018-07-08 21:04:50 -07:00
How-to-tolerate-exceptions.md Fix wrong dependency in doc for IgnoredException (#69) 2021-11-09 10:16:51 +08:00
Java-Plugin-Development-Guide.md Polish up kafka,nats,activemq,rabbitmq plugins to set peer at comsumer side (#377) 2022-11-06 18:57:19 +08:00
Opentracing.md Polish docs for preparing release. (#490) 2023-03-29 11:21:50 +08:00
Optional-plugins.md Add plugin for Spring 6, set development baseline to JDK 17, remove Powermock entirely (#444) 2023-01-31 19:29:32 +08:00
Plugin-list.md add RocketMQ 5.x plugin (#536) 2023-06-07 22:05:08 +08:00
Plugin-test.md Upgrade agent-test-tools and polish dubbo plugin (#387) 2022-11-19 16:27:25 +08:00
README.md Add JDK17 supported declaration. (#52) 2021-10-16 20:40:42 +08:00
Setting-override.md feat:Active System.env Config In Both Collector And agent.config. (#1957) 2018-11-26 00:12:01 +08:00
Specified-agent-config.md Add the function of the specified agent config 2018-08-25 21:41:42 +08:00
Supported-list.md add RocketMQ 5.x plugin (#536) 2023-06-07 22:05:08 +08:00
TLS.md Support mTLS for gRPC channel (#15) 2021-08-31 15:56:30 +08:00
Token-auth.md Doc polish, remove unrelated documents and fix source code LICENSE (#5) 2021-08-27 10:08:36 +08:00
advanced-features.md Adds Micrometer Observation instrumentation (#401) 2022-12-06 18:51:12 +08:00
advanced-reporters.md [Feature] Support to configure custom decode method for kafka configurations (#540) 2023-05-31 18:03:35 +08:00
configuration-discovery.md Add `plugin.jdbc.trace_sql_parameters` into Configuration Discovery S… (#174) 2022-05-30 20:42:30 +08:00
configurations.md Improve bytebuddy class enhance for retransform classes (#561) 2023-06-24 20:50:10 +08:00
containerization.md add java agent injector link (#112) 2022-02-27 18:56:33 +08:00
logic-endpoint.md Separate agent docs to avoid long single page. (#7537) 2021-08-23 20:10:01 +08:00

README.md

Setup java agent

  1. Agent is available for JDK 8 - 17.
  2. Find agent folder in SkyWalking release package
  3. Set agent.service_name in config/agent.config. Could be any String in English.
  4. Set collector.backend_service in config/agent.config. Default point to 127.0.0.1:11800, only works for local backend.
  5. Add -javaagent:/path/to/skywalking-package/agent/skywalking-agent.jar to JVM argument. And make sure to add it before the -jar argument.

The agent release dist is included in Apache official release. New agent package looks like this.

+-- agent
    +-- activations
         apm-toolkit-log4j-1.x-activation.jar
         apm-toolkit-log4j-2.x-activation.jar
         apm-toolkit-logback-1.x-activation.jar
         ...
    +-- config
         agent.config  
    +-- plugins
         apm-dubbo-plugin.jar
         apm-feign-default-http-9.x.jar
         apm-httpClient-4.x-plugin.jar
         .....
    +-- optional-plugins
         apm-gson-2.x-plugin.jar
         .....
    +-- bootstrap-plugins
         jdk-http-plugin.jar
         .....
    +-- logs
    skywalking-agent.jar
  • Start your application.

Install javaagent FAQs

  • Linux Tomcat 7, Tomcat 8, Tomcat 9
    Change the first line of tomcat/bin/catalina.sh.
CATALINA_OPTS="$CATALINA_OPTS -javaagent:/path/to/skywalking-agent/skywalking-agent.jar"; export CATALINA_OPTS
  • Windows Tomcat 7, Tomcat 8, Tomcat 9
    Change the first line of tomcat/bin/catalina.bat.
set "CATALINA_OPTS=-javaagent:/path/to/skywalking-agent/skywalking-agent.jar"
  • JAR file
    Add -javaagent argument to command line in which you start your app. eg:
java -javaagent:/path/to/skywalking-agent/skywalking-agent.jar -jar yourApp.jar
  • Jetty
    Modify jetty.sh, add -javaagent argument to command line in which you start your app. eg:
export JAVA_OPTIONS="${JAVA_OPTIONS} -javaagent:/path/to/skywalking-agent/skywalking-agent.jar"

Plugins

SkyWalking agent has supported various middlewares, frameworks and libraries. Read supported list to get them and supported version. If the plugin is in Optional² catalog, go to optional plugins and bootstrap class plugin section to learn how to active it.

  • All plugins in /plugins folder are active. Remove the plugin jar, it disabled.
  • The default logging output folder is /logs.