org.apache.skywalking.apm.agent.core.context.trace.SpanLayer Java Examples

The following examples show how to use org.apache.skywalking.apm.agent.core.context.trace.SpanLayer. 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: TomcatInvokeInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
/**
 * * The {@link TraceSegment#refs} of current trace segment will reference to the trace segment id of the previous
 * level if the serialized context is not null.
 *
 * @param result change this result, if you want to truncate the method.
 */
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    Request request = (Request) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();

    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHeader(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier);
    Tags.URL.set(span, request.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, request.getMethod());
    span.setComponent(ComponentsDefine.TOMCAT);
    SpanLayer.asHttp(span);

    if (Config.Plugin.Tomcat.COLLECT_HTTP_PARAMS) {
        collectHttpParam(request, span);
    }
}
 
Example #2
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 #3
Source File: TransportClientHandlerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    Invocation invocation = (Invocation) allArguments[0];
    if (!checkRegisterStatus(invocation)) {
        return;
    }
    URI uri = new URI(invocation.getEndpoint().toString());
    String peer = uri.getHost() + ":" + uri.getPort();
    String operationName = invocation.getMicroserviceQualifiedName();
    final ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        invocation.getContext().put(next.getHeadKey(), next.getHeadValue());
    }
    String url = invocation.getOperationMeta().getOperationPath();
    Tags.URL.set(span, url);
    span.setComponent(ComponentsDefine.SERVICECOMB);
    SpanLayer.asRPCFramework(span);
}
 
Example #4
Source File: AbstractMessageConsumeInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    List<MessageExt> msgs = (List<MessageExt>) allArguments[0];

    ContextCarrier contextCarrier = getContextCarrierFromMessage(msgs.get(0));
    AbstractSpan span = ContextManager.createEntrySpan(CONSUMER_OPERATION_NAME_PREFIX + msgs.get(0)
                                                                                            .getTopic() + "/Consumer", contextCarrier);

    span.setComponent(ComponentsDefine.ROCKET_MQ_CONSUMER);
    SpanLayer.asMQ(span);
    for (int i = 1; i < msgs.size(); i++) {
        ContextManager.extract(getContextCarrierFromMessage(msgs.get(i)));
    }

}
 
Example #5
Source File: SofaRpcProviderInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    SofaRequest sofaRequest = (SofaRequest) allArguments[0];

    AbstractSpan span = null;

    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        final String headKey = next.getHeadKey();
        final Object attachment = sofaRequest.getRequestProp(SKYWALKING_PREFIX + headKey);
        if (attachment != null) {
            next.setHeadValue(attachment.toString());
        } else {
            next.setHeadValue("");
        }
    }
    span = ContextManager.createEntrySpan(generateViewPoint(sofaRequest), contextCarrier);

    span.setComponent(ComponentsDefine.SOFARPC);
    SpanLayer.asRPCFramework(span);
}
 
Example #6
Source File: SolrClientInterceptorTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
private void spanDeleteAssert(AbstractSpan span, String operationName, String statement) {
    Assert.assertEquals(span.getOperationName(), operationName);
    SpanAssert.assertComponent(span, ComponentsDefine.SOLRJ);
    SpanAssert.assertOccurException(span, false);
    SpanAssert.assertLogSize(span, 0);
    SpanAssert.assertLayer(span, SpanLayer.DB);

    SpanAssert.assertTag(span, 0, "Solr");

    int start = 0;
    if (Config.Plugin.SolrJ.TRACE_STATEMENT) {
        SpanAssert.assertTag(span, ++start, statement);
    }
    if (Config.Plugin.SolrJ.TRACE_OPS_PARAMS) {
        SpanAssert.assertTag(span, ++start, "-1");
    }

    SpanAssert.assertTag(span, start + 1, "5");
}
 
Example #7
Source File: PreparedStatementExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
                               Class<?>[] argumentsTypes, MethodInterceptResult result) {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
    ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo
            .getDatabasePeer());
    Tags.DB_TYPE.set(span, "sql");
    Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
    Tags.DB_STATEMENT.set(span, cacheObject.getSql());
    span.setComponent(connectInfo.getComponent());

    if (Config.Plugin.POSTGRESQL.TRACE_SQL_PARAMETERS) {
        final Object[] parameters = cacheObject.getParameters();
        if (parameters != null && parameters.length > 0) {
            int maxIndex = cacheObject.getMaxIndex();
            String parameterString = getParameterString(parameters, maxIndex);
            SQL_PARAMETERS.set(span, parameterString);
        }
    }

    SpanLayer.asDB(span);
}
 
