use of org.apache.skywalking.apm.agent.core.context.trace.WithPeerInfo in project incubator-skywalking by apache.
the class TracingContext method inject.
/**
* Inject the context into the given carrier, only when the active span is an exit one.
*
* @param carrier to carry the context for crossing process.
* @throws IllegalStateException if the active span isn't an exit one.
* Ref to {@link AbstractTracerContext#inject(ContextCarrier)}
*/
@Override
public void inject(ContextCarrier carrier) {
AbstractSpan span = this.activeSpan();
if (!span.isExit()) {
throw new IllegalStateException("Inject can be done only in Exit Span");
}
WithPeerInfo spanWithPeer = (WithPeerInfo) span;
String peer = spanWithPeer.getPeer();
int peerId = spanWithPeer.getPeerId();
carrier.setTraceSegmentId(this.segment.getTraceSegmentId());
carrier.setSpanId(span.getSpanId());
carrier.setParentApplicationInstanceId(segment.getApplicationInstanceId());
if (DictionaryUtil.isNull(peerId)) {
carrier.setPeerHost(peer);
} else {
carrier.setPeerId(peerId);
}
List<TraceSegmentRef> refs = this.segment.getRefs();
int operationId;
String operationName;
int entryApplicationInstanceId;
if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0);
operationId = ref.getEntryOperationId();
operationName = ref.getEntryOperationName();
entryApplicationInstanceId = ref.getEntryApplicationInstanceId();
} else {
AbstractSpan firstSpan = first();
operationId = firstSpan.getOperationId();
operationName = firstSpan.getOperationName();
entryApplicationInstanceId = this.segment.getApplicationInstanceId();
}
carrier.setEntryApplicationInstanceId(entryApplicationInstanceId);
if (operationId == DictionaryUtil.nullValue()) {
carrier.setEntryOperationName(operationName);
} else {
carrier.setEntryOperationId(operationId);
}
int parentOperationId = first().getOperationId();
if (parentOperationId == DictionaryUtil.nullValue()) {
carrier.setParentOperationName(first().getOperationName());
} else {
carrier.setParentOperationId(parentOperationId);
}
carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces());
}
Aggregations