Search in sources :

Example 6 with SpanBuilder

use of io.opentracing.Tracer.SpanBuilder in project hono by eclipse.

the class LoraProtocolAdapterTest method setUp.

/**
 * Sets up the fixture.
 */
@BeforeEach
public void setUp() {
    vertx = mock(Vertx.class);
    final Context context = VertxMockSupport.mockContext(vertx);
    webClient = mock(WebClient.class);
    this.properties = givenDefaultConfigurationProperties();
    createClients();
    prepareClients();
    processMessageSpan = mock(Span.class);
    when(processMessageSpan.context()).thenReturn(mock(SpanContext.class));
    final Span otherSpan = mock(Span.class);
    when(otherSpan.context()).thenReturn(mock(SpanContext.class));
    final SpanBuilder processMessageSpanBuilder = mock(SpanBuilder.class, withSettings().defaultAnswer(RETURNS_SELF));
    when(processMessageSpanBuilder.start()).thenReturn(processMessageSpan);
    final SpanBuilder otherSpanBuilder = mock(SpanBuilder.class, withSettings().defaultAnswer(RETURNS_SELF));
    when(otherSpanBuilder.start()).thenReturn(otherSpan);
    final Tracer tracer = mock(Tracer.class);
    when(tracer.buildSpan(eq(LoraProtocolAdapter.SPAN_NAME_PROCESS_MESSAGE))).thenReturn(processMessageSpanBuilder);
    when(tracer.buildSpan(argThat(opName -> !opName.equals(LoraProtocolAdapter.SPAN_NAME_PROCESS_MESSAGE)))).thenReturn(otherSpanBuilder);
    final HttpAdapterMetrics metrics = mock(HttpAdapterMetrics.class);
    when(metrics.startTimer()).thenReturn(mock(Sample.class));
    adapter = new LoraProtocolAdapter(webClient);
    adapter.setConfig(properties);
    adapter.setTracer(tracer);
    adapter.init(vertx, context);
    adapter.setMetrics(metrics);
    setServiceClients(adapter);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) Context(io.vertx.core.Context) CommandContext(org.eclipse.hono.client.command.CommandContext) HttpContext(org.eclipse.hono.service.http.HttpContext) SpanContext(io.opentracing.SpanContext) HttpURLConnection(java.net.HttpURLConnection) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) LoraProviderMalformedPayloadException(org.eclipse.hono.adapter.lora.providers.LoraProviderMalformedPayloadException) RoutingContext(io.vertx.ext.web.RoutingContext) Context(io.vertx.core.Context) RETURNS_SELF(org.mockito.Mockito.RETURNS_SELF) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) CommandContext(org.eclipse.hono.client.command.CommandContext) Set(java.util.Set) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Future(io.vertx.core.Future) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Buffer(io.vertx.core.buffer.Buffer) CommandConsumer(org.eclipse.hono.client.command.CommandConsumer) VertxMockSupport(org.eclipse.hono.test.VertxMockSupport) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Span(io.opentracing.Span) Mockito.withSettings(org.mockito.Mockito.withSettings) CommandEndpoint(org.eclipse.hono.util.CommandEndpoint) HttpAdapterMetrics(org.eclipse.hono.adapter.http.HttpAdapterMetrics) QoS(org.eclipse.hono.util.QoS) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpContext(org.eclipse.hono.service.http.HttpContext) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpResponse(io.vertx.ext.web.client.HttpResponse) LoraProvider(org.eclipse.hono.adapter.lora.providers.LoraProvider) WebClient(io.vertx.ext.web.client.WebClient) Command(org.eclipse.hono.client.command.Command) HashMap(java.util.HashMap) ClientErrorException(org.eclipse.hono.client.ClientErrorException) SpanBuilder(io.opentracing.Tracer.SpanBuilder) DeviceUser(org.eclipse.hono.service.auth.DeviceUser) TracingHandler(org.eclipse.hono.service.http.TracingHandler) ProtocolAdapterTestSupport(org.eclipse.hono.adapter.test.ProtocolAdapterTestSupport) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) Tracer(io.opentracing.Tracer) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) Sample(io.micrometer.core.instrument.Timer.Sample) Mockito.verify(org.mockito.Mockito.verify) SpanContext(io.opentracing.SpanContext) HttpRequest(io.vertx.ext.web.client.HttpRequest) HttpProtocolAdapterProperties(org.eclipse.hono.adapter.http.HttpProtocolAdapterProperties) Handler(io.vertx.core.Handler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SpanBuilder(io.opentracing.Tracer.SpanBuilder) SpanContext(io.opentracing.SpanContext) Tracer(io.opentracing.Tracer) Sample(io.micrometer.core.instrument.Timer.Sample) Vertx(io.vertx.core.Vertx) WebClient(io.vertx.ext.web.client.WebClient) Span(io.opentracing.Span) HttpAdapterMetrics(org.eclipse.hono.adapter.http.HttpAdapterMetrics) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with SpanBuilder

use of io.opentracing.Tracer.SpanBuilder in project hono by eclipse.

the class TracingMockSupport method mockSpanBuilder.

/**
 * Creates a mocked OpenTracing SpanBuilder for creating a given Span.
 * <p>
 * All invocations on the mock are stubbed to return the builder by default.
 *
 * @param spanToCreate The object that the <em>start</em> method of the
 *                     returned builder should produce.
 * @return The builder.
 */
public static SpanBuilder mockSpanBuilder(final Span spanToCreate) {
    final SpanBuilder spanBuilder = mock(SpanBuilder.class, Mockito.RETURNS_SELF);
    when(spanBuilder.start()).thenReturn(spanToCreate);
    return spanBuilder;
}
Also used : SpanBuilder(io.opentracing.Tracer.SpanBuilder)

Example 8 with SpanBuilder

use of io.opentracing.Tracer.SpanBuilder in project motan by weibocom.

the class OpenTracingFilter method processRefererTrace.

/**
 * process trace in client end
 *
 * @param caller
 * @param request
 * @return
 */
protected Response processRefererTrace(Tracer tracer, Caller<?> caller, Request request) {
    String operationName = buildOperationName(request);
    SpanBuilder spanBuilder = tracer.buildSpan(operationName);
    Span activeSpan = OpenTracingContext.getActiveSpan();
    if (activeSpan != null) {
        spanBuilder.asChildOf(activeSpan);
    }
    Span span = spanBuilder.start();
    span.setTag("requestId", request.getRequestId());
    attachTraceInfo(tracer, span, request);
    return process(caller, request, span);
}
Also used : SpanBuilder(io.opentracing.Tracer.SpanBuilder) Span(io.opentracing.Span)

Example 9 with SpanBuilder

use of io.opentracing.Tracer.SpanBuilder in project motan by weibocom.

the class OpenTracingFilter method extractTraceInfo.

protected Span extractTraceInfo(Request request, Tracer tracer) {
    String operationName = buildOperationName(request);
    SpanBuilder span = tracer.buildSpan(operationName);
    try {
        SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(request.getAttachments()));
        if (spanContext != null) {
            span.asChildOf(spanContext);
        }
    } catch (Exception e) {
        span.withTag("Error", "extract from request fail, error msg:" + e.getMessage());
    }
    return span.start();
}
Also used : SpanBuilder(io.opentracing.Tracer.SpanBuilder) TextMapExtractAdapter(io.opentracing.propagation.TextMapExtractAdapter) SpanContext(io.opentracing.SpanContext)

Aggregations

SpanBuilder (io.opentracing.Tracer.SpanBuilder)9 SpanContext (io.opentracing.SpanContext)6 Tracer (io.opentracing.Tracer)5 Scope (io.opentracing.Scope)3 Span (io.opentracing.Span)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 RequestTraceSpan (fish.payara.notification.requesttracing.RequestTraceSpan)1 RequestTraceSpanContext (fish.payara.notification.requesttracing.RequestTraceSpanContext)1 RequestTracingService (fish.payara.nucleus.requesttracing.RequestTracingService)1 MapToTextMap (fish.payara.opentracing.propagation.MapToTextMap)1 Sample (io.micrometer.core.instrument.Timer.Sample)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)1 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpServerRequest (io.vertx.core.http.HttpServerRequest)1 HttpServerResponse (io.vertx.core.http.HttpServerResponse)1