提交 69877b80 编写于 作者: wu-sheng's avatar wu-sheng

Give a sample code of the first Mock trace.

上级 a4d2f237
package com.a.eye.skywalking.sniffer.mock.trace;
import com.a.eye.skywalking.trace.TraceSegment;
/**
* Created by wusheng on 2017/2/20.
*/
public interface TraceSegmentBuilder {
TraceSegment build();
}
package com.a.eye.skywalking.sniffer.mock.trace;
import com.a.eye.skywalking.sniffer.mock.trace.builders.SingleTomcat200TraceBuilder;
import com.a.eye.skywalking.trace.TraceSegment;
import java.util.HashMap;
import java.util.Map;
/**
* The <code>TraceSegmentBuilderFactory</code> contains all {@link TraceSegmentBuilder} implementations.
* All the implementations can build a true {@link TraceSegment} object, and contain all necessary spans, with all tags/events, all refs.
*
* Created by wusheng on 2017/2/20.
*/
public enum TraceSegmentBuilderFactory {
INSTANCE;
private Map<String, TraceSegmentBuilder> allBuilders;
TraceSegmentBuilderFactory(){
allBuilders = new HashMap<String, TraceSegmentBuilder>();
initialize();
}
public TraceSegment singleTomcat200Trace(){
return allBuilders.get(SingleTomcat200TraceBuilder.INSTANCE).build();
}
private void initialize(){
initBuilder(SingleTomcat200TraceBuilder.INSTANCE);
}
private void initBuilder(TraceSegmentBuilder builder){
allBuilders.put(builder.toString(), builder);
}
}
package com.a.eye.skywalking.sniffer.mock.trace.builders;
import com.a.eye.skywalking.api.context.ContextManager;
import com.a.eye.skywalking.sniffer.mock.trace.TraceSegmentBuilder;
import com.a.eye.skywalking.trace.Span;
import com.a.eye.skywalking.trace.TraceSegment;
import com.a.eye.skywalking.trace.tag.Tags;
/**
* A Trace contains only one span, which represent a tomcat server side span.
*
* Created by wusheng on 2017/2/20.
*/
public enum SingleTomcat200TraceBuilder implements TraceSegmentBuilder {
INSTANCE;
@Override public TraceSegment build() {
Span webSpan = ContextManager.INSTANCE.createSpan("/web/serviceA");
{
Tags.COMPONENT.set(webSpan, "tomcat");
Tags.URL.set(webSpan, "http://10.21.9.35/web/serviceA");
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
Tags.STATUS_CODE.set(webSpan, 200);
}
return null;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册