@Trace public User methodYouWantToTrace(String param1, String param2) { // ActiveSpan.setOperationName("Customize your own operation name, if this is an entry span, this would be an endpoint name"); // ... }
publicclassMain { publicstaticvoidmain(String[] args) { AbstractSpanmySpan= ContextManager.createEntrySpan("mySpan"); Runnablerunnable= () -> { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { thrownewRuntimeException(e); } // 3. Propagate the span to any other thread. // 4. Once the above steps are all set, call #asyncFinish in any thread. mySpan.asyncFinish();
}; // 1. Call #prepareForAsync in the original context. mySpan.prepareForAsync(); newThread(runnable).start(); // 2. Run ContextManager#stopSpan in the original context when your job in the current thread is complete. ContextManager.stopSpan(); } }
/** * Continue the context from the given snapshot of parent thread. * * @param snapshot from {@link #capture()} in the parent thread. Ref to {@link AbstractTracerContext#continued(ContextSnapshot)} */ @Override publicvoidcontinued(ContextSnapshot snapshot) { if (snapshot.isValid()) { TraceSegmentRefsegmentRef=newTraceSegmentRef(snapshot); this.segment.ref(segmentRef); this.activeSpan().ref(segmentRef); this.segment.relatedGlobalTrace(snapshot.getTraceId()); this.correlationContext.continued(snapshot); this.extensionContext.continued(snapshot); this.extensionContext.handle(this.activeSpan()); } }
/** * An {@link InstanceMethodsAroundInterceptor} This name should only stay in {@link String}, the real {@link Class} * type will trigger classloader failure. If you want to know more, please check on books about Classloader or * Classloader appointment mechanism. */ private InstanceMethodsAroundInterceptor interceptor;
/** * Intercept the target instance method. * * @param obj target class instance. * @param allArguments all method arguments * @param method method description. * @param zuper the origin call ref. * @return the return value of target instance method. * @throws Exception only throw exception because of zuper.call() or unexpected exception in sky-walking ( This is a * bug, if anything triggers this condition ). */ @RuntimeType public Object intercept(@This Object obj, @AllArguments Object[] allArguments, @SuperCall Callable<?> zuper, @Origin Method method)throws Throwable { EnhancedInstancetargetObject= (EnhancedInstance) obj;
// WARNING: the native code knows the name & signature of this method privatevoid loadClassAndCallPremain( String classname, String optionsString) throws Throwable {
// WARNING: the native code knows the name & signature of this method privatevoid loadClassAndCallAgentmain( String classname, String optionsString) throws Throwable {