use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class MongoBaseTest method assertTrace.
protected void assertTrace(boolean success, String error) {
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertNotNull(mockSpan);
assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
assertEquals("mongodb-" + this.dbName, mockSpan.remoteServiceName());
assertEquals(this.cmdName, mockSpan.tag("mongodb.command"));
assertEquals("mongodb", mockSpan.tag("component.type"));
assertEquals(this.collection, mockSpan.tag("mongodb.collection"));
assertEquals(this.clusterId.getValue(), mockSpan.tag("mongodb.cluster_id"));
assertEquals(this.serverAddress.getHost(), mockSpan.remoteEndpoint().ipv4());
assertEquals(this.serverAddress.getPort(), mockSpan.remoteEndpoint().port());
if (success) {
assertNull(mockSpan.tag("error"));
}
if (!success) {
assertNotNull(mockSpan.tag("error"));
assertEquals(error, mockSpan.tag("error"));
}
assertNull(mockSpan.parentId());
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class KafkaProducerDoSendInterceptorTest method testRedirectedTag.
@Test
public void testRedirectedTag() {
KafkaAbstractConfigConstructInterceptor kafkaAbstractConfigConstructInterceptor = new KafkaAbstractConfigConstructInterceptor();
KafkaTestUtils.mockRedirect(() -> {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, TestConst.URIS);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { props }).build();
kafkaAbstractConfigConstructInterceptor.doBefore(methodInfo, EaseAgent.getContext());
MockKafkaProducer kafkaProducer = new MockKafkaProducer(props);
kafkaProducer.setEaseAgent$$DynamicField$$Data(props.getProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));
KafkaProducerDoSendInterceptor interceptor = new KafkaProducerDoSendInterceptor();
Context context = EaseAgent.getContext();
ProducerRecord record = new ProducerRecord<>(topic, key, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertEquals(TestConst.REDIRECT_URIS, mockSpan.tag("label.remote"));
});
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.
the class KafkaProducerDoSendInterceptorTest method doBefore.
@Test
public void doBefore() {
KafkaProducerDoSendInterceptor interceptor = new KafkaProducerDoSendInterceptor();
MockKafkaProducer kafkaProducer = MockKafkaProducer.buildOne();
Context context = EaseAgent.getContext();
ProducerRecord record = new ProducerRecord<>(topic, key, value);
MethodInfo methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
Span span = finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
checkBaseInfo(mockSpan);
assertEquals(key, mockSpan.tag(KafkaTags.KAFKA_KEY_TAG));
record = new ProducerRecord<>(topic, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
context = EaseAgent.getContext();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
span = finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
checkBaseInfo(mockSpan);
assertNull(mockSpan.tag(KafkaTags.KAFKA_KEY_TAG));
record = new ProducerRecord<>(topic, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
context = EaseAgent.getContext();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
assertNotNull(methodInfo.getArgs()[1]);
assertTrue(methodInfo.getArgs()[1] instanceof TraceCallback);
}
use of com.megaease.easeagent.plugin.report.tracing.ReportSpan 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.report.tracing.ReportSpan 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);
}
Aggregations