Example #8
Source File: SyncHttpRequestSendInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    HttpRequest request = (HttpRequest) objInst;
    ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(request.getURI()
                                                             .getPath(), contextCarrier, request.getHost() + ":" + request
        .getPort());
    span.setComponent(ComponentsDefine.JETTY_CLIENT);

    Tags.HTTP.METHOD.set(span, getHttpMethod(request));
    Tags.URL.set(span, request.getURI().toString());
    SpanLayer.asHttp(span);

    CarrierItem next = contextCarrier.items();
    HttpFields field = request.getHeaders();
    while (next.hasNext()) {
        next = next.next();
        field.add(next.getHeadKey(), next.getHeadValue());
    }
}
 
Example #9
Source File: HttpClientRequestImplInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                         MethodInterceptResult result) {
    HttpClientRequestContext requestContext = (HttpClientRequestContext) objInst.getSkyWalkingDynamicField();
    if (!requestContext.sent) {
        HttpClientRequest request = (HttpClientRequest) objInst;
        ContextCarrier contextCarrier = new ContextCarrier();
        AbstractSpan span = ContextManager.createExitSpan(toPath(request.uri()), contextCarrier,
                requestContext.remotePeer);
        span.setComponent(ComponentsDefine.VERTX);
        SpanLayer.asHttp(span);
        Tags.HTTP.METHOD.set(span, request.method().toString());
        Tags.URL.set(span, request.uri());

        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            request.headers().add(next.getHeadKey(), next.getHeadValue());
        }
        requestContext.vertxContext = new VertxContext(ContextManager.capture(), span.prepareForAsync());
    }
}
 
Example #10
Source File: HttpClientRequestImplHandleResponseInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    if (VertxContext.VERTX_VERSION < 38 || allArguments.length == 2) {
        HttpClientRequestContext requestContext = (HttpClientRequestContext) objInst.getSkyWalkingDynamicField();
        if (!requestContext.usingWebClient) {
            VertxContext context = requestContext.vertxContext;
            Tags.STATUS_CODE.set(context.getSpan(), Integer.toString(((HttpClientResponse) allArguments[0]).statusCode()));
            context.getSpan().asyncFinish();

            AbstractSpan span = ContextManager.createLocalSpan("#" + context.getSpan().getOperationName());
            span.setComponent(ComponentsDefine.VERTX);
            SpanLayer.asHttp(span);
            ContextManager.continued(context.getContextSnapshot());
        }
    }
}
 
Example #11
Source File: ServerConnectionHandleMessageInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    if (allArguments[0] instanceof HttpRequest) {
        HttpRequest request = (HttpRequest) allArguments[0];
        ContextCarrier contextCarrier = new ContextCarrier();
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            next.setHeadValue(request.headers().get(next.getHeadKey()));
            request.headers().remove(next.getHeadKey());
        }

        AbstractSpan span = ContextManager.createEntrySpan(toPath(request.getUri()), contextCarrier);
        span.setComponent(ComponentsDefine.VERTX);
        SpanLayer.asHttp(span);
        Tags.HTTP.METHOD.set(span, request.getMethod().toString());
        Tags.URL.set(span, request.getUri());

        objInst.setSkyWalkingDynamicField(new VertxContext(ContextManager.capture(), span.prepareForAsync()));
    }
}
 
Example #12
Source File: TracingServerCall.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void sendMessage(RESPONSE message) {
    // We just create the request on message span for server stream calls.
    if (!getMethodDescriptor().getType().serverSendsOneMessage()) {
        final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + RESPONSE_ON_MESSAGE_OPERATION_NAME);
        span.setComponent(ComponentsDefine.GRPC);
        span.setLayer(SpanLayer.RPC_FRAMEWORK);
        ContextManager.continued(contextSnapshot);

        try {
            super.sendMessage(message);
        } catch (Throwable t) {
            ContextManager.activeSpan().errorOccurred().log(t);
            throw t;
        } finally {
            ContextManager.stopSpan();
        }
    } else {
        super.sendMessage(message);
    }
}
 
