Please enable Javascript to view the contents

Opentelemetry Java Agent 浅度解构

 ·  ☕ 2 分钟

Agent initialization sequence

Agent classloader state

Conf

Creating spans around methods with otel.instrumentation.methods.include

Ref: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/manual-instrumentation.md

Format is "java -Dotel.instrumentation.methods.include=my.package.MyClass1[method1,method2];my.package.MyClass2[method3]"

Classloader

[arthas@16908]$ classloader -t
+-BootstrapClassLoader                                                                                                 
+-io.opentelemetry.javaagent.bootstrap.AgentClassLoader@379619aa                                                       
+-sun.misc.Launcher$ExtClassLoader@41fa769c                                                                            
  +-com.taobao.arthas.agent.ArthasClassloader@3697b340                                                                 
  +-sun.misc.Launcher$AppClassLoader@18b4aac2                                                                          
    +-java.net.URLClassLoader@71b2d611                                                                                 
    +-java.net.URLClassLoader@69cd1085                                                                                 
    | +-WebAppClassLoader=266661735@fe4ef67                                                                            
    | | +-com.mycom.sig.foundation.servicediscovery.ExtendedClassLoader@573f7aae                                    
    | +-WebAppClassLoader=Server Initiated@1ccb04b3                                                                    
    | | +-com.mycom.sig.foundation.servicediscovery.ExtendedClassLoader@4b3b9a06                                    
    | | +-jnr.ffi.provider.jffi.AsmClassLoader@73cb9ccb                                                                
    | | +-jnr.ffi.provider.jffi.AsmClassLoader@7c380e94                                                                
    | | +-jnr.ffi.provider.jffi.AsmClassLoader@69ec5d1f                                                                
    | +-WebAppClassLoader=OAuth Server@10d98940                                                                        
    | | +-com.mycom.ece.common.svcfinder.ExtendedClassLoader@3528968e                                               
    | | +-com.mycom.sig.foundation.servicediscovery.ExtendedClassLoader@2919aff3                                    
    | | +-jnr.ffi.provider.jffi.AsmClassLoader@1b0e6bac                                                                
    | | +-jnr.ffi.provider.jffi.AsmClassLoader@2f12d8d1                                                                
    | | +-jnr.ffi.provider.jffi.AsmClassLoader@73123f21                                                                
    | +-WebAppClassLoader=1133988396@43974a2c                                                                          
    |   +-com.mycom.sig.foundation.servicediscovery.ExtendedClassLoader@39d87c5f                                    
    +-java.net.URLClassLoader@1b4c457c                                                                                 
    +-java.net.URLClassLoader@3a477cf5                                                                                 
Affect(row-cnt:24) cost in 31 ms.

[arthas@16908]$ classloader
 name                                                              numberOfInstances  loadedCountTotal                 
 org.eclipse.jetty.webapp.WebAppClassLoader                        4                  24687                            
 BootstrapClassLoader                                              1                  4341                             
 io.opentelemetry.javaagent.bootstrap.AgentClassLoader             1                  3502                             
 com.taobao.arthas.agent.ArthasClassloader                         1                  1430                             
 java.net.URLClassLoader                                           4                  1252                             
 sun.misc.Launcher$AppClassLoader                                  1                  570                              
 sun.reflect.DelegatingClassLoader                                 378                378                              
 sun.misc.Launcher$ExtClassLoader                                  1                  56                               
 jnr.ffi.provider.jffi.AsmClassLoader                              6                  8                                
 com.mycom.sig.foundation.servicediscovery.ExtendedClassLoader  4                  6                                
 com.mycom.ece.common.svcfinder.ExtendedClassLoader             1                  1  
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[arthas@16908]$ jad -c 1ccb04b3 com.mycom.jee.iam.client.service.payload.ClientResponse setProjectName

