Add peer to entry span (#2287)

* Add peer to entry span

* Fix CI
This commit is contained in:
Xin,Zhang 2019-02-27 20:19:18 +08:00 committed by 吴晟 Wu Sheng
parent fb62025da8
commit 1c32d59542
5 changed files with 75 additions and 28 deletions

View File

@ -127,4 +127,6 @@ public interface AbstractSpan {
void ref(TraceSegmentRef ref);
AbstractSpan start(long starttime);
AbstractSpan setPeer(String remotePeer);
}

View File

@ -20,8 +20,6 @@
package org.apache.skywalking.apm.agent.core.context.trace;
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import org.apache.skywalking.apm.network.trace.component.Component;
/**
@ -38,31 +36,21 @@ import org.apache.skywalking.apm.network.trace.component.Component;
* @author wusheng
*/
public class ExitSpan extends StackBasedTracingSpan implements WithPeerInfo {
private String peer;
private int peerId;
public ExitSpan(int spanId, int parentSpanId, String operationName, String peer) {
super(spanId, parentSpanId, operationName);
this.peer = peer;
this.peerId = DictionaryUtil.nullValue();
super(spanId, parentSpanId, operationName, peer);
}
public ExitSpan(int spanId, int parentSpanId, int operationId, int peerId) {
super(spanId, parentSpanId, operationId);
this.peer = null;
this.peerId = peerId;
super(spanId, parentSpanId, operationId, peerId);
}
public ExitSpan(int spanId, int parentSpanId, int operationId, String peer) {
super(spanId, parentSpanId, operationId);
this.peer = peer;
this.peerId = DictionaryUtil.nullValue();
super(spanId, parentSpanId, operationId, peer);
}
public ExitSpan(int spanId, int parentSpanId, String operationName, int peerId) {
super(spanId, parentSpanId, operationName);
this.peer = null;
this.peerId = peerId;
super(spanId, parentSpanId, operationName, peerId);
}
/**
@ -126,18 +114,6 @@ public class ExitSpan extends StackBasedTracingSpan implements WithPeerInfo {
return this;
}
@Override public SpanObjectV2.Builder transform() {
SpanObjectV2.Builder spanBuilder = super.transform();
if (peerId != DictionaryUtil.nullValue()) {
spanBuilder.setPeerId(peerId);
} else {
if (peer != null) {
spanBuilder.setPeer(peer);
}
}
return spanBuilder;
}
@Override
public AbstractTracingSpan setOperationName(String operationName) {
if (stackDepth == 1) {

View File

@ -53,4 +53,8 @@ public class LocalSpan extends AbstractTracingSpan {
@Override public boolean isExit() {
return false;
}
@Override public AbstractSpan setPeer(String remotePeer) {
return this;
}
}

View File

@ -111,4 +111,8 @@ public class NoopSpan implements AbstractSpan {
@Override public AbstractSpan start(long startTime) {
return this;
}
@Override public AbstractSpan setPeer(String remotePeer) {
return this;
}
}

View File

@ -21,6 +21,7 @@ package org.apache.skywalking.apm.agent.core.context.trace;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryManager;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.agent.core.dictionary.PossibleFound;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
/**
* The <code>StackBasedTracingSpan</code> represents a span with an inside stack construction.
@ -31,15 +32,58 @@ import org.apache.skywalking.apm.agent.core.dictionary.PossibleFound;
*/
public abstract class StackBasedTracingSpan extends AbstractTracingSpan {
protected int stackDepth;
protected String peer;
protected int peerId;
protected StackBasedTracingSpan(int spanId, int parentSpanId, String operationName) {
super(spanId, parentSpanId, operationName);
this.stackDepth = 0;
this.peer = null;
this.peerId = DictionaryUtil.nullValue();
}
protected StackBasedTracingSpan(int spanId, int parentSpanId, int operationId) {
super(spanId, parentSpanId, operationId);
this.stackDepth = 0;
this.peer = null;
this.peerId = DictionaryUtil.nullValue();
}
public StackBasedTracingSpan(int spanId, int parentSpanId, int operationId, int peerId) {
super(spanId, parentSpanId, operationId);
this.peer = null;
this.peerId = peerId;
}
public StackBasedTracingSpan(int spanId, int parentSpanId, int operationId, String peer) {
super(spanId, parentSpanId, operationId);
this.peer = peer;
this.peerId = DictionaryUtil.nullValue();
}
protected StackBasedTracingSpan(int spanId, int parentSpanId, String operationName, String peer) {
super(spanId, parentSpanId, operationName);
this.peer = peer;
this.peerId = DictionaryUtil.nullValue();
}
protected StackBasedTracingSpan(int spanId, int parentSpanId, String operationName, int peerId) {
super(spanId, parentSpanId, operationName);
this.peer = null;
this.peerId = peerId;
}
@Override
public SpanObjectV2.Builder transform() {
SpanObjectV2.Builder spanBuilder = super.transform();
if (peerId != DictionaryUtil.nullValue()) {
spanBuilder.setPeerId(peerId);
} else {
if (peer != null) {
spanBuilder.setPeer(peer);
}
}
return spanBuilder;
}
@Override
@ -66,4 +110,21 @@ public abstract class StackBasedTracingSpan extends AbstractTracingSpan {
return false;
}
}
@Override public AbstractSpan setPeer(final String remotePeer) {
DictionaryManager.findNetworkAddressSection().find(remotePeer).doInCondition(
new PossibleFound.Found() {
@Override
public void doProcess(int remotePeerId) {
peerId = remotePeerId;
}
}, new PossibleFound.NotFound() {
@Override
public void doProcess() {
peer = remotePeer;
}
}
);
return this;
}
}