Example #13
Source File: SWServerRPCPlugin.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void serverReceiveRequest(RPCContext context) {
    Map meta = context.requestCallMeta();

    ContextCarrier carrier = new ContextCarrier();
    CarrierItem items = carrier.items();
    while (items.hasNext()) {
        items = items.next();
        ByteBuffer buffer = (ByteBuffer) meta.get(new Utf8(items.getHeadKey()));
        items.setHeadValue(new String(buffer.array()));
    }

    String operationName = prefix + context.getMessage().getName();
    AbstractSpan span = ContextManager.createEntrySpan(operationName, carrier);
    SpanLayer.asRPCFramework(span);
    span.setComponent(ComponentsDefine.AVRO_SERVER);
}
 
Example #14
Source File: RestHighLevelClientIndexMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    IndexRequest indexRequest = (IndexRequest) (allArguments[0]);

    RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(Constants.INDEX_OPERATOR_NAME, restClientEnhanceInfo.getPeers());
    span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

    Tags.DB_TYPE.set(span, DB_TYPE);
    Tags.DB_INSTANCE.set(span, indexRequest.index());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, indexRequest.toString());
    }

    SpanLayer.asDB(span);
}
 
Example #15
Source File: ServerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public <REQUEST, RESPONSE> ServerCall.Listener<REQUEST> interceptCall(ServerCall<REQUEST, RESPONSE> call,
    Metadata headers, ServerCallHandler<REQUEST, RESPONSE> handler) {
    final ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        String contextValue = headers.get(Metadata.Key.of(next.getHeadKey(), Metadata.ASCII_STRING_MARSHALLER));
        if (!StringUtil.isEmpty(contextValue)) {
            next.setHeadValue(contextValue);
        }
    }

    final AbstractSpan span = ContextManager.createEntrySpan(OperationNameFormatUtil.formatOperationName(call.getMethodDescriptor()), contextCarrier);
    span.setComponent(ComponentsDefine.GRPC);
    span.setLayer(SpanLayer.RPC_FRAMEWORK);
    try {
        return new TracingServerCallListener<>(handler.startCall(new TracingServerCall<>(call, ContextManager.capture()), headers), call
            .getMethodDescriptor(), ContextManager.capture());
    } finally {
        ContextManager.stopSpan();
    }
}
 
Example #16
Source File: SkywalkingTraceFactory.java    From joyrpc with Apache License 2.0 6 votes vote down vote up
@Override
public void begin(final String name, final String component, final Map<String, String> tags) {
    Map<String, String> ctx = (Map<String, String>) invocation.removeAttachment(HIDDEN_KEY_TRACE_SKYWALKING);
    ContextCarrier contextCarrier = new ContextCarrier();
    if (ctx != null) {
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            next.setHeadValue(ctx.get(next.getHeadKey()));
        }
    }
    span = ContextManager.createEntrySpan(name, contextCarrier);
    span.setComponent(new OfficialComponent(componentId, component));
    tag(tags);
    SpanLayer.asRPCFramework(span);
}
 
Example #17
Source File: RestExecuteInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    final URI requestURL = (URI) allArguments[0];
    final HttpMethod httpMethod = (HttpMethod) allArguments[1];
    final ContextCarrier contextCarrier = new ContextCarrier();

    String remotePeer = requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : "https".equalsIgnoreCase(requestURL
        .getScheme()) ? 443 : 80);
    String formatURIPath = requestURL.getPath();
    AbstractSpan span = ContextManager.createExitSpan(formatURIPath, contextCarrier, remotePeer);

    span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE);
    Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL
        .getPath());
    Tags.HTTP.METHOD.set(span, httpMethod.toString());
    SpanLayer.asHttp(span);

    objInst.setSkyWalkingDynamicField(contextCarrier);
}
 
