use of com.megaease.easeagent.plugin.api.context.RequestContext in project easeagent by megaease.
the class TracingImplTest method clientRequest.
@Test
public void clientRequest() {
RequestMock requestMock = new RequestMock().setKind(Span.Kind.CLIENT).setName(name);
assertFalse(iTracing.hasCurrentSpan());
RequestContext requestContext = iTracing.clientRequest(requestMock);
assertTrue(iTracing.hasCurrentSpan());
MutableSpan mutableSpan = TracingProviderImplMock.getMutableSpan(requestContext.span());
assertEquals(brave.Span.Kind.CLIENT, mutableSpan.kind());
assertEquals(name, mutableSpan.name());
try (Scope scope = requestContext.scope()) {
assertNull(requestContext.span().parentIdString());
RequestContext requestContext2 = iTracing.clientRequest(requestMock);
assertEquals(requestContext.span().traceIdString(), requestContext2.span().traceIdString());
assertEquals(requestContext.span().spanIdString(), requestContext2.span().parentIdString());
requestContext2.scope().close();
}
assertFalse(iTracing.hasCurrentSpan());
}
use of com.megaease.easeagent.plugin.api.context.RequestContext in project easeagent by megaease.
the class WebClientFilterTracingInterceptorTest method doBefore.
@Test
public void doBefore() throws URISyntaxException {
WebClientFilterTracingInterceptor interceptor = new WebClientFilterTracingInterceptor();
Context context = EaseAgent.getContext();
URI uri = new URI(url);
ClientRequest clientRequest = MockClientRequest.build(uri);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).build();
interceptor.doBefore(methodInfo, context);
RequestContext requestContext = context.get(interceptor.getProgressKey());
assertNotNull(requestContext);
requestContext.scope().close();
requestContext.span().finish();
assertNull(requestContext.span().parentIdString());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(requestContext.span(), mockSpan);
ClientRequest request = (ClientRequest) methodInfo.getArgs()[0];
Collection<String> headers = request.headers().toSingleValueMap().values();
assertTrue(headers.contains(mockSpan.traceId()));
assertTrue(headers.contains(mockSpan.id()));
Span span = context.nextSpan().start();
try (Scope ignored = span.maybeScope()) {
clientRequest = MockClientRequest.build(uri);
methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).build();
interceptor.doBefore(methodInfo, context);
requestContext = context.get(interceptor.getProgressKey());
requestContext.scope().close();
requestContext.span().finish();
mockSpan = MockEaseAgent.getLastSpan();
assertEquals(span.traceIdString(), mockSpan.traceId());
assertEquals(span.spanIdString(), mockSpan.parentId());
}
span.finish();
}
use of com.megaease.easeagent.plugin.api.context.RequestContext in project easeagent by megaease.
the class GatewayAccessLogInterceptorTest method before.
@Test
public void before() {
GatewayAccessLogInterceptor interceptor = new GatewayAccessLogInterceptor();
Context context = EaseAgent.getContext();
MockServerWebExchange mockServerWebExchange = TestServerWebExchangeUtils.mockServerWebExchange();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { mockServerWebExchange }).build();
interceptor.before(methodInfo, context);
RequestInfo requestInfo = (RequestInfo) mockServerWebExchange.getAttributes().get(RequestInfo.class.getName());
assertNotNull(requestInfo);
verify(requestInfo, TimeUtils.startTime(context, startTime));
assertNull(requestInfo.getTraceId());
assertNull(requestInfo.getSpanId());
assertNull(requestInfo.getParentSpanId());
mockServerWebExchange = TestServerWebExchangeUtils.mockServerWebExchange();
methodInfo = MethodInfo.builder().args(new Object[] { mockServerWebExchange }).build();
interceptor.before(methodInfo, context);
RequestContext requestContext = GatewayServerTracingInterceptorTest.beforeGatewayServerTracing(mockServerWebExchange);
Span span = requestContext.span();
try (Scope ignored = requestContext.scope()) {
interceptor.before(methodInfo, context);
requestInfo = (RequestInfo) mockServerWebExchange.getAttributes().get(RequestInfo.class.getName());
assertNotNull(requestInfo);
verify(requestInfo, TimeUtils.startTime(context, startTime));
assertEquals(span.traceIdString(), requestInfo.getTraceId());
assertEquals(span.spanIdString(), requestInfo.getSpanId());
assertEquals(span.parentIdString(), requestInfo.getParentSpanId());
}
}
use of com.megaease.easeagent.plugin.api.context.RequestContext in project easeagent by megaease.
the class HttpHeadersFilterTracingInterceptorTest method doAfter.
@Test
public void doAfter() {
HttpHeadersFilterTracingInterceptor interceptor = new HttpHeadersFilterTracingInterceptor();
MockServerWebExchange mockServerWebExchange = TestServerWebExchangeUtils.mockServerWebExchange();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { null, mockServerWebExchange }).retValue(new HttpHeaders()).build();
interceptor.doAfter(methodInfo, EaseAgent.getContext());
assertNull(mockServerWebExchange.getAttribute(GatewayCons.CHILD_SPAN_KEY));
mockServerWebExchange = TestServerWebExchangeUtils.mockServerWebExchange();
methodInfo = MethodInfo.builder().args(new Object[] { null, mockServerWebExchange }).retValue(new HttpHeaders()).build();
RequestContext requestContext = GatewayServerTracingInterceptorTest.beforeGatewayServerTracing(mockServerWebExchange);
Span span = requestContext.span();
try (Scope ignored = requestContext.scope()) {
interceptor.doAfter(methodInfo, EaseAgent.getContext());
RequestContext clientContext = mockServerWebExchange.getAttribute(GatewayCons.CHILD_SPAN_KEY);
HttpHeaders ret = (HttpHeaders) methodInfo.getRetValue();
Collection<String> headers = ret.toSingleValueMap().values();
assertTrue(headers.contains(clientContext.span().traceIdString()));
assertTrue(headers.contains(clientContext.span().spanIdString()));
assertTrue(headers.contains(clientContext.span().parentIdString()));
assertEquals(span.traceIdString(), clientContext.span().traceIdString());
assertEquals(span.spanIdString(), clientContext.span().parentIdString());
clientContext.scope().close();
}
}
use of com.megaease.easeagent.plugin.api.context.RequestContext in project easeagent by megaease.
the class WebClientFilterTracingInterceptor method doBefore.
@Override
public void doBefore(MethodInfo methodInfo, Context context) {
HttpRequest request = getRequest(methodInfo);
RequestContext requestContext = context.clientRequest(request);
Span span = requestContext.span();
HttpUtils.handleReceive(span.start(), request);
context.put(getProgressKey(), requestContext);
}
Aggregations