New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support open-tracing #81
Conversation
* | ||
* @return span. if it exists, or null | ||
*/ | ||
public static Span getLatestSpan() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to getActiveSpan
or getCurrentSpan
. There is no guarantee about, the top span of stack, is the latest span.
* | ||
* @param tags tags map | ||
*/ | ||
public static void setTags2CurrentSpan(Map<String, String> tags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method should declare as
public static void setTag(Span span, String tagKey, String tagValue)
} | ||
|
||
|
||
public static void putBaseSpan(ContextData contextData){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BaseSpan
is a strange name. It's something like prevSpanContext
, maybe should be a new type, which contains: traceid, parentSpanId. No need be a span
.
* This {@link SpanNode} represent the base span of all the next spans. the trace id and | ||
* the level id will base on it. | ||
*/ | ||
private SpanNode baseSpan = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename, and add a new type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RefContext
may be a good name.
@@ -85,6 +105,10 @@ private void listPush(SpanNode spanNode) { | |||
spans.add(spans.size(), spanNode); | |||
} | |||
|
|||
private void initBaseSpan(Span baseSpan){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to initRefContext
.
return this; | ||
} | ||
|
||
public IdentificationBuilder tags(Map<String, String> tags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method should be tag
, instead of tags
.
@@ -42,12 +42,12 @@ private static Span getSpanFromThreadLocal(Identification id) { | |||
// 2 校验Context,Context是否存在 | |||
if (parentSpan == null) { | |||
// 不存在,新创建一个Context | |||
span = new Span(id.getViewPoint()); | |||
span = new Span(id.getViewPoint(), id.getStartTime(), id.getTags()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tags
, as a constructor parameters, is an improper thing.
Span
should have a method, named tag()
@Override | ||
public String getMethodsInterceptor() { | ||
return "com.a.eye.skywalking.toolkit.activation.opentracing" + | ||
".SkywalkingSpanTagsInterceptor"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All interceptor name should refactor:
com.a.eye.skywalking.toolkit.activation.opentracing.SkywalkingSpanTagsInterceptor
refactor to
com.a.eye.skywalking.toolkit.activation.opentracing.span.SetTagInterceptor
All other methods should stay in the same principle.
public class SkyWalkingSpanTagsInterceptor implements InstanceMethodsAroundInterceptor { | ||
@Override | ||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { | ||
Map<String, String> tags = (Map<String, String>) context.get("tags"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tags
and something like this, should be a constant.
/** | ||
* Set the tag to span | ||
* | ||
* @param span |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments: the span will be tagged with the given key and value pair.
|
||
|
||
/** | ||
* Get the latest span of current trace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get the current span
* | ||
* @param contextData context data | ||
*/ | ||
public static void putRefContext(ContextData contextData){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putRefContext
's parameter should be RefContext
type. And caller in charge of converting ContextData
to RefContext
.
putRefContext
should be named set...
or init...
. There is nothing to put here.
@@ -42,7 +43,20 @@ public static Span pop() { | |||
return nodes.get().pop(); | |||
} | |||
|
|||
public static void putRefContext(RefContext refContext) { | |||
if (nodes.get() == null){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need null-point check?
@@ -0,0 +1,8 @@ | |||
package com.a.eye.skywalking.model; | |||
|
|||
public class BaseSpan extends Span { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why still have the BaseSpan
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will delete it
|
||
@Override | ||
public String getConstructorInterceptor() { | ||
return "com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor.SpanConstructorInterceptor"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the correct name again. No need of Span
prefix, it already existed in package name.
Maybe com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor.Constructor
? or use other principles.
import javax.net.ssl.StandardConstants; | ||
|
||
/** | ||
* Created by wusheng on 2017/1/3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment code by the actual author name.
import io.opentracing.propagation.TextMap; | ||
|
||
/** | ||
* Created by wusheng on 2017/1/3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment code by the actual author name.
Map.Entry<String, String> entry = iterator.next(); | ||
if ("SkyWalking-TRACING-NAME".equals(entry.getKey())){ | ||
try { | ||
Tracing.putBaseSpan(new ContextData(entry.getValue())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still putBaseSpan
, check your code carefully.
Iterator<Map.Entry<String, String>> iterator = textMap.iterator(); | ||
while (iterator.hasNext()){ | ||
Map.Entry<String, String> entry = iterator.next(); | ||
if ("SkyWalking-TRACING-NAME".equals(entry.getKey())){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SkyWalking-TRACING-NAME
need be a constant.
/** | ||
* This {@link RefContext} contain the trace context from another processor. | ||
*/ | ||
private RefContext refContext = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field should set to null
, when spans
is empty after pop
invokes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, maybe cause a leak when the next transaction begins.
@@ -29,41 +35,63 @@ public String getBusinessKey() { | |||
return businessKey; | |||
} | |||
|
|||
public long getStartTime() { | |||
if (startTime == 0){ | |||
return System.currentTimeMillis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an identification, only be used in create span. Why need getStartTime
?
And even need this, why not assign this.startTime
= 'return-value'?
return startTime; | ||
} | ||
|
||
public Map<String, String> getTags() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need get
?
@@ -166,12 +170,12 @@ public void setBusinessKey(String businessKey) { | |||
|
|||
public RequestSpan.Builder buildRequestSpan(RequestSpan.Builder builder) { | |||
return builder.setTraceId(this.traceId).setParentLevel(this.parentLevel).setLevelId(this.levelId) | |||
.setStartDate(this.startDate).setRouteKey(routeKey).putAllTags(tags); | |||
.setStartDate(this.startTime).setRouteKey(routeKey).putAllTags(tags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still have two method names, StartDate
and StartTime
, please make sure they are uniform.
/** | ||
* Created by xin on 2017/1/16. | ||
*/ | ||
public class OpenTracingLocalBuriedPointType implements IBuriedPointType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a suggestion, refactor class type to enum
seems better. Also suggest in other plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After you test, this will be ready to be merged.
@rayzhang0603 , in 2.1-2017, we provide opentracing-implemetation tracer. Have tested by using motan's filter, with your source code, since your next version is not released yet. Seem passed. The visualization is above. btw @andot , I think this feature will work in hprose-java filter. |
No description provided.