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

Fix database plugin missing tag span.kind.

上级 5f6dd33c
......@@ -9,7 +9,7 @@ public class Config {
public static String PATH = "";
public static int SAMPLING_RATE = 10000;
public static int SAMPLING_CYCLE = 1;
}
public static class Collector{
......
......@@ -12,7 +12,7 @@ import com.a.eye.skywalking.trace.TraceSegment;
* have been traced, but, considering CPU cost of serialization/deserialization, and network bandwidth, the agent do NOT
* send all of them to collector, if SAMPLING is on.
*
* By default, SAMPLING is off, and {@link Config.Agent#SAMPLING_RATE} == 1000.
* By default, SAMPLING is off, and {@link Config.Agent#SAMPLING_CYCLE} == 1.
*
* @author wusheng
*/
......@@ -20,26 +20,25 @@ public class SamplingService implements BootService {
private static ILog logger = LogManager.getLogger(SamplingService.class);
private volatile boolean on = false;
private volatile int rate = 0;
private volatile int rollingSeed = 1;
@Override
public void bootUp() throws Throwable {
if (Config.Agent.SAMPLING_RATE == 10000) {
if (Config.Agent.SAMPLING_CYCLE == 1) {
this.on = false;
return;
}
if (Config.Agent.SAMPLING_RATE > 10000 || Config.Agent.SAMPLING_RATE < 1) {
throw new IllegalSamplingRateException("sampling rate should stay in (0, 10000].");
if (Config.Agent.SAMPLING_CYCLE < 1) {
throw new IllegalSamplingRateException("sampling cycle must greater than 0.");
}
rate = 10000 / Config.Agent.SAMPLING_RATE;
on = true;
this.on = true;
logger.debug("The trace sampling is on, and the sampling rate is: {}", rate);
logger.debug("The trace sampling is on, and the sampling cycle is: {}", Config.Agent.SAMPLING_CYCLE);
}
public void trySampling(TraceSegment segment) {
if (on) {
if (rollingSeed % rate != 0) {
if (rollingSeed % Config.Agent.SAMPLING_CYCLE != 0) {
segment.setSampled(false);
}
rollingSeed++;
......
......@@ -13,7 +13,7 @@ import org.junit.Test;
public class SamplingServiceTest {
@Test
public void test50Percent(){
Config.Agent.SAMPLING_RATE = 5000;
Config.Agent.SAMPLING_CYCLE = 2;
ServiceManager.INSTANCE.boot();
TraceSegment segment = new TraceSegment();
......@@ -30,7 +30,7 @@ public class SamplingServiceTest {
@AfterClass
public static void clear(){
Config.Agent.SAMPLING_RATE = 10000;
Config.Agent.SAMPLING_CYCLE = 1;
ServiceManager.INSTANCE.boot();
}
}
......@@ -24,6 +24,7 @@ public class CallableStatementTracing {
try {
Span span = ContextManager.createSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method);
Tags.DB_TYPE.set(span, "sql");
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
Tags.DB_STATEMENT.set(span, sql);
Tags.SPAN_LAYER.asDB(span);
......
......@@ -24,6 +24,7 @@ public class ConnectionTracing {
try {
Span span = ContextManager.createSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method);
Tags.DB_TYPE.set(span, "sql");
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
Tags.DB_STATEMENT.set(span, sql);
Tags.COMPONENT.set(span, connectInfo.getDBType());
......
......@@ -23,6 +23,7 @@ public class PreparedStatementTracing {
try {
Span span = ContextManager.createSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method);
Tags.DB_TYPE.set(span, "sql");
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
Tags.DB_STATEMENT.set(span, sql);
Tags.COMPONENT.set(span, connectInfo.getDBType());
......
......@@ -23,6 +23,7 @@ public class StatementTracing {
try {
Span span = ContextManager.createSpan(connectInfo.getDBType() + "/JDBI/Statement/" + method);
Tags.DB_TYPE.set(span, "sql");
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
Tags.DB_STATEMENT.set(span, sql);
Tags.COMPONENT.set(span, connectInfo.getDBType());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册