Search in sources :

Example 1 with EntrySpan

use of org.apache.skywalking.apm.agent.core.context.trace.EntrySpan in project incubator-skywalking by apache.

the class TracingContext method createEntrySpan.

/**
 * Create an entry span
 *
 * @param operationName most likely a service name
 * @return span instance.
 * Ref to {@link EntrySpan}
 */
@Override
public AbstractSpan createEntrySpan(final String operationName) {
    if (isLimitMechanismWorking()) {
        NoopSpan span = new NoopSpan();
        return push(span);
    }
    AbstractSpan entrySpan;
    final AbstractSpan parentSpan = peek();
    final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
    if (parentSpan != null && parentSpan.isEntry()) {
        entrySpan = (AbstractTracingSpan) DictionaryManager.findOperationNameCodeSection().findOnly(segment.getApplicationId(), operationName).doInCondition(new PossibleFound.FoundAndObtain() {

            @Override
            public Object doProcess(int operationId) {
                return parentSpan.setOperationId(operationId);
            }
        }, new PossibleFound.NotFoundAndObtain() {

            @Override
            public Object doProcess() {
                return parentSpan.setOperationName(operationName);
            }
        });
        return entrySpan.start();
    } else {
        entrySpan = (AbstractTracingSpan) DictionaryManager.findOperationNameCodeSection().findOnly(segment.getApplicationId(), operationName).doInCondition(new PossibleFound.FoundAndObtain() {

            @Override
            public Object doProcess(int operationId) {
                return new EntrySpan(spanIdGenerator++, parentSpanId, operationId);
            }
        }, new PossibleFound.NotFoundAndObtain() {

            @Override
            public Object doProcess() {
                return new EntrySpan(spanIdGenerator++, parentSpanId, operationName);
            }
        });
        entrySpan.start();
        return push(entrySpan);
    }
}
Also used : PossibleFound(org.apache.skywalking.apm.agent.core.dictionary.PossibleFound) EntrySpan(org.apache.skywalking.apm.agent.core.context.trace.EntrySpan) NoopSpan(org.apache.skywalking.apm.agent.core.context.trace.NoopSpan) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 2 with EntrySpan

use of org.apache.skywalking.apm.agent.core.context.trace.EntrySpan in project incubator-skywalking by apache.

the class TracingContext method extract.

/**
 * Extract the carrier to build the reference for the pre segment.
 *
 * @param carrier carried the context from a cross-process segment.
 * Ref to {@link AbstractTracerContext#extract(ContextCarrier)}
 */
@Override
public void extract(ContextCarrier carrier) {
    TraceSegmentRef ref = new TraceSegmentRef(carrier);
    this.segment.ref(ref);
    this.segment.relatedGlobalTraces(carrier.getDistributedTraceId());
    AbstractSpan span = this.activeSpan();
    if (span instanceof EntrySpan) {
        span.ref(ref);
    }
}
Also used : EntrySpan(org.apache.skywalking.apm.agent.core.context.trace.EntrySpan) TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)2 EntrySpan (org.apache.skywalking.apm.agent.core.context.trace.EntrySpan)2 NoopSpan (org.apache.skywalking.apm.agent.core.context.trace.NoopSpan)1 TraceSegmentRef (org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)1 PossibleFound (org.apache.skywalking.apm.agent.core.dictionary.PossibleFound)1