Java Code Examples for org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan#setPeer()

The following examples show how to use org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan#setPeer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Armeria085ServerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
                         final Class<?>[] argumentsTypes, final MethodInterceptResult result) {

    DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1];
    HttpHeaders headers = httpRequest.headers();

    ContextCarrier carrier = new ContextCarrier();
    for (CarrierItem item = carrier.items(); item.hasNext(); ) {
        item = item.next();
        item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey())));
    }

    AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier);
    entrySpan.setComponent(ComponentsDefine.ARMERIA);
    entrySpan.setLayer(SpanLayer.HTTP);
    entrySpan.setPeer(httpRequest.authority());
    Tags.URL.set(entrySpan, httpRequest.path());
    Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name());
}
 
Example 2
Source File: ContextCarrierHelper.java    From skywalking with Apache License 2.0 6 votes vote down vote up
/**
 * In {@link ClientTracingFilterInterceptor}, we create {@link ExitSpan} without op name and peer information, and
 * we use {@link AnnotationInterceptor.Rpc} and {@link ClientDestTracingFilterInterceptor} to put op name and
 * peer information into LocalContext, but the order of these two interceptors are uncertain, so after each
 * interceptor, we check if the op name and peer information are exists in LocalContext, if it exists, we set it
 * to span and inject to contextCarrier.
 */
static void tryInjectContext(AbstractSpan span) {
    /*
     * this may be a {@link NoopSpan}.
     */
    if (span != null && span.isExit()) {
        String operationName = span.getOperationName();
        if (PENDING_OP_NAME.equals(operationName)) {
            return;
        }
        String peer = getPeerHost();
        if (peer == null) {
            return;
        }
        span.setPeer(peer);

        ContextCarrier contextCarrier = new ContextCarrier();
        ((ExitTypeSpan) span).inject(contextCarrier);

        SWContextCarrier swContextCarrier = getSWContextCarrier();
        // we can ensure swContextCarrier is not null here
        swContextCarrier.setContextCarrier(contextCarrier);
        swContextCarrier.setOperationName(operationName);
    }
}
 
Example 3
Source File: Armeria084ServerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
    final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable {

    DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1];
    HttpHeaders headers = httpRequest.headers();

    ContextCarrier carrier = new ContextCarrier();
    for (CarrierItem item = carrier.items(); item.hasNext(); ) {
        item = item.next();
        item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey())));
    }

    AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier);
    entrySpan.setComponent(ComponentsDefine.ARMERIA);
    entrySpan.setLayer(SpanLayer.HTTP);
    entrySpan.setPeer(httpRequest.authority());
    Tags.URL.set(entrySpan, httpRequest.path());
    Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name());
}
 
Example 4
Source File: GenericRequestorInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    AvroInstance instance = (AvroInstance) objInst.getSkyWalkingDynamicField();

    AbstractSpan span = ContextManager.createExitSpan(instance.namespace + allArguments[0], instance.remotePeer);
    SpanLayer.asRPCFramework(span);
    span.setPeer(instance.remotePeer);
    span.setComponent(ComponentsDefine.AVRO_CLIENT);
}
 
Example 5
Source File: SpecificRequestorInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    AvroInstance instance = (AvroInstance) objInst.getSkyWalkingDynamicField();
    Method invoke = (Method) allArguments[1];

    AbstractSpan span = ContextManager.createExitSpan(instance.namespace + invoke.getName(), instance.remotePeer);
    SpanLayer.asRPCFramework(span);
    span.setPeer(instance.remotePeer);
    span.setComponent(ComponentsDefine.AVRO_CLIENT);
}