ClassLoader:                                                                                                           
+-WebAppClassLoader=Server Initiated@1ccb04b3                                                                          
  +-java.net.URLClassLoader@69cd1085                                                                                   
    +-sun.misc.Launcher$AppClassLoader@18b4aac2                                                                        
      +-sun.misc.Launcher$ExtClassLoader@41fa769c                                                                      

Location:                                                                                                              
/var/lib/modules/DP-OAuth-Traffic/tmp/server-initiated-aa-war.war/webapp/WEB-INF/lib/clients-api-3.19.5.jar            

            public void setProjectName(String string) {                                                                
                StackTraceElement[] stackTraceElementArray;
/*729*/         Context context = null;                                                                                
                Scope scope = null;               
                try {                                                                                                  
                    stackTraceElementArray = Thread.currentThread().getStackTrace();                                                                                                                                                          
                    context = MethodTracer.tracer().startSpan(ClientResponse.class.getMethod("setProjectName", String.class), stackTraceElementArray, new Object[]{string});
                    if (context != null) {
                        scope = context.makeCurrent();
                    }
                }
                catch (Throwable throwable) {
                    try {
                        LoggerFactory.getLogger(ExceptionLogger.class).debug("Failed to handle exception in instrumentation for com.mycom.jee.iam.client.service.payload.ClientResponse on sun.misc.Launcher$AppClassLoader@18b4aac2", thr$
wable);
                    }
                    catch (Throwable throwable2) {
                    }
                }
                stackTraceElementArray = this;
                String projectName = string;
                try {
                    this.projectName = projectName;
                    stackTraceElementArray = null;
                }
                catch (Throwable throwable) {
                    // empty catch block
                }
                try {
                    if (context != null) {
                        scope.close();
                        if (stackTraceElementArray != null) {
                            MethodTracer.tracer().endExceptionally(context, (Throwable)stackTraceElementArray);
                        } else {
                            Span span = Span.fromContext(context);
                            span.setAttribute(MethodTracer.JAVA_METHOD_RETURN.getKey(), null == null ? "null" : ((Object)null).toString());
                            MethodTracer.tracer().end(context);
                        }
                    }
                }
                catch (Throwable throwable) {
                    try {
                        LoggerFactory.getLogger(ExceptionLogger.class).debug("Failed to handle exception in instrumentation for com.mycom.jee.iam.client.service.payload.ClientResponse on sun.misc.Launcher$AppClassLoader@18b4aac2", thro
wable);
                    }
                    catch (Throwable throwable3) {
                    }
                }
                if (stackTraceElementArray != null) {
                    throw stackTraceElementArray;
                }
            }

[arthas@16908]$ sc io.opentelemetry.javaagent.instrumentation.methods.MethodInstrumentationModule
io.opentelemetry.javaagent.instrumentation.methods.MethodInstrumentationModule
Affect(row-cnt:1) cost in 54 ms.
[arthas@16908]$ sc -d io.opentelemetry.javaagent.instrumentation.methods.MethodInstrumentationModule
 class-info        io.opentelemetry.javaagent.instrumentation.methods.MethodInstrumentationModule                      
 code-source       /                                                                                                   
 name              io.opentelemetry.javaagent.instrumentation.methods.MethodInstrumentationModule                      
 isInterface       false                                                                                               
 isAnnotation      false                                                                                               
 isEnum            false                                                                                               
 isAnonymousClass  false                                                                                               
 isArray           false                                                                                               
 isLocalClass      false                                                                                               
 isMemberClass     false                                                                                               
 isPrimitive       false                                                                                               
 isSynthetic       false                                                                                               
 simple-name       MethodInstrumentationModule                                                                         
 modifier          public                                                                                              
 annotation                                                                                                            
 interfaces                                                                                                            
 super-class       +-io.opentelemetry.javaagent.tooling.InstrumentationModule                                          
                     +-java.lang.Object                                                                                
 class-loader      +-io.opentelemetry.javaagent.bootstrap.AgentClassLoader@379619aa                                    
 classLoaderHash   379619aa 
[arthas@16908]$ sc -d io.opentelemetry.javaagent.instrumentation.methods.MethodTracer
 class-info        io.opentelemetry.javaagent.instrumentation.methods.MethodTracer                                     
 code-source                                                                                                           
 name              io.opentelemetry.javaagent.instrumentation.methods.MethodTracer                                     
 isInterface       false                                                                                               
 isAnnotation      false                                                                                               
 isEnum            false                                                                                               
 isAnonymousClass  false                                                                                               
 isArray           false                                                                                               
 isLocalClass      false                                                                                               
 isMemberClass     false                                                                                               
 isPrimitive       false                                                                                               
 isSynthetic       false                                                                                               
 simple-name       MethodTracer                                                                                        
 modifier          public                                                                                              
 annotation                                                                                                            
 interfaces                                                                                                            
 super-class       +-io.opentelemetry.javaagent.shaded.instrumentation.api.tracer.BaseTracer                           
                     +-java.lang.Object                                                                                
 class-loader      +-WebAppClassLoader=Server Initiated@1ccb04b3                                                       
                     +-java.net.URLClassLoader@69cd1085                                                                
                       +-sun.misc.Launcher$AppClassLoader@18b4aac2                                                     
                         +-sun.misc.Launcher$ExtClassLoader@41fa769c                                                   
 classLoaderHash   1ccb04b3                                                                                            

 class-info        io.opentelemetry.javaagent.instrumentation.methods.MethodTracer                                     
 code-source                                                                                                           
 name              io.opentelemetry.javaagent.instrumentation.methods.MethodTracer                                     
 isInterface       false                                                                                               
 isAnnotation      false                                                                                               
 isEnum            false                                                                                               
 isAnonymousClass  false                                                                                               
 isArray           false                                                                                               
 isLocalClass      false                                                                                               
 isMemberClass     false                                                                                               
 isPrimitive       false                                                                                               
 isSynthetic       false                                                                                               
 simple-name       MethodTracer                                                                                        
 modifier          public                                                                                              
 annotation                                                                                                            
 interfaces                                                                                                            
 super-class       +-io.opentelemetry.javaagent.shaded.instrumentation.api.tracer.BaseTracer                           
                     +-java.lang.Object                                                                                
 class-loader      +-WebAppClassLoader=OAuth Server@10d98940                                                           
                     +-java.net.URLClassLoader@69cd1085                                                                
                       +-sun.misc.Launcher$AppClassLoader@18b4aac2                                                     
                         +-sun.misc.Launcher$ExtClassLoader@41fa769c                                                   
 classLoaderHash   10d98940                                                                                            

shaded

io.opentelemetry.instrumentation.api.config.Config
->
sc -d io.opentelemetry.javaagent.shaded.instrumentation.api.config.Config

[arthas@16908]$ sc -d io.opentelemetry.javaagent.shaded.instrumentation.api.config.Config                                                                                            

 class-info        io.opentelemetry.javaagent.shaded.instrumentation.api.config.Config                                 
 code-source                                                                                                           
 name              io.opentelemetry.javaagent.shaded.instrumentation.api.config.Config                                 
 isInterface       false                                                                                               
 isAnnotation      false                                                                                               
 isEnum            false                                                                                               
 isAnonymousClass  false                                                                                               
 isArray           false                                                                                               
 isLocalClass      false                                                                                               
 isMemberClass     false                                                                                               
 isPrimitive       false                                                                                               
 isSynthetic       false                                                                                               
 simple-name       Config                                                                                              
 modifier          abstract,public                                                                                     
 annotation                                                                                                            
 interfaces                                                                                                            
 super-class       +-java.lang.Object                                                                                  
 class-loader                                                                                                          
 classLoaderHash   null 
分享

Mark Zhu
作者
Mark Zhu
Old Developer