Search in sources :

Example 16 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class KafkaMessageListenerTracingInterceptorTest method doAfter.

@Test
public void doAfter() {
    KafkaMessageListenerTracingInterceptor interceptor = new KafkaMessageListenerTracingInterceptor();
    Context context = EaseAgent.getContext();
    MockEaseAgent.cleanLastSpan();
    interceptor.doAfter(null, context);
    assertNull(MockEaseAgent.getLastSpan());
    Span span = context.nextSpan().start();
    context.put(KafkaMessageListenerTracingInterceptor.SPAN, span);
    MethodInfo methodInfo = MethodInfo.builder().build();
    interceptor.doAfter(methodInfo, context);
    ReportSpan mockSpan = MockEaseAgent.getLastSpan();
    SpanTestUtils.sameId(span, mockSpan);
    String errorInfo = "test error";
    methodInfo = MethodInfo.builder().throwable(new RuntimeException(errorInfo)).build();
    span = context.nextSpan().start();
    context.put(KafkaMessageListenerTracingInterceptor.SPAN, span);
    interceptor.doAfter(methodInfo, context);
    mockSpan = MockEaseAgent.getLastSpan();
    SpanTestUtils.sameId(span, mockSpan);
    assertTrue(mockSpan.tags().containsKey("error"));
    assertEquals(errorInfo, mockSpan.tags().get("error"));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 17 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class SpanImplTest method flush.

@Test
public void flush() {
    Span eSpan = SpanImpl.build(tracing, tracing.tracer().nextSpan(), injector);
    eSpan.start();
    eSpan.flush();
    assertNull(MockReport.getLastSpan());
    assertNotNull(MockReport.getLastSkipSpan());
    ReportSpan reportSpan = MockReport.getLastSkipSpan();
    Assert.assertNotNull(reportSpan);
    assertEquals(eSpan.traceIdString(), reportSpan.traceId());
    assertEquals(eSpan.spanIdString(), reportSpan.id());
}
Also used : ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 18 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class ConvertSpanReporter method report.

@Override
public void report(MutableSpan span) {
    maybeAddErrorTag(span);
    ReportSpan converted = convert(span);
    delegate.report(converted);
}
Also used : ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan)

Example 19 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class TracingProviderImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    ThreadLocalCurrentTraceContext traceContext = ThreadLocalCurrentTraceContext.newBuilder().addScopeDecorator(AgentMDCScopeDecorator.get()).addScopeDecorator(AgentMDCScopeDecorator.getV2()).addScopeDecorator(AgentMDCScopeDecorator.getAgentDecorator()).build();
    serviceName = new AutoRefreshConfigItem<>(config, ConfigConst.SERVICE_NAME, Config::getString);
    /*
        String target = config.getString("observability.tracings.output.target");
        String zipkinUrl = config.getString("observability.tracings.output.target.zipkinUrl");
        Boolean compressionEnabled = config.getBoolean("observability.tracings.output.target.zipkin.compressionEnabled");

        boolean toZipkin = false;
        if (target != null && target.equalsIgnoreCase("zipkin") && StringUtils.isNotEmpty(zipkinUrl)) {
            toZipkin = true;
        }
        String zipkinUrlFromEnv = System.getenv(ENV_ZIPKIN_SERVER_URL);
        if (StringUtils.isNotEmpty(zipkinUrlFromEnv)) {
            toZipkin = true;
            zipkinUrl = zipkinUrlFromEnv;
        }
        Reporter<Span> reporter;
        if (toZipkin) {
            reporter = AsyncReporter.create(URLConnectionSender.newBuilder()
                .endpoint(zipkinUrl)
                .compressionEnabled(compressionEnabled == null || compressionEnabled).build());
        } else {
            reporter = span -> agentReport.report(span);
        }
        */
    Reporter<ReportSpan> reporter;
    reporter = span -> agentReport.report(span);
    this.tracing = Tracing.newBuilder().localServiceName(getServiceName()).traceId128Bit(false).sampler(CountingSampler.create(1)).addSpanHandler(new CustomTagsSpanHandler(this::getServiceName, AdditionalAttributes.getHostName())).addSpanHandler(ConvertZipkinSpanHandler.builder(reporter).alwaysReportSpans(true).build()).currentTraceContext(traceContext).build();
}
Also used : ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) ThreadLocalCurrentTraceContext(brave.propagation.ThreadLocalCurrentTraceContext)

Example 20 with ReportSpan

use of com.megaease.easeagent.plugin.report.tracing.ReportSpan in project easeagent by megaease.

the class TraceReport method initSpanRefreshableReporter.

private RefreshableReporter<ReportSpan> initSpanRefreshableReporter(Config configs) {
    SenderWithEncoder sender = ReporterRegistry.getSender(ReportConfigConst.TRACE_SENDER, configs);
    TraceAsyncProps traceProperties = TraceAsyncProps.newDefault(configs);
    GlobalExtrasSupplier extrasSupplier = new GlobalExtrasSupplier() {

        final AutoRefreshConfigItem<String> serviceName = new AutoRefreshConfigItem<>(configs, ConfigConst.SERVICE_NAME, Config::getString);

        final AutoRefreshConfigItem<String> systemName = new AutoRefreshConfigItem<>(configs, ConfigConst.SYSTEM_NAME, Config::getString);

        @Override
        public String service() {
            return serviceName.getValue();
        }

        @Override
        public String system() {
            return systemName.getValue();
        }
    };
    SDKAsyncReporter<ReportSpan> reporter = SDKAsyncReporter.builderSDKAsyncReporter(sender, traceProperties, extrasSupplier);
    reporter.startFlushThread();
    return new RefreshableReporter<>(reporter, traceProperties);
}
Also used : GlobalExtrasSupplier(com.megaease.easeagent.report.encoder.span.GlobalExtrasSupplier) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) SenderWithEncoder(com.megaease.easeagent.report.sender.SenderWithEncoder) TraceAsyncProps(com.megaease.easeagent.report.async.TraceAsyncProps) AutoRefreshConfigItem(com.megaease.easeagent.config.AutoRefreshConfigItem)

Aggregations

ReportSpan (com.megaease.easeagent.plugin.report.tracing.ReportSpan)54 Test (org.junit.Test)46 Context (com.megaease.easeagent.plugin.api.Context)38 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)36 Span (com.megaease.easeagent.plugin.api.trace.Span)28 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)10 Scope (com.megaease.easeagent.plugin.api.trace.Scope)9 Message (org.springframework.amqp.core.Message)6 URI (java.net.URI)5 MockEaseAgent (com.megaease.easeagent.mock.plugin.api.MockEaseAgent)4 EaseAgentJunit4ClassRunner (com.megaease.easeagent.mock.plugin.api.junit.EaseAgentJunit4ClassRunner)4 EaseAgent (com.megaease.easeagent.plugin.bridge.EaseAgent)4 MockKafkaConsumer (com.megaease.easeagent.plugin.kafka.interceptor.MockKafkaConsumer)4 ArrayList (java.util.ArrayList)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Assert (org.junit.Assert)4 RunWith (org.junit.runner.RunWith)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ClientRequest (org.springframework.web.reactive.function.client.ClientRequest)3