@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { ClientHttpRequest clientHttpRequest = (ClientHttpRequest)ret; if (clientHttpRequest instanceof AbstractClientHttpRequest) { AbstractClientHttpRequest httpRequest = (AbstractClientHttpRequest)clientHttpRequest; ContextCarrier contextCarrier = (ContextCarrier)objInst.getSkyWalkingDynamicField(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); httpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue()); } } return ret; }
@Test public void test1() throws Exception { RestTemplate restTemplate = new RestTemplate(); String forObject = restTemplate.getForObject(webServer.getCallHttpUrl(), String.class); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); verifier.verifyTrace(event("REST_TEMPLATE", RestTemplate.class.getConstructor())); verifier.verifyTrace(event("REST_TEMPLATE", AbstractClientHttpRequest.class.getMethod("execute"), annotation("http.status.code", 200))); }
@Test public void test2() throws Exception { RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); String forObject = restTemplate.getForObject(webServer.getCallHttpUrl(), String.class); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); verifier.verifyTrace(event("REST_TEMPLATE", RestTemplate.class.getConstructor())); verifier.verifyTrace(event("REST_TEMPLATE", AbstractClientHttpRequest.class.getMethod("execute"), annotation("http.status.code", 200))); }