Search in sources :

Example 71 with AbstractSpan

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

the class TracingContext method capture.

/**
 * Capture the snapshot of current context.
 *
 * @return the snapshot of context for cross-thread propagation
 * Ref to {@link AbstractTracerContext#capture()}
 */
@Override
public ContextSnapshot capture() {
    List<TraceSegmentRef> refs = this.segment.getRefs();
    ContextSnapshot snapshot = new ContextSnapshot(segment.getTraceSegmentId(), activeSpan().getSpanId(), segment.getRelatedGlobalTraces());
    int entryOperationId;
    String entryOperationName;
    int entryApplicationInstanceId;
    AbstractSpan firstSpan = first();
    if (refs != null && refs.size() > 0) {
        TraceSegmentRef ref = refs.get(0);
        entryOperationId = ref.getEntryOperationId();
        entryOperationName = ref.getEntryOperationName();
        entryApplicationInstanceId = ref.getEntryApplicationInstanceId();
    } else {
        entryOperationId = firstSpan.getOperationId();
        entryOperationName = firstSpan.getOperationName();
        entryApplicationInstanceId = this.segment.getApplicationInstanceId();
    }
    snapshot.setEntryApplicationInstanceId(entryApplicationInstanceId);
    if (entryOperationId == DictionaryUtil.nullValue()) {
        snapshot.setEntryOperationName(entryOperationName);
    } else {
        snapshot.setEntryOperationId(entryOperationId);
    }
    if (firstSpan.getOperationId() == DictionaryUtil.nullValue()) {
        snapshot.setParentOperationName(firstSpan.getOperationName());
    } else {
        snapshot.setParentOperationId(firstSpan.getOperationId());
    }
    return snapshot;
}
Also used : TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 72 with AbstractSpan

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

the class TracingContext method createLocalSpan.

/**
 * Create a local span
 *
 * @param operationName most likely a local method signature, or business name.
 * @return the span represents a local logic block.
 * Ref to {@link LocalSpan}
 */
@Override
public AbstractSpan createLocalSpan(final String operationName) {
    if (isLimitMechanismWorking()) {
        NoopSpan span = new NoopSpan();
        return push(span);
    }
    AbstractSpan parentSpan = peek();
    final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
    AbstractTracingSpan span = (AbstractTracingSpan) DictionaryManager.findOperationNameCodeSection().findOrPrepare4Register(segment.getApplicationId(), operationName, false, false).doInCondition(new PossibleFound.FoundAndObtain() {

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

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

Example 73 with AbstractSpan

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

the class TracingContext method createExitSpan.

/**
 * Create an exit span
 *
 * @param operationName most likely a service name of remote
 * @param remotePeer the network id(ip:port, hostname:port or ip1:port1,ip2,port, etc.)
 * @return the span represent an exit point of this segment.
 * @see  ExitSpan
 */
@Override
public AbstractSpan createExitSpan(final String operationName, final String remotePeer) {
    AbstractSpan exitSpan;
    AbstractSpan parentSpan = peek();
    if (parentSpan != null && parentSpan.isExit()) {
        exitSpan = parentSpan;
    } else {
        final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
        exitSpan = (AbstractSpan) DictionaryManager.findNetworkAddressSection().find(remotePeer).doInCondition(new PossibleFound.FoundAndObtain() {

            @Override
            public Object doProcess(final int peerId) {
                if (isLimitMechanismWorking()) {
                    return new NoopExitSpan(peerId);
                }
                return DictionaryManager.findOperationNameCodeSection().findOnly(segment.getApplicationId(), operationName).doInCondition(new PossibleFound.FoundAndObtain() {

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

                    @Override
                    public Object doProcess() {
                        return new ExitSpan(spanIdGenerator++, parentSpanId, operationName, peerId);
                    }
                });
            }
        }, new PossibleFound.NotFoundAndObtain() {

            @Override
            public Object doProcess() {
                if (isLimitMechanismWorking()) {
                    return new NoopExitSpan(remotePeer);
                }
                return DictionaryManager.findOperationNameCodeSection().findOnly(segment.getApplicationId(), operationName).doInCondition(new PossibleFound.FoundAndObtain() {

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

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

Example 74 with AbstractSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan 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 75 with AbstractSpan

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

the class ContextManager method createEntrySpan.

public static AbstractSpan createEntrySpan(String operationName, ContextCarrier carrier) {
    SamplingService samplingService = ServiceManager.INSTANCE.findService(SamplingService.class);
    AbstractSpan span;
    AbstractTracerContext context;
    if (carrier != null && carrier.isValid()) {
        samplingService.forceSampled();
        context = getOrCreate(operationName, true);
        span = context.createEntrySpan(operationName);
        context.extract(carrier);
    } else {
        context = getOrCreate(operationName, false);
        span = context.createEntrySpan(operationName);
    }
    return span;
}
Also used : SamplingService(org.apache.skywalking.apm.agent.core.sampling.SamplingService) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)141 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)36 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)29 URI (java.net.URI)7 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)7 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)7 ConnectionInfo (org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 StatementEnhanceInfos (org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos)6 Invocation (io.servicecomb.core.Invocation)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Invocation (org.apache.servicecomb.core.Invocation)5 SQLException (java.sql.SQLException)4 Metadata (io.grpc.Metadata)3 Field (java.lang.reflect.Field)3 List (java.util.List)3 TraceSegmentRef (org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)3 EnhancedInstance (org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)3 Request (com.weibo.api.motan.rpc.Request)2 Response (com.weibo.api.motan.rpc.Response)2