@Test public void spanIsNull() { spanStore.storeSpan(null); boolean result = spanStore.finishSpan(); assertThat(result, is(false)); verifyZeroInteractions(span); }
@Test public void spanIsNull() { spanStore.storeSpan(null); boolean result = spanStore.startSpan(); assertThat(result, is(false)); verifyZeroInteractions(span); } }
@Test public void tagsSpanIsNull() { when(adapter.getTags()).thenReturn(Collections.singletonMap("key", "value")); spanStore.storeSpan(null); boolean result = spanStore.finishSpan(adapter); assertThat(result, is(false)); verifyZeroInteractions(span); } }
@Test public void consecutiveCalls() throws Exception { SpanStore spanStore = mock(SpanStore.class); Object[] parameters = new Object[] { spanStore }; SpanBuilderImpl builder = mock(SpanBuilderImpl.class); SpanImpl span = mock(SpanImpl.class); SpanContextImpl spanContext = mock(SpanContextImpl.class); when(span.context()).thenReturn(spanContext); when(tracer.buildSpan(null, References.FOLLOWS_FROM, true)).thenReturn(builder); when(builder.build()).thenReturn(span); when(tracer.isCurrentContextExisting()).thenReturn(true); hook.beforeBody(1L, 2L, targetObject, parameters, rsc); hook.firstAfterBody(1L, 2L, targetObject, parameters, result, false, rsc); hook.secondAfterBody(null, 1L, 2L, targetObject, parameters, spanContext, false, rsc); hook.beforeBody(1L, 2L, targetObject, parameters, rsc); hook.firstAfterBody(1L, 2L, targetObject, parameters, result, false, rsc); hook.secondAfterBody(null, 1L, 2L, targetObject, parameters, spanContext, false, rsc); verify(tracer, times(2)).buildSpan(null, References.FOLLOWS_FROM, true); verify(builder, times(2)).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.PROCESS.toString()); verify(builder, times(2)).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); verify(builder, times(2)).withTag(ExtraTags.INSPECTT_METHOD_ID, 1L); verify(builder, times(2)).withTag(ExtraTags.INSPECTT_SENSOR_ID, 2L); verify(builder, times(2)).build(); verify(spanStore, times(2)).storeSpan(span); verify(asyncListener, times(2)).asyncSpanContextCreated(spanContext); verifyNoMoreInteractions(tracer, builder, spanStore, asyncListener); } }
@Test public void successful() throws Exception { SpanStore spanStore = mock(SpanStore.class); Object[] parameters = new Object[] { spanStore }; SpanBuilderImpl builder = mock(SpanBuilderImpl.class); SpanImpl span = mock(SpanImpl.class); SpanContextImpl spanContext = mock(SpanContextImpl.class); when(span.context()).thenReturn(spanContext); when(tracer.buildSpan(null, References.FOLLOWS_FROM, true)).thenReturn(builder); when(builder.build()).thenReturn(span); when(tracer.isCurrentContextExisting()).thenReturn(true); hook.beforeBody(1L, 2L, targetObject, parameters, rsc); hook.firstAfterBody(1L, 2L, targetObject, parameters, result, false, rsc); hook.secondAfterBody(null, 1L, 2L, targetObject, parameters, spanContext, false, rsc); verify(tracer).buildSpan(null, References.FOLLOWS_FROM, true); verify(builder).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.PROCESS.toString()); verify(builder).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); verify(builder).withTag(ExtraTags.INSPECTT_METHOD_ID, 1L); verify(builder).withTag(ExtraTags.INSPECTT_SENSOR_ID, 2L); verify(builder).build(); verify(spanStore).storeSpan(span); verify(asyncListener).asyncSpanContextCreated(spanContext); verifyNoMoreInteractions(tracer, builder, spanStore, asyncListener); }
@Test public void nestedCalls() throws Exception { SpanStore spanStore = mock(SpanStore.class); Object[] parameters = new Object[] { spanStore }; SpanBuilderImpl builder = mock(SpanBuilderImpl.class); SpanImpl span = mock(SpanImpl.class); SpanContextImpl spanContext = mock(SpanContextImpl.class); when(span.context()).thenReturn(spanContext); when(tracer.buildSpan(null, References.FOLLOWS_FROM, true)).thenReturn(builder); when(builder.build()).thenReturn(span); when(tracer.isCurrentContextExisting()).thenReturn(true); hook.beforeBody(1L, 2L, targetObject, parameters, rsc); hook.beforeBody(1L, 2L, targetObject, parameters, rsc); hook.firstAfterBody(1L, 2L, targetObject, parameters, result, false, rsc); hook.secondAfterBody(null, 1L, 2L, targetObject, parameters, spanContext, false, rsc); hook.firstAfterBody(1L, 2L, targetObject, parameters, result, false, rsc); hook.secondAfterBody(null, 1L, 2L, targetObject, parameters, spanContext, false, rsc); verify(tracer).buildSpan(null, References.FOLLOWS_FROM, true); verify(builder).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.PROCESS.toString()); verify(builder).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); verify(builder).withTag(ExtraTags.INSPECTT_METHOD_ID, 1L); verify(builder).withTag(ExtraTags.INSPECTT_SENSOR_ID, 2L); verify(builder).build(); verify(spanStore).storeSpan(span); verify(asyncListener).asyncSpanContextCreated(spanContext); verifyNoMoreInteractions(tracer, builder, spanStore, asyncListener); }
/** * Handles the {@link ClientRequestAdapter}. This method should be called when new client * request is created. * * @param <C> * type of carrier adapter is providing * @param requestAdapter * {@link ClientRequestAdapter} providing necessary information. * @return Created span */ public <C> SpanImpl handleAsyncRequest(AsyncClientRequestAdapter<C> requestAdapter) { SpanBuilderImpl builder = handleRequestInternal(requestAdapter); // nothing to do if builder was not created if (null == builder) { return null; } // just build the span and store it for later start SpanImpl span = builder.build(); SpanStore spanStore = new SpanStore(); spanStore.storeSpan(span); requestAdapter.getSpanStoreAdapter().setSpanStore(spanStore); // inject here as the context is created when span is started tracer.inject(span.context(), requestAdapter.getFormat(), requestAdapter.getCarrier()); return span; }
/** * {@inheritDoc} */ @Override public void beforeBody(long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc) { if (!REF_MARKER.isMarkerSet()) { if ((parameters.length > 0) && (parameters[0] instanceof SpanStore)) { SpanBuilderImpl builder = tracer.buildSpan(null, References.FOLLOWS_FROM, true); builder.withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.PROCESS.toString()); builder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); builder.withTag(ExtraTags.INSPECTT_METHOD_ID, methodId); builder.withTag(ExtraTags.INSPECTT_SENSOR_ID, sensorTypeId); SpanImpl span = builder.build(); SpanStore spanStore = (SpanStore) parameters[0]; spanStore.storeSpan(span); asyncSpanContextListener.asyncSpanContextCreated(span.context()); } } REF_MARKER.markCall(); }