Skip to content

how to implement asynchronous tracking of the webclient in WebFlux. #7434

@kin122

Description

@kin122

Please answer these questions before submitting your issue.

  • Why do you submit this issue?
  • [ * ] Question or discussion

Question

  • What do you want to know?
    hi ,Mr Wu.
    We want to implement asynchronous tracking of the webclient in WebFlux.
    So we try to modify the WebFluxWebClientInterceptor in spring-webflux-5.x-webclient-plugin.
    The code is as follows:
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInvocationContext context) throws Throwable {
        if (allArguments[0] == null) {
            //illegal args,can't trace ignore
            return;
        }
       // ################# here are the code we injected###########################
        LOGGER.info("getSkyWalkingDynamicField-------------{}", objInst.getSkyWalkingDynamicField());
        for (int i = 0; i < allArguments.length; i++) {
            LOGGER.info("----allArguments[{}]-----{}---------", i, allArguments[i]);
        }
        ClientRequest request = (ClientRequest) allArguments[0];
        final ContextCarrier contextCarrier = new ContextCarrier();

        URI uri = request.url();
        final String requestURIString = getRequestURIString(uri);
        final String operationName = requestURIString;
        final String remotePeer = getIPAndPort(uri);
        AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer);

        //set components name
        span.setComponent(ComponentsDefine.SPRING_WEBCLIENT);
        Tags.URL.set(span, uri.toString());
        Tags.HTTP.METHOD.set(span, request.method().toString());
        SpanLayer.asHttp(span);

        if (request instanceof EnhancedInstance) {
            ((EnhancedInstance) request).setSkyWalkingDynamicField(contextCarrier);
        }

        //user async interface
        span.prepareForAsync();
        ContextManager.stopSpan();

        context.setContext(span);
    }

We would like to use objInst.getSkyWalkingDynamicField() to get the traceid, but always get null.

May I ask if this method is feasible to get the traceid of the webclient ?
Or give me some suggestion,please.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThe description doesn't fit the case.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions