use of com.megaease.easeagent.plugin.api.Context 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.Context in project easeagent by megaease.
the class MongoReactiveMetricCommandListener method commandStarted.
@Override
public void commandStarted(CommandStartedEvent event) {
// LOGGER.warn("reactive commandStarted metric");
Context context = EaseAgent.getContext();
MongoCtx mongoCtx = MongoCtx.getOrCreate(context);
MetricHelper.commandStarted(context, event);
mongoCtx.put(MongoUtils.METRIC, this.mongoMetric);
mongoCtx.put(MongoUtils.CONFIG, this.config);
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class MongoReactiveMetricCommandListener method commandFailed.
@Override
public void commandFailed(CommandFailedEvent event) {
// LOGGER.warn("reactive commandFailed metric");
Context context = EaseAgent.getContext();
context.put(MongoUtils.EVENT_KEY, event);
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class TraceCallbackTest method onCompletion.
@Test
public void onCompletion() throws InterruptedException {
Context context = EaseAgent.getContext();
Span span = context.nextSpan().start();
TraceCallback traceCallback = new TraceCallback(span, null);
traceCallback.onCompletion(null, null);
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
assertFalse(mockSpan.hasError());
span = context.nextSpan().start();
String errorInfo = "test error";
traceCallback = new TraceCallback(span, null);
traceCallback.onCompletion(null, new RuntimeException(errorInfo));
mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
assertTrue(mockSpan.hasError());
assertEquals(errorInfo, mockSpan.errorInfo());
AtomicBoolean ran = new AtomicBoolean(false);
span = context.nextSpan().start();
final TraceCallback traceCallbackAsync = new TraceCallback(span, (metadata, exception) -> {
assertTrue(EaseAgent.getContext().currentTracing().hasCurrentSpan());
ran.set(true);
});
Thread thread = new Thread(() -> traceCallbackAsync.onCompletion(null, null));
thread.start();
thread.join();
mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
assertFalse(mockSpan.hasError());
assertTrue(ran.get());
}
use of com.megaease.easeagent.plugin.api.Context 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);
}
Aggregations