Example #18
Source File: RestExecuteInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    final URI requestURL = (URI) allArguments[0];
    final HttpMethod httpMethod = (HttpMethod) allArguments[1];
    final ContextCarrier contextCarrier = new ContextCarrier();

    String remotePeer = requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : "https".equalsIgnoreCase(requestURL
        .getScheme()) ? 443 : 80);

    String formatURIPath = requestURL.getPath();
    AbstractSpan span = ContextManager.createExitSpan(formatURIPath, contextCarrier, remotePeer);

    span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE);
    Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL
        .getPath());
    Tags.HTTP.METHOD.set(span, httpMethod.toString());
    SpanLayer.asHttp(span);
    Object[] cacheValues = new Object[3];
    cacheValues[0] = formatURIPath;
    cacheValues[1] = contextCarrier;
    objInst.setSkyWalkingDynamicField(cacheValues);
}
 
Example #19
Source File: SyncHttpRequestSendInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    HttpRequest request = (HttpRequest) objInst;
    ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(request.getURI()
                                                             .getPath(), contextCarrier, request.getHost() + ":" + request
        .getPort());
    span.setComponent(ComponentsDefine.JETTY_CLIENT);

    Tags.HTTP.METHOD.set(span, getHttpMethod(request));
    Tags.URL.set(span, request.getURI().toString());
    SpanLayer.asHttp(span);

    CarrierItem next = contextCarrier.items();
    HttpFields field = request.getHeaders();
    while (next.hasNext()) {
        next = next.next();
        field.add(next.getHeadKey(), next.getHeadValue());
    }
}
 
Example #20
Source File: MotanConsumerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {

    URL url = (URL) objInst.getSkyWalkingDynamicField();
    Request request = (Request) allArguments[0];
    if (url != null) {
        ContextCarrier contextCarrier = new ContextCarrier();
        String remotePeer = url.getHost() + ":" + url.getPort();
        AbstractSpan span = ContextManager.createExitSpan(generateOperationName(url, request), contextCarrier, remotePeer);
        span.setComponent(ComponentsDefine.MOTAN);
        Tags.URL.set(span, url.getIdentity());
        SpanLayer.asRPCFramework(span);
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            request.setAttachment(next.getHeadKey(), next.getHeadValue());
        }
    }
}
 
Example #21
Source File: MessageSendInterceptorTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessage() throws Throwable {
    messageSendInterceptor.beforeMethod(enhancedInstance, null, arguments, null, null);
    messageSendInterceptor.afterMethod(enhancedInstance, null, arguments, null, null);

    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));

    AbstractTracingSpan mqSpan = spans.get(0);

    SpanAssert.assertLayer(mqSpan, SpanLayer.MQ);
    SpanAssert.assertComponent(mqSpan, ComponentsDefine.ROCKET_MQ_PRODUCER);
    SpanAssert.assertTag(mqSpan, 0, "127.0.0.1");
    verify(messageRequestHeader).setProperties(anyString());
    verify(callBack).setSkyWalkingDynamicField(Matchers.any());
}
 
Example #22
Source File: ServerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                         MethodInterceptResult result) throws Throwable {
    Request request = (Request) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    if (request.getKvAttachment() == null) {
        request.setKvAttachment(new HashMap<>());
    }
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue((String) request.getKvAttachment().get(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(generateOperationName(request), contextCarrier);
    SpanLayer.asRPCFramework(span);
    span.setComponent(ComponentsDefine.BRPC_JAVA);
}
 
Example #23
Source File: ProducerOperationHandlerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    Invocation invocation = (Invocation) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(invocation.getContext().get(next.getHeadKey()));
    }
    String operationName = invocation.getMicroserviceQualifiedName();
    AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier);
    String url = invocation.getOperationMeta().getOperationPath();
    Tags.URL.set(span, url);
    span.setComponent(ComponentsDefine.SERVICECOMB);
    SpanLayer.asRPCFramework(span);
}
 
Example #24
Source File: SenderSendInterceptor.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 {
    Request req = (Request) objInst.getSkyWalkingDynamicField();
    final URI requestURL = req.getUrl().toURI();
    final METHOD httpMethod = req.getMethod();
    final ContextCarrier contextCarrier = new ContextCarrier();
    String remotePeer = requestURL.getHost() + ":" + requestURL.getPort();
    AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer);

    span.setComponent(ComponentsDefine.NUTZ_HTTP);
    Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL
        .getPath());
    Tags.HTTP.METHOD.set(span, httpMethod.toString());
    SpanLayer.asHttp(span);

    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        req.getHeader().set(next.getHeadKey(), next.getHeadValue());
    }
}
 
Example #25
Source File: RestHighLevelClientSearchMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    SearchRequest searchRequest = (SearchRequest) (allArguments[0]);

    RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(Constants.SEARCH_OPERATOR_NAME, restClientEnhanceInfo.getPeers());
    span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

    Tags.DB_TYPE.set(span, DB_TYPE);
    Tags.DB_INSTANCE.set(span, Arrays.asList(searchRequest.indices()).toString());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, searchRequest.toString());
    }

    SpanLayer.asDB(span);
}
 
Example #26
Source File: ArmeriaClientInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
protected void beforeMethod(final URI uri, final HttpMethod httpMethod, final String path) {
    final ContextCarrier contextCarrier = new ContextCarrier();
    final String remotePeer = uri.getHost() + ":" + uri.getPort();

    final AbstractSpan exitSpan = ContextManager.createExitSpan(path, contextCarrier, remotePeer);

    exitSpan.setComponent(ComponentsDefine.ARMERIA);
    exitSpan.setLayer(SpanLayer.HTTP);
    Tags.HTTP.METHOD.set(exitSpan, httpMethod.name());

    ContextManager.getRuntimeContext().put(KEY_SAFE_CLOSEABLE, Clients.withHttpHeaders(headers -> {
        HttpHeadersBuilder builder = headers.toBuilder();
        for (CarrierItem item = contextCarrier.items(); item.hasNext(); ) {
            item = item.next();
            builder.add(AsciiString.of(item.getHeadKey()), item.getHeadValue());
        }
        return builder.build();
    }));
}
 
Example #27
Source File: PreparedStatementExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
                               Class<?>[] argumentsTypes, MethodInterceptResult result) {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
    ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
    if (connectInfo == null) {
        return;
    }
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject
            .getStatementName()), connectInfo.getDatabasePeer());
    Tags.DB_TYPE.set(span, "sql");
    Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
    Tags.DB_STATEMENT.set(span, cacheObject.getSql());
    span.setComponent(connectInfo.getComponent());

    if (Config.Plugin.MARIADB.TRACE_SQL_PARAMETERS) {
        final Object[] parameters = cacheObject.getParameters();
        if (parameters != null && parameters.length > 0) {
            int maxIndex = cacheObject.getMaxIndex();
            SQL_PARAMETERS.set(span, getParameterString(parameters, maxIndex));
        }
    }

    SpanLayer.asDB(span);
}
 
Example #28
Source File: SynchronousDispatcherInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    HttpRequest request = (HttpRequest) allArguments[0];

    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHttpHeaders().getHeaderString(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(request.getUri().getPath(), contextCarrier);
    Tags.URL.set(span, toPath(request.getUri().getRequestUri().toString()));
    Tags.HTTP.METHOD.set(span, request.getHttpMethod());
    span.setComponent(ComponentsDefine.RESTEASY);
    SpanLayer.asHttp(span);
}
 
Example #29
Source File: PulsarConsumerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    if (allArguments[0] != null) {
        ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField();
        Message msg = (Message) allArguments[0];
        ContextCarrier carrier = new ContextCarrier();
        CarrierItem next = carrier.items();
        while (next.hasNext()) {
            next = next.next();
            next.setHeadValue(msg.getProperty(next.getHeadKey()));
        }
        AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + requiredInfo.getTopic() + CONSUMER_OPERATE_NAME + requiredInfo
            .getSubscriptionName(), carrier);
        activeSpan.setComponent(ComponentsDefine.PULSAR_CONSUMER);
        SpanLayer.asMQ(activeSpan);
        Tags.MQ_BROKER.set(activeSpan, requiredInfo.getServiceUrl());
        Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopic());
    }
}
 
Example #30
Source File: TransportClientHandlerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    Invocation invocation = (Invocation) allArguments[0];
    if (!checkRegisterStatus(invocation)) {
        return;
    }
    URI uri = new URI(invocation.getEndpoint().toString());
    String peer = uri.getHost() + ":" + uri.getPort();
    String operationName = invocation.getMicroserviceQualifiedName();
    final ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        invocation.getContext().put(next.getHeadKey(), next.getHeadValue());
    }
    String url = invocation.getOperationMeta().getOperationPath();
    Tags.URL.set(span, url);
    span.setComponent(ComponentsDefine.SERVICECOMB);
    SpanLayer.asRPCFramework(span);
}