Search in sources :

Example 76 with AbstractSpan

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

the class ContextManager method createExitSpan.

public static AbstractSpan createExitSpan(String operationName, String remotePeer) {
    AbstractTracerContext context = getOrCreate(operationName, false);
    AbstractSpan span = context.createExitSpan(operationName, remotePeer);
    return span;
}
Also used : AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 77 with AbstractSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan 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());
}
Also used : WithPeerInfo(org.apache.skywalking.apm.agent.core.context.trace.WithPeerInfo) TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 78 with AbstractSpan

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

Example 79 with AbstractSpan

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

the class ActiveSpanTagInterceptor method beforeMethod.

@Override
public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, MethodInterceptResult result) {
    AbstractSpan activeSpan = null;
    try {
        activeSpan = ContextManager.activeSpan();
        activeSpan.tag(String.valueOf(allArguments[0]), String.valueOf(allArguments[1]));
    } catch (NullPointerException e) {
    }
}
Also used : AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 80 with AbstractSpan

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

the class MemcachedMethodInterceptor method handleMethodException.

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
    AbstractSpan span = ContextManager.activeSpan();
    span.errorOccurred();
    span.log(t);
}
Also used : 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