@Test public void propagation() { when(spanImpl.context()).thenReturn(SpanContextImpl.build()); when(spanImpl.getTags()).thenReturn(Collections.singletonMap(ExtraTags.PROPAGATION_TYPE, PropagationType.JMS.toString())); AbstractSpan span = SpanTransformer.transformSpan(spanImpl); assertThat(span.getPropagationType(), is(PropagationType.JMS)); assertThat(span.getTags().size(), is(0)); }
/** * {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); long temp; temp = Double.doubleToLongBits(this.duration); result = (prime * result) + (int) (temp ^ (temp >>> 32)); result = (prime * result) + (int) (this.parentSpanId ^ (this.parentSpanId >>> 32)); result = (prime * result) + ((this.propagationType == null) ? 0 : this.propagationType.hashCode()); result = (prime * result) + ((this.referenceType == null) ? 0 : this.referenceType.hashCode()); result = (prime * result) + ((this.spanIdent == null) ? 0 : this.spanIdent.hashCode()); result = (prime * result) + ((this.tags == null) ? 0 : this.tags.hashCode()); return result; }
/** * Returns result of {@link #valueOf(String)} if the given parameter is not <code>null</code>. * * @param propagation * as string * @return {@link PropagationType} enum or <code>null</code> */ public static PropagationType safeValueOf(String propagation) { if (null != propagation) { return valueOf(propagation); } else { return null; } }
span.setPropagationType(PropagationType.safeValueOf(propagation));
/** * Returns styled string including the span propagation. * * @param propagationType * Propagation type. Can be <code>null</code>. Returns "Unknown" as the result. * @return Styled string. */ public static StyledString getPropagationStyled(PropagationType propagationType) { StyledString styledString = new StyledString(); if (propagationType == PropagationType.JAVASCRIPT) { styledString.append("JavaScript"); } else if (null != propagationType) { styledString.append(propagationType.toString()); } else { // if it's null we assume it's our SDK as we always set the propagation styledString.append("SDK"); } return styledString; }
@Test public void tagsNull() { when(requestAdapter.startClientSpan()).thenReturn(true); when(requestAdapter.getTags()).thenReturn(null); when(requestAdapter.getPropagationType()).thenReturn(PropagationType.HTTP); when(requestAdapter.getReferenceType()).thenReturn(References.FOLLOWS_FROM); SpanImpl result = interceptor.handleAsyncRequest(requestAdapter); assertThat(result, is(span)); verify(tracer).buildSpan(null, References.FOLLOWS_FROM, true); verify(tracer).inject(context, Format.Builtin.TEXT_MAP, carrier); verify(spanBuilder).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); verify(spanBuilder).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.HTTP.toString()); verify(spanBuilder).build(); verify(span).context(); ArgumentCaptor<SpanStore> spanStoreCaptor = ArgumentCaptor.forClass(SpanStore.class); verify(spanStoreAdapter).setSpanStore(spanStoreCaptor.capture()); assertThat(spanStoreCaptor.getValue().getSpan(), is(span)); verifyNoMoreInteractions(tracer, spanBuilder, span); verifyZeroInteractions(context); }
@Test public void tagsNull() { when(requestAdapter.startClientSpan()).thenReturn(true); when(requestAdapter.getTags()).thenReturn(null); when(requestAdapter.getPropagationType()).thenReturn(PropagationType.HTTP); when(requestAdapter.getReferenceType()).thenReturn(References.CHILD_OF); SpanImpl result = interceptor.handleRequest(requestAdapter); assertThat(result, is(span)); verify(tracer).buildSpan(null, References.CHILD_OF, true); verify(tracer).inject(context, Format.Builtin.TEXT_MAP, carrier); verify(spanBuilder).doNotReport(); verify(spanBuilder).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); verify(spanBuilder).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.HTTP.toString()); verify(spanBuilder).start(); verify(span).context(); verifyNoMoreInteractions(tracer, spanBuilder, span); verifyZeroInteractions(context); }
@Test public void happyPath() { when(requestAdapter.startClientSpan()).thenReturn(true); when(requestAdapter.getTags()).thenReturn(Collections.<String, String> singletonMap(Tags.HTTP_URL.getKey(), "value")); when(requestAdapter.getPropagationType()).thenReturn(PropagationType.HTTP); when(requestAdapter.getReferenceType()).thenReturn(References.FOLLOWS_FROM); SpanImpl result = interceptor.handleAsyncRequest(requestAdapter); assertThat(result, is(span)); verify(tracer).buildSpan(null, References.FOLLOWS_FROM, true); verify(tracer).inject(context, Format.Builtin.TEXT_MAP, carrier); verify(spanBuilder).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); verify(spanBuilder).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.HTTP.toString()); verify(spanBuilder).withTag(Tags.HTTP_URL.getKey(), "value"); verify(spanBuilder).build(); verify(span).context(); ArgumentCaptor<SpanStore> spanStoreCaptor = ArgumentCaptor.forClass(SpanStore.class); verify(spanStoreAdapter).setSpanStore(spanStoreCaptor.capture()); assertThat(spanStoreCaptor.getValue().getSpan(), is(span)); verifyNoMoreInteractions(tracer, spanBuilder, span); verifyZeroInteractions(context); }
@Test public void happyPath() { when(requestAdapter.startClientSpan()).thenReturn(true); when(requestAdapter.getTags()).thenReturn(Collections.<String, String> singletonMap(Tags.HTTP_URL.getKey(), "value")); when(requestAdapter.getPropagationType()).thenReturn(PropagationType.HTTP); when(requestAdapter.getReferenceType()).thenReturn(References.CHILD_OF); SpanImpl result = interceptor.handleRequest(requestAdapter); assertThat(result, is(span)); verify(tracer).buildSpan(null, References.CHILD_OF, true); verify(tracer).inject(context, Format.Builtin.TEXT_MAP, carrier); verify(spanBuilder).doNotReport(); verify(spanBuilder).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); verify(spanBuilder).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.HTTP.toString()); verify(spanBuilder).withTag(Tags.HTTP_URL.getKey(), "value"); verify(spanBuilder).start(); verify(span).context(); verifyNoMoreInteractions(tracer, spanBuilder, span); verifyZeroInteractions(context); }
@Test public void tagsNull() { when(requestAdapter.getTags()).thenReturn(null); when(requestAdapter.getReferenceType()).thenReturn("reference"); when(requestAdapter.getPropagationType()).thenReturn(PropagationType.HTTP); when(tracer.extract(Format.Builtin.TEXT_MAP, carrier)).thenReturn(context); when(spanContextStore.getSpanContext()).thenReturn(null); SpanImpl result = interceptor.handleRequest(requestAdapter); assertThat(result, is(span)); verify(tracer).buildSpan(); verify(tracer).extract(Format.Builtin.TEXT_MAP, carrier); verify(spanBuilder).addReference("reference", context); verify(spanBuilder).addReference(References.FOLLOWS_FROM, null); verify(spanBuilder).doNotReport(); verify(spanBuilder).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); verify(spanBuilder).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.HTTP.toString()); verify(spanBuilder).start(); verify(spanContextStore).setSpanContext(result.context()); verify(spanContextStore).getSpanContext(); verify(span, times(2)).context(); // one in test itself verifyNoMoreInteractions(tracer, spanBuilder, span, spanContextStore); verifyZeroInteractions(context, context2); }
@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); } }
builder.withTag(ExtraTags.PROPAGATION_TYPE, requestAdapter.getPropagationType().toString());
@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 happyPath() { when(requestAdapter.getReferenceType()).thenReturn("reference"); when(requestAdapter.getPropagationType()).thenReturn(PropagationType.HTTP); when(requestAdapter.getTags()).thenReturn(Collections.<String, String> singletonMap(Tags.HTTP_URL.getKey(), "value")); when(tracer.extract(Format.Builtin.TEXT_MAP, carrier)).thenReturn(context); when(spanContextStore.getSpanContext()).thenReturn(context2); SpanImpl result = interceptor.handleRequest(requestAdapter); assertThat(result, is(span)); verify(tracer).buildSpan(); verify(tracer).extract(Format.Builtin.TEXT_MAP, carrier); verify(spanBuilder).addReference("reference", context); verify(spanBuilder).addReference(References.FOLLOWS_FROM, context2); verify(spanBuilder).doNotReport(); verify(spanBuilder).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); verify(spanBuilder).withTag(ExtraTags.PROPAGATION_TYPE, PropagationType.HTTP.toString()); verify(spanBuilder).withTag(Tags.HTTP_URL.getKey(), "value"); verify(spanBuilder).start(); verify(spanContextStore).setSpanContext(result.context()); verify(spanContextStore).getSpanContext(); verify(span, times(2)).context(); // one in test itself verifyNoMoreInteractions(tracer, spanBuilder, span, spanContextStore); verifyZeroInteractions(context, context2); }
@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); }
builder.withTag(ExtraTags.PROPAGATION_TYPE, requestAdapter.getPropagationType().toString());
/** * {@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(); }