yaojingguo opened a new issue #6625:
URL: https://github.com/apache/skywalking/issues/6625


   Please answer these questions before submitting your issue.
   
   - Why do you submit this issue?
   - [ ] Question or discussion
   - [ ] Bug
   - [x] Requirement
   - [ ] Feature or performance improvement
   ___
   # Requirement
   I want to pragmatically instrument Java code. There are possible two ways to 
do it. 
   
   ## gRPC API
   This approach uses gPRC API to report segments to the OAP server. This 
approach is similar to [go2sky]. But there is a problem with it. The spans 
create by gPRC API can be related to the spans created by the Java agent. 
Consider the following example:
   
   ```Java
   @GetMapping("/greeting")
   public String greeting() {
      foo();
      return "hello";
   }
   private void foo() {
      // Create a span B and report it to OAP server
   }
   ```
   Java agent creates an entry span A for the greeting method. There will be no 
ChildOf relation created between span A and span B  since Java agent and gRPC 
API do the instrument separately. In one word, this approach does not integrate 
well with the automatic instrument by Java agent.
   
   ## apm-toolkit-trace
   [apm-toolkit-trace] uses Java annotations to create tracing data such as 
span, log, and tag. For example, we can use `@Trace` annotation to create a 
span for bar method:
   
   ```Java
   @Trace
   public void bar() {
   }
   ```
   The problem is that I can't decide whether to create a span for bar at 
runtime. For example, I want to disable span creation for bar method by 
default. After I turn on some flag, I want to create spans for the invocation 
of the method bar.
   
   So the existing approaches do not solve my problem. I want to implement the 
following feature by extending apm-toolkit-trace module. My idea is to add the 
following APIs to  apm-toolkit-trace module (This API list is incomplete. If 
this design makes sense, I will make a complete API list for review):
   
   - createLoalSpan
   - createEntrySpan
   - createExitSpan
   - stopSpan
   
   The above methods essentially do the same thing as the aforementioned 
annotations. For example, createLoalSpan and stopSpan can do the same thing as 
`@Trace` annotation. In summary, my idea is to provide a programmatic interface 
for the functionalities which have existed in apm-toolkit-trace module.
   
   [go2sky]: https://github.com/SkyAPM/go2sky
   [apm-toolkit-trace]: 
https://github.com/apache/skywalking/blob/master/docs/en/setup/service-agent/java-agent/Application-toolkit-trace.md
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to