Fix opentracing-toolkit activation compile issue, and useless codes.
This commit is contained in:
parent
47871d1571
commit
bfa53127fb
|
|
@ -54,7 +54,7 @@ public class Span {
|
|||
private final List<LogData> logs;
|
||||
|
||||
/**
|
||||
* Create a new span, by given span id and parent span id.
|
||||
* Create a new span, by given span id, parent span id and operationName.
|
||||
* This span must belong a {@link TraceSegment}, also is a part of Distributed Trace.
|
||||
*
|
||||
* @param spanId given by the creator, and must be unique id in the {@link TraceSegment}
|
||||
|
|
@ -63,9 +63,23 @@ public class Span {
|
|||
* @param operationName {@link #operationName}
|
||||
*/
|
||||
private Span(int spanId, int parentSpanId, String operationName) {
|
||||
this(spanId, parentSpanId, operationName, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
*Create a new span, by given span id, parent span id, operationName and startTime.
|
||||
* This span must belong a {@link TraceSegment}, also is a part of Distributed Trace.
|
||||
*
|
||||
* @param spanId given by the creator, and must be unique id in the {@link TraceSegment}
|
||||
* @param parentSpanId given by the creator, and must be an existed span id in the {@link TraceSegment}. Value -1
|
||||
* means no parent span if this {@link TraceSegment}.
|
||||
* @param operationName {@link #operationName}
|
||||
* @param startTime given start timestamp.
|
||||
*/
|
||||
private Span(int spanId, int parentSpanId, String operationName, long startTime){
|
||||
this.spanId = spanId;
|
||||
this.parentSpanId = parentSpanId;
|
||||
this.startTime = System.currentTimeMillis();
|
||||
this.startTime = startTime;
|
||||
this.operationName = operationName;
|
||||
this.tags = new HashMap<String, Object>();
|
||||
this.logs = new ArrayList<LogData>();
|
||||
|
|
@ -82,6 +96,19 @@ public class Span {
|
|||
this(spanId, -1, operationName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Create a new span, by given span id and give startTime but no parent span id,
|
||||
* No parent span id means that, this Span is the first span of the {@link TraceSegment}
|
||||
*
|
||||
* @param spanId given by the creator, and must be unique id in the {@link TraceSegment}
|
||||
* @param operationName {@link #operationName}
|
||||
* @param startTime given start time of span
|
||||
*/
|
||||
public Span(int spanId, String operationName, long startTime) {
|
||||
this(spanId, -1, operationName, startTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new span, by given span id and given parent {@link Span}.
|
||||
*
|
||||
|
|
@ -90,7 +117,18 @@ public class Span {
|
|||
* @param operationName {@link #operationName}
|
||||
*/
|
||||
public Span(int spanId, Span parentSpan, String operationName) {
|
||||
this(spanId, parentSpan.spanId, operationName);
|
||||
this(spanId, parentSpan.spanId, operationName, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param spanId
|
||||
* @param parentSpan
|
||||
* @param operationName
|
||||
* @param startTime
|
||||
*/
|
||||
public Span(int spanId, Span parentSpan, String operationName, long startTime) {
|
||||
this(spanId, parentSpan.spanId, operationName, startTime);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -100,12 +138,36 @@ public class Span {
|
|||
* @param owner of the Span.
|
||||
*/
|
||||
public void finish(TraceSegment owner) {
|
||||
this.endTime = System.currentTimeMillis();
|
||||
this.finish(owner, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish the active Span.
|
||||
* When it is finished, it will be archived by the given {@link TraceSegment}, which owners it.
|
||||
* At the same out, set the {@link #endTime} as the given endTime
|
||||
*
|
||||
* @param owner of the Span.
|
||||
* @param endTime of the Span.
|
||||
*/
|
||||
public void finish(TraceSegment owner, long endTime){
|
||||
this.endTime = endTime;
|
||||
owner.archive(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string name for the logical operation this span represents.
|
||||
*
|
||||
* @return this Span instance, for chaining
|
||||
*/
|
||||
public Span setOperationName(String operationName){
|
||||
this.operationName = operationName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a key:value tag on the Span.
|
||||
*
|
||||
* @return this Span instance, for chaining
|
||||
*/
|
||||
public final Span setTag(String key, String value) {
|
||||
tags.put(key, value);
|
||||
|
|
|
|||
|
|
@ -46,11 +46,6 @@
|
|||
<artifactId>skywalking-logging-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
<artifactId>disruptor</artifactId>
|
||||
<version>3.3.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@ public enum ContextManager implements TracerContextListener {
|
|||
return get().createSpan(operationName);
|
||||
}
|
||||
|
||||
public Span createSpan(String operationName, long startTime) {
|
||||
return get().createSpan(operationName);
|
||||
}
|
||||
|
||||
public Span activeSpan() {
|
||||
return get().activeSpan();
|
||||
}
|
||||
|
|
@ -65,6 +69,10 @@ public enum ContextManager implements TracerContextListener {
|
|||
get().stopSpan(span);
|
||||
}
|
||||
|
||||
public void stopSpan(Long endTime) {
|
||||
get().stopSpan(activeSpan(), endTime);
|
||||
}
|
||||
|
||||
public void stopSpan() {
|
||||
stopSpan(activeSpan());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,12 +40,23 @@ public final class TracerContext {
|
|||
* @return the new active span.
|
||||
*/
|
||||
public Span createSpan(String operationName) {
|
||||
return this.createSpan(operationName, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new span, as an active span, by the given operationName and startTime;
|
||||
*
|
||||
* @param operationName {@link Span#operationName}
|
||||
* @param startTime {@link Span#startTime}
|
||||
* @return
|
||||
*/
|
||||
public Span createSpan(String operationName, long startTime){
|
||||
Span parentSpan = peek();
|
||||
Span span;
|
||||
if (parentSpan == null) {
|
||||
span = new Span(spanIdGenerator++, operationName);
|
||||
span = new Span(spanIdGenerator++, operationName, startTime);
|
||||
} else {
|
||||
span = new Span(spanIdGenerator++, parentSpan, operationName);
|
||||
span = new Span(spanIdGenerator++, parentSpan, operationName, startTime);
|
||||
}
|
||||
push(span);
|
||||
return span;
|
||||
|
|
@ -68,9 +79,13 @@ public final class TracerContext {
|
|||
* @param span to finish. It must the the top element of {@link #activeSpanStack}.
|
||||
*/
|
||||
public void stopSpan(Span span) {
|
||||
stopSpan(span, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void stopSpan(Span span, Long endTime){
|
||||
Span lastSpan = peek();
|
||||
if (lastSpan == span) {
|
||||
segment.archive(pop());
|
||||
pop().finish(segment, endTime);
|
||||
} else {
|
||||
throw new IllegalStateException("Stopping the unexpected span = " + span);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.noneOf;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,36 +1,32 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.invoke.monitor.LocalMethodInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import java.util.Map;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpan;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
* Intercept these following methods:
|
||||
* {@link SkyWalkingSpan#finish()}
|
||||
* {@link SkyWalkingSpan#finish(long)}
|
||||
*/
|
||||
public class SpanFinishInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
Span currentSpan = Tracing.getCurrentSpan();
|
||||
Object[] allArguments = interceptorContext.allArguments();
|
||||
|
||||
Map<String, String> tags = (Map<String, String>) context.get("tags");
|
||||
if (tags != null) {
|
||||
for (Map.Entry<String, String> entry : tags.entrySet()) {
|
||||
Tracing.tag(currentSpan, entry.getKey(), entry.getValue());
|
||||
}
|
||||
if(allArguments.length == 1) {
|
||||
ContextManager.INSTANCE.stopSpan(((Long)allArguments[0]));
|
||||
}else{
|
||||
ContextManager.INSTANCE.stopSpan();
|
||||
}
|
||||
|
||||
new LocalMethodInvokeMonitor().afterInvoke();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,28 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpan;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangxin
|
||||
* Intercept {@link SkyWalkingSpan} constructor.
|
||||
*/
|
||||
public class SpanNewInstanceInterceptor implements InstanceConstructorInterceptor {
|
||||
|
||||
private static final String OPERATION_NAME = "operationName";
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
context.set(OPERATION_NAME, interceptorContext.allArguments()[0]);
|
||||
Object[] allArguments = interceptorContext.allArguments();
|
||||
String operationName = ((String)allArguments[0]);
|
||||
long startTime = ((Long)allArguments[1]);
|
||||
Map<String, String> tags = ((Map<String, String>)allArguments[2]);
|
||||
Span span = ContextManager.INSTANCE.createSpan(operationName, startTime);
|
||||
|
||||
for (Map.Entry<String, String> entry : tags.entrySet()) {
|
||||
span.setTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpan;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
* Intercept {@link SkyWalkingSpan#setOperationName(String)}
|
||||
*/
|
||||
public class SpanSetOperationNameInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
private static final String OPERATION_NAME = "operationName";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
context.set(OPERATION_NAME, interceptorContext.allArguments()[0]);
|
||||
String operationName = (String)interceptorContext.allArguments()[0];
|
||||
ContextManager.INSTANCE.activeSpan().setOperationName(operationName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,39 +1,42 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpan;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
* Intercept these following methods:
|
||||
* {@link SkyWalkingSpan#setTag(String, boolean)}
|
||||
* {@link SkyWalkingSpan#setTag(String, Number)}
|
||||
* {@link SkyWalkingSpan#setTag(String, String)}
|
||||
*/
|
||||
public class SpanSetTagInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
private static final String TAGS = "tags";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
Map<String, String> contextTags = (Map<String, String>) context.get(TAGS);
|
||||
if (!context.isContain(TAGS)){
|
||||
contextTags = new HashMap<String, String>();
|
||||
context.set(TAGS, contextTags);
|
||||
}
|
||||
|
||||
contextTags.put((String) interceptorContext.allArguments()[0], String.valueOf(interceptorContext
|
||||
.allArguments()[1]));
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
String key = (String)interceptorContext.allArguments()[0];
|
||||
Object value = interceptorContext.allArguments()[1];
|
||||
if (value instanceof String)
|
||||
ContextManager.INSTANCE.activeSpan().setTag(key, (String)value);
|
||||
else if (value instanceof Boolean)
|
||||
ContextManager.INSTANCE.activeSpan().setTag(key, (Boolean)value);
|
||||
else if (value instanceof Number)
|
||||
ContextManager.INSTANCE.activeSpan().setTag(key, (Number)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
|
||||
/**
|
||||
* @author zhangxin
|
||||
*/
|
||||
public enum OpenTracingLocalBuriedPointType implements IBuriedPointType {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "OT";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.LOCAL;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
*/
|
||||
public class SkyWalkingSpanBuilderActivation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpanBuilder";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[]{
|
||||
new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getConstructorMatcher() {
|
||||
return takesArguments(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor.SpanBuilderNewInstanceInterceptor";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("withTag");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor.SpanBuilderWithTagInterceptor";
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("withStartTimestamp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor.SpanBuilderWithStartTimeInterceptor";
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("start");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor.SpanBuilderStartInterceptor";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
|
||||
public class SpanBuilderNewInstanceInterceptor implements InstanceConstructorInterceptor {
|
||||
|
||||
public static final String OPERATION_NAME = "operationName";
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
context.set(OPERATION_NAME, interceptorContext.allArguments()[0]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.invoke.monitor.LocalMethodInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.OpenTracingLocalBuriedPointType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class SpanBuilderStartInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
public static final String START_TIME = "startTimestamp";
|
||||
public static final String OPERATION_NAME = "operationName";
|
||||
public static final String TAGS = "tags";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
|
||||
Long startTime = fetchStartTime(context);
|
||||
String operationName = (String) context.get(OPERATION_NAME);
|
||||
Identification.IdentificationBuilder builder = Identification.newBuilder().viewPoint(operationName)
|
||||
.spanType(OpenTracingLocalBuriedPointType.INSTANCE);
|
||||
|
||||
if (startTime != null){
|
||||
builder.startTime(startTime);
|
||||
}
|
||||
|
||||
Map<String, String> tags = (Map<String, String>) context.get(TAGS);
|
||||
if (tags != null) {
|
||||
for (Map.Entry<String, String> tag : tags.entrySet()) {
|
||||
builder.tag(tag.getKey(), tag.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
new LocalMethodInvokeMonitor().beforeInvoke(builder.build());
|
||||
}
|
||||
|
||||
private Long fetchStartTime(EnhancedClassInstanceContext context) {
|
||||
Object startTime = context.get(START_TIME);
|
||||
if (startTime != null){
|
||||
return (Long) startTime;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
*/
|
||||
public class SpanBuilderWithStartTimeInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
public static final String START_TIME = "startTimestamp";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
context.set(START_TIME, interceptorContext.allArguments()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
*/
|
||||
public class SpanBuilderWithTagInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
public static final String TAGS = "tags";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
Map<String, String> contextTags = (Map<String, String>) context.get(TAGS);
|
||||
if (!context.isContain(TAGS)){
|
||||
contextTags = new HashMap<String, String>();
|
||||
context.set(TAGS, contextTags);
|
||||
}
|
||||
|
||||
contextTags.put((String) interceptorContext.allArguments()[0], String.valueOf(interceptorContext
|
||||
.allArguments()[1]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.tracer;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||
import static com.a.eye.skywalking.api.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.tracer.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.model.RefContext;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingTracer;
|
||||
import io.opentracing.propagation.TextMap;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangxin
|
||||
* Intercept {@link SkyWalkingTracer#extractCrossProcessPropagationContextData(TextMap)}
|
||||
*/
|
||||
public class TracerExtractCrossProcessByteBufferContextInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
|
|
@ -24,7 +25,11 @@ public class TracerExtractCrossProcessByteBufferContextInterceptor implements In
|
|||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
ByteBuffer byteBuffer = (ByteBuffer) interceptorContext.allArguments()[0];
|
||||
String contextDataStr = new String(byteBuffer.array(), Charset.forName("UTF-8"));
|
||||
Tracing.initRefContext(new RefContext(contextDataStr));
|
||||
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
carrier.deserialize(contextDataStr);
|
||||
|
||||
ContextManager.INSTANCE.extract(carrier);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,50 +1,49 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.tracer.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.model.RefContext;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingTracer;
|
||||
import io.opentracing.propagation.TextMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import io.opentracing.propagation.TextMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangxin
|
||||
* Intercept {@link SkyWalkingTracer#extractCrossProcessPropagationContextData(TextMap)}
|
||||
*/
|
||||
public class TracerExtractCrossProcessTextMapContextInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
|
||||
public static final String SKY_WALKING_TRACING_NAME = "SkyWalking-TRACING-NAME";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
TextMap textMap = (TextMap) interceptorContext.allArguments()[0];
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
TextMap textMap = (TextMap)interceptorContext.allArguments()[0];
|
||||
Iterator<Map.Entry<String, String>> iterator = textMap.iterator();
|
||||
while (iterator.hasNext()){
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, String> entry = iterator.next();
|
||||
if (SKY_WALKING_TRACING_NAME.equals(entry.getKey())){
|
||||
try {
|
||||
Tracing.initRefContext(new RefContext(entry.getValue()));
|
||||
}catch (Throwable e){
|
||||
// do something
|
||||
}
|
||||
if (SKY_WALKING_TRACING_NAME.equals(entry.getKey())) {
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
carrier.deserialize(entry.getValue());
|
||||
|
||||
ContextManager.INSTANCE.extract(carrier);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.tracer.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingTracer;
|
||||
|
||||
/**
|
||||
* @author zhangxin
|
||||
* Intercept {@link SkyWalkingTracer#formatCrossProcessPropagationContextData()}
|
||||
*/
|
||||
public class TracerFormatCrossProcessContextInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
|
|
@ -19,23 +19,13 @@ public class TracerFormatCrossProcessContextInterceptor implements InstanceMetho
|
|||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
Span span = Tracing.getCurrentSpan();
|
||||
if (span != null) {
|
||||
return new ContextData(span.getTraceId(), generateSubParentLevelId(span), span.getRouteKey()).toString();
|
||||
}
|
||||
return ret;
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
ContextManager.INSTANCE.inject(carrier);
|
||||
return carrier.serialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
|
||||
private String generateSubParentLevelId(Span spanData) {
|
||||
if (spanData.getParentLevel() == null || spanData.getParentLevel().length() == 0) {
|
||||
return spanData.getLevelId() + "";
|
||||
}
|
||||
|
||||
return spanData.getParentLevel() + "." + spanData.getLevelId();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
com.a.eye.skywalking.toolkit.activation.opentracing.span.SkyWalkingSpanActivation
|
||||
com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.SkyWalkingSpanBuilderActivation
|
||||
com.a.eye.skywalking.toolkit.activation.opentracing.tracer.SkyWalkingTracerActivation
|
||||
com.a.eye.skywalking.toolkit.activation.opentracing.tracer.SkyWalkingTracerActivation
|
||||
|
|
|
|||
Loading…
Reference in New Issue