@Test public void baggageInjection() { String key = "key"; String value = "value"; ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(urlConnection, null, rsc); adapter.getCarrier().put(key, value); verify(urlConnection).setRequestProperty(key, value); verifyZeroInteractions(rsc); }
@BeforeMethod public void setup() { when(requestAdapter.getFormat()).thenReturn(Format.Builtin.TEXT_MAP); when(requestAdapter.getCarrier()).thenReturn(carrier); when(tracer.buildSpan(anyString(), anyString(), anyBoolean())).thenReturn(spanBuilder); when(spanBuilder.start()).thenReturn(span); when(span.context()).thenReturn(context); }
@Test public void baggageInjection() { String key = "key"; String value = "value"; ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(object, new Object[] { null, httpRequest }, rsc); adapter.getCarrier().put(key, value); verify(httpRequest).setHeader(key, value); verifyZeroInteractions(object, rsc); } }
@Test public void baggageInjectionHeadersNull() { String key = "key"; String value = "value"; when(httpRequest.getHeaders()).thenReturn(null); ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(httpRequest, null, rsc); adapter.getCarrier().put(key, value); verifyNoMoreInteractions(rsc); } }
@Test public void baggageInjection() { String key = "key"; String value = "value"; when(httpRequest.getHeaders()).thenReturn(headers); ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(httpRequest, null, rsc); adapter.getCarrier().put(key, value); verify(headers).set(key, value); verifyNoMoreInteractions(rsc); }
@Test public void baggageInjection() throws Exception { String key = "key"; String value = "value"; when(rsc.getParameterTypes()).thenReturn(Collections.singletonList("javax.jms.Message")); ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(object, new Object[] { message }, rsc); adapter.getCarrier().put(key, value); verify(message).setStringProperty(key, value); verifyZeroInteractions(object); } }
/** * 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 handleRequest(ClientRequestAdapter<C> requestAdapter) { SpanBuilderImpl builder = handleRequestInternal(requestAdapter); // nothing to do if builder was not created if (null == builder) { return null; } // set no reporting as we will do it ourselves in case on sync requests builder.doNotReport(); // start SpanImpl span = builder.start(); // inject here as the context is created when span is started tracer.inject(span.context(), requestAdapter.getFormat(), requestAdapter.getCarrier()); return span; }