use of com.megaease.easeagent.plugin.api.trace.Scope in project easeagent by megaease.
the class AgentMDCScopeDecoratorTest method getV2.
@Test
public void getV2() {
Span eSpan = SpanImpl.build(tracing, tracing.tracer().nextSpan(), injector);
checkEmptySpanIds();
Span eSpan2 = SpanImpl.build(tracing, tracing.tracer().nextSpan(), injector);
checkEmptySpanIds();
try (Scope scope = eSpan.maybeScope()) {
checkSpanIds(eSpan);
eSpan2 = SpanImpl.build(tracing, tracing.tracer().nextSpan(), injector);
try (Scope s = eSpan2.maybeScope()) {
checkSpanIds(eSpan2);
}
checkSpanIds(eSpan);
}
checkEmptySpanIds();
}
use of com.megaease.easeagent.plugin.api.trace.Scope in project easeagent by megaease.
the class OkHttpTracingInterceptorTest method doBefore.
@Test
public void doBefore() {
Call call = OkHttpTestUtils.buildCall();
MethodInfo.MethodInfoBuilder methodInfoBuilder = MethodInfo.builder().invoker(call);
MethodInfo methodInfo = methodInfoBuilder.build();
Context context = EaseAgent.getContext();
OkHttpTracingInterceptor okHttpTracingInterceptor = new OkHttpTracingInterceptor();
MockEaseAgent.cleanLastSpan();
okHttpTracingInterceptor.before(methodInfo, context);
methodInfo = methodInfoBuilder.retValue(OkHttpTestUtils.responseBuilder(call).addHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE).build()).build();
okHttpTracingInterceptor.after(methodInfo, context);
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertNotNull(mockSpan);
assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
assertEquals(TestConst.RESPONSE_TAG_VALUE, mockSpan.tag(TestConst.RESPONSE_TAG_NAME));
assertNull(mockSpan.parentId());
call = OkHttpTestUtils.buildCall();
methodInfo = methodInfoBuilder.invoker(call).retValue(null).build();
okHttpTracingInterceptor.before(methodInfo, context);
methodInfo.retValue(OkHttpTestUtils.responseBuilder(call).addHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE).build());
RuntimeException runtimeException = new RuntimeException("test error");
methodInfo.throwable(runtimeException);
okHttpTracingInterceptor.after(methodInfo, context);
mockSpan = MockEaseAgent.getLastSpan();
assertNotNull(mockSpan);
assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
assertEquals(TestConst.RESPONSE_TAG_VALUE, mockSpan.tag(TestConst.RESPONSE_TAG_NAME));
assertNull(mockSpan.parentId());
call = OkHttpTestUtils.buildCall();
methodInfo = methodInfoBuilder.invoker(call).retValue(null).build();
Span span = context.nextSpan();
try (Scope ignored = span.maybeScope()) {
okHttpTracingInterceptor.before(methodInfo, context);
methodInfo.retValue(OkHttpTestUtils.responseBuilder(call).addHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE).build());
okHttpTracingInterceptor.after(methodInfo, context);
mockSpan = MockEaseAgent.getLastSpan();
assertEquals(span.traceIdString(), mockSpan.traceId());
assertEquals(span.spanIdString(), mockSpan.parentId());
assertNotNull(mockSpan.id());
}
}
use of com.megaease.easeagent.plugin.api.trace.Scope in project easeagent by megaease.
the class OkHttpAsyncTracingInterceptorTest method doBefore.
@Test
public void doBefore() throws InterruptedException {
ReportSpan mockSpan = runOne((call, callback) -> {
Response response = OkHttpTestUtils.responseBuilder(call).addHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE).build();
try {
callback.onResponse(call, response);
} catch (IOException e) {
throw new RuntimeException("onResponse fail.", e);
}
});
assertNotNull(mockSpan);
assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
assertEquals(TestConst.RESPONSE_TAG_VALUE, mockSpan.tag(TestConst.RESPONSE_TAG_NAME));
assertNull(mockSpan.parentId());
Context context = EaseAgent.getContext();
Span span = context.nextSpan();
try (Scope ignored = span.maybeScope()) {
mockSpan = runOne((call, callback) -> {
Response response = OkHttpTestUtils.responseBuilder(call).addHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE).build();
try {
callback.onResponse(call, response);
} catch (IOException e) {
throw new RuntimeException("onResponse fail.", e);
}
});
assertNotNull(mockSpan);
assertEquals(span.traceIdString(), mockSpan.traceId());
assertEquals(span.spanIdString(), mockSpan.parentId());
assertNotNull(mockSpan.id());
}
mockSpan = runOne((call, callback) -> {
callback.onFailure(call, new IOException("test error"));
});
assertNull(mockSpan);
}
use of com.megaease.easeagent.plugin.api.trace.Scope in project easeagent by megaease.
the class HttpClient5AsyncTracingInterceptorTest method doBefore.
@Test
public void doBefore() throws InterruptedException {
BasicHttpResponse basicHttpResponse = new BasicHttpResponse(200);
basicHttpResponse.setHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE);
ReportSpan mockSpan = runOne(httpResponseFutureCallback -> {
httpResponseFutureCallback.completed(basicHttpResponse);
});
assertNotNull(mockSpan);
assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
assertEquals(TestConst.RESPONSE_TAG_VALUE, mockSpan.tag(TestConst.RESPONSE_TAG_NAME));
assertNull(mockSpan.parentId());
Context context = EaseAgent.getContext();
Span span = context.nextSpan();
try (Scope scope = span.maybeScope()) {
mockSpan = runOne(httpResponseFutureCallback -> {
httpResponseFutureCallback.completed(basicHttpResponse);
});
assertNotNull(mockSpan);
assertEquals(span.traceIdString(), mockSpan.traceId());
assertEquals(span.spanIdString(), mockSpan.parentId());
assertNotNull(mockSpan.id());
}
mockSpan = runOne(httpResponseFutureCallback -> {
httpResponseFutureCallback.failed(new RuntimeException("test error"));
});
assertNull(mockSpan);
}
use of com.megaease.easeagent.plugin.api.trace.Scope in project easeagent by megaease.
the class CommonRedisTracingInterceptorTest method startTracing.
@Test
public void startTracing() {
CommonRedisTracingInterceptor commonRedisTracingInterceptor = new MockCommonRedisTracingInterceptor();
Context context = EaseAgent.getContext();
commonRedisTracingInterceptor.startTracing(context, name, null, null);
Span span = context.get(SPAN_KEY);
span.finish();
checkMockSpanInfo(Objects.requireNonNull(MockEaseAgent.getLastSpan()));
String cmd = "testCmd";
commonRedisTracingInterceptor.startTracing(context, name, null, cmd);
span = context.get(SPAN_KEY);
span.finish();
ReportSpan mockSpan = Objects.requireNonNull(MockEaseAgent.getLastSpan());
checkMockSpanInfo(mockSpan);
assertEquals(cmd, mockSpan.tag("redis.method"));
Span pSpan = context.nextSpan().start();
ReportSpan child;
try (Scope ignored = pSpan.maybeScope()) {
commonRedisTracingInterceptor.startTracing(context, name, null, null);
span = context.get(SPAN_KEY);
span.finish();
child = Objects.requireNonNull(MockEaseAgent.getLastSpan());
} finally {
pSpan.finish();
}
ReportSpan parent = Objects.requireNonNull(MockEaseAgent.getLastSpan());
assertEquals(parent.traceId(), child.traceId());
assertEquals(parent.id(), child.parentId());
assertNull(parent.parentId());
}
Aggregations