Search in sources :

Example 1 with NoopExitSpan

use of org.apache.skywalking.apm.agent.core.context.trace.NoopExitSpan 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)

Aggregations

AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1 ExitSpan (org.apache.skywalking.apm.agent.core.context.trace.ExitSpan)1 NoopExitSpan (org.apache.skywalking.apm.agent.core.context.trace.NoopExitSpan)1 PossibleFound (org.apache.skywalking.apm.agent.core.dictionary.PossibleFound)1