Skip to content

Commit

Permalink
Merge branch 'master' into fix/opentracing-plugin-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ascrutae committed Dec 14, 2017
2 parents e1da9b5 + eee5e65 commit 1dade17
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
Expand Up @@ -16,7 +16,6 @@
*
*/


package org.apache.skywalking.apm.agent.core.context;

import java.util.LinkedList;
Expand Down Expand Up @@ -50,6 +49,7 @@
* ContextCarrier} or {@link ContextSnapshot}.
*
* @author wusheng
* @author zhang xin
*/
public class TracingContext implements AbstractTracerContext {
/**
Expand Down Expand Up @@ -159,7 +159,7 @@ public void extract(ContextCarrier carrier) {
this.segment.relatedGlobalTraces(carrier.getDistributedTraceId());
AbstractSpan span = this.activeSpan();
if (span instanceof EntrySpan) {
((EntrySpan)span).ref(ref);
span.ref(ref);
}
}

Expand Down Expand Up @@ -213,7 +213,9 @@ public ContextSnapshot capture() {
*/
@Override
public void continued(ContextSnapshot snapshot) {
this.segment.ref(new TraceSegmentRef(snapshot));
TraceSegmentRef segmentRef = new TraceSegmentRef(snapshot);
this.segment.ref(segmentRef);
this.activeSpan().ref(segmentRef);
this.segment.relatedGlobalTraces(snapshot.getDistributedTraceId());
}

Expand Down
Expand Up @@ -16,7 +16,6 @@
*
*/


package org.apache.skywalking.apm.agent.core.context.trace;

import java.util.Map;
Expand Down Expand Up @@ -110,4 +109,11 @@ public interface AbstractSpan {
String getOperationName();

AbstractSpan setOperationId(int operationId);

/**
* Reference other trace segment.
*
* @param ref segment ref
*/
void ref(TraceSegmentRef ref);
}
Expand Up @@ -16,7 +16,6 @@
*
*/


package org.apache.skywalking.apm.agent.core.context.trace;

import java.util.LinkedList;
Expand Down Expand Up @@ -64,6 +63,13 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
*/
protected List<LogDataEntity> logs;

/**
* The refs of parent trace segments, except the primary one. For most RPC call, {@link #refs} contains only one
* element, but if this segment is a start span of batch process, the segment faces multi parents, at this moment,
* we use this {@link #refs} to link them.
*/
protected List<TraceSegmentRef> refs;

protected AbstractTracingSpan(int spanId, int parentSpanId, String operationName) {
this.operationName = operationName;
this.operationId = DictionaryUtil.nullValue();
Expand Down Expand Up @@ -273,7 +279,21 @@ public SpanObject.Builder transform() {
spanBuilder.addLogs(log.transform());
}
}
if (this.refs != null) {
for (TraceSegmentRef ref : this.refs) {
spanBuilder.addRefs(ref.transform());
}
}

return spanBuilder;
}

@Override public void ref(TraceSegmentRef ref) {
if (refs == null) {
refs = new LinkedList<TraceSegmentRef>();
}
if (!refs.contains(ref)) {
refs.add(ref);
}
}
}
Expand Up @@ -16,13 +16,9 @@
*
*/


package org.apache.skywalking.apm.agent.core.context.trace;

import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.network.proto.SpanObject;
import org.apache.skywalking.apm.network.trace.component.Component;

/**
Expand All @@ -38,12 +34,6 @@
* @author wusheng
*/
public class EntrySpan extends StackBasedTracingSpan {
/**
* The refs of parent trace segments, except the primary one. For most RPC call, {@link #refs} contains only one
* element, but if this segment is a start span of batch process, the segment faces multi parents, at this moment,
* we use this {@link #refs} to link them.
*/
private List<TraceSegmentRef> refs;

private int currentMaxDepth;

Expand Down Expand Up @@ -136,25 +126,6 @@ public EntrySpan log(Throwable t) {
return false;
}

@Override public SpanObject.Builder transform() {
SpanObject.Builder builder = super.transform();
if (refs != null) {
for (TraceSegmentRef ref : refs) {
builder.addRefs(ref.transform());
}
}
return builder;
}

public void ref(TraceSegmentRef ref) {
if (refs == null) {
refs = new LinkedList<TraceSegmentRef>();
}
if (!refs.contains(ref)) {
refs.add(ref);
}
}

private void clearWhenRestart() {
this.componentId = DictionaryUtil.nullValue();
this.componentName = null;
Expand Down
Expand Up @@ -99,4 +99,7 @@ public AbstractSpan tag(String key, String value) {
@Override public AbstractSpan setOperationId(int operationId) {
return this;
}

@Override public void ref(TraceSegmentRef ref) {
}
}

0 comments on commit 1dade17

Please sign in to comment.