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);
}
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;
}
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);
}
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();
}
Aggregations