Skip to content
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

Merged
merged 1 commit into from Jan 23, 2017
Merged

support open-tracing #81

merged 1 commit into from Jan 23, 2017

Conversation

ascrutae
Copy link
Member

No description provided.

*
* @return span. if it exists, or null
*/
public static Span getLatestSpan() {
Copy link
Member

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) {
Copy link
Member

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){
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member

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){
Copy link
Member

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) {
Copy link
Member

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());
Copy link
Member

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";
Copy link
Member

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");
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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){
Copy link
Member

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){
Copy link
Member

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 {
Copy link
Member

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?

Copy link
Member Author

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";
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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()));
Copy link
Member

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())){
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member

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();
Copy link
Member

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() {
Copy link
Member

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);
Copy link
Member

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 {
Copy link
Member

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.

@wu-sheng wu-sheng added this to the 2.1-2017 milestone Jan 18, 2017
Copy link
Member

@wu-sheng wu-sheng left a 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.

@ascrutae
Copy link
Member Author

ascrutae commented Jan 23, 2017

The visualization is:

qq20170123-150036 2x

@wu-sheng wu-sheng merged commit e671b73 into apache:master Jan 23, 2017
@wu-sheng
Copy link
Member

@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. opentracing-contrib/java-hprose is in releasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants