ClientSpanServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { handleRequest(req, resp); } ClientSpanServlet();   ClientSpanServlet(TracingPlugin tracingPlugin, ServletPlugin servletPlugin);   }
@Test public void testConvertWeaselBeaconToSpan_withPageLoadBeacon() throws ServletException, IOException { final String userAgentHeader = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"; MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.addHeader("user-agent", userAgentHeader); mockHttpServletRequest.setParameter("ty", "pl"); mockHttpServletRequest.setParameter("r", "1496751574200"); mockHttpServletRequest.setParameter("u", "http: mockHttpServletRequest.setParameter("m_user", "tom.mason@example.com"); mockHttpServletRequest.setParameter("ts", "-197"); mockHttpServletRequest.setParameter("d", "518"); mockHttpServletRequest.setParameter("sp", "1"); mockHttpServletRequest.setParameter("m_bsp", "1"); mockHttpServletRequest.setParameter("t_unl", "0"); mockHttpServletRequest.setParameter("t_red", "0"); mockHttpServletRequest.setParameter("t_apc", "5"); mockHttpServletRequest.setParameter("t_dns", "0"); mockHttpServletRequest.setParameter("t_tcp", "0"); mockHttpServletRequest.setParameter("t_ssl", "2"); mockHttpServletRequest.setParameter("t_req", "38"); mockHttpServletRequest.setParameter("t_rsp", "4"); mockHttpServletRequest.setParameter("t_pro", "471"); mockHttpServletRequest.setParameter("t_loa", "5"); mockHttpServletRequest.setParameter("t_fp", "151"); mockHttpServletRequest.setParameter("k", "someKey"); mockHttpServletRequest.setParameter("t", "a6b5fd025be24191"); mockHttpServletRequest.setParameter("res", "{\"http: servlet.doPost(mockHttpServletRequest, new MockHttpServletResponse()); verify(reportingSpanEventListener, never()).update(any(), any(), any()); assertSoftly(softly -> { final List<MockSpan> finishedSpans = mockTracer.finishedSpans(); softly.assertThat(finishedSpans).hasSize(1); MockSpan span = finishedSpans.get(0); softly.assertThat(span.operationName()).isEqualTo("/petclinic/"); softly.assertThat(span.finishMicros() - span.startMicros()).isEqualTo(TimeUnit.MILLISECONDS.toMicros(518L)); final long redirect = 0L; final long appCacheLookup = 5L; final long dns = 0L; final long tcp = 0L; final long ssl = 2L; final long request = 38L; final long response = 4L; softly.assertThat(span.tags()) .containsEntry("type", "pageload") .doesNotContainEntry(Tags.SAMPLING_PRIORITY.getKey(), 0) .doesNotContainKey("user") .containsEntry("user_agent.header", userAgentHeader) .containsEntry("http.url", "http: .containsEntry("timing.unload", 0L) .containsEntry("timing.redirect", redirect) .containsEntry("timing.app_cache_lookup", appCacheLookup) .containsEntry("timing.dns_lookup", dns) .containsEntry("timing.tcp", tcp) .containsEntry("timing.ssl", ssl) .containsEntry("timing.request", request) .containsEntry("timing.response", response) .containsEntry("timing.processing", 471L) .containsEntry("timing.load", 5L) .containsEntry("timing.time_to_first_paint", 151L) .containsEntry("timing.resource", redirect + appCacheLookup + dns + tcp + ssl + request + response); }); }
@Test public void testConvertWeaselBeaconToSpan_withPageLoadBeacon_withBackendTraceId() throws ServletException, IOException { MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setParameter("ty", "pl"); mockHttpServletRequest.setParameter("d", "518"); mockHttpServletRequest.setParameter("r", "1496751574200"); mockHttpServletRequest.setParameter("ts", "-197"); mockHttpServletRequest.setParameter("t", "a6b5fd025be24191"); final String backendTraceId = "6210be349041096e"; mockHttpServletRequest.setParameter("bt", backendTraceId); final String backendSpanId = "6210be349041096e"; mockHttpServletRequest.setParameter("m_bs", backendSpanId); servlet.doPost(mockHttpServletRequest, new MockHttpServletResponse()); final List<MockSpan> finishedSpans = mockTracer.finishedSpans(); assertThat(finishedSpans).hasSize(1); MockSpan span = finishedSpans.get(0); final String spanIdOfPageloadTrace = B3HeaderFormat.getB3Identifiers(mockTracer, span).getSpanId(); final B3HeaderFormat.B3Identifiers traceIdsOfServerSpan = B3HeaderFormat.B3Identifiers.builder() .traceId(backendTraceId) .spanId(backendSpanId) .build(); final B3HeaderFormat.B3Identifiers newSpanIdentifiers = B3HeaderFormat.B3Identifiers.builder() .traceId(backendTraceId) .spanId(backendSpanId) .parentSpanId(spanIdOfPageloadTrace) .build(); verify(reportingSpanEventListener).update(eq(traceIdsOfServerSpan), eq(newSpanIdentifiers), eq(Collections.emptyMap())); assertSoftly(softly -> softly.assertThat(span.tags()) .containsEntry("type", "pageload") .containsEntry("trace_id", backendTraceId) .doesNotContainEntry(Tags.SAMPLING_PRIORITY.getKey(), 0)); }
@Test public void testConvertWeaselBeaconToSpan_withNegativeRedirectTimeIsDiscarded() throws ServletException, IOException { MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setParameter("ty", "pl"); mockHttpServletRequest.setParameter("r", "1496751574200"); mockHttpServletRequest.setParameter("u", "http: mockHttpServletRequest.setParameter("ts", "-197"); mockHttpServletRequest.setParameter("d", "518"); mockHttpServletRequest.setParameter("sp", "1"); mockHttpServletRequest.setParameter("t_unl", "0"); mockHttpServletRequest.setParameter("t_red", "-500"); mockHttpServletRequest.setParameter("t_apc", "5"); mockHttpServletRequest.setParameter("t_dns", "0"); mockHttpServletRequest.setParameter("t_tcp", "0"); mockHttpServletRequest.setParameter("t_ssl", "2"); mockHttpServletRequest.setParameter("t_req", "38"); mockHttpServletRequest.setParameter("t_rsp", "4"); mockHttpServletRequest.setParameter("t_pro", "471"); mockHttpServletRequest.setParameter("t_loa", "5"); mockHttpServletRequest.setParameter("t_fp", "151"); servlet.doPost(mockHttpServletRequest, new MockHttpServletResponse()); assertSpanIsDiscarded(); }
@Test public void testConvertWeaselBeaconToSpan_withDisabledSamplingFlagIsDiscarded() throws ServletException, IOException { MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setParameter("ty", "pl"); mockHttpServletRequest.setParameter("r", "1496751574200"); mockHttpServletRequest.setParameter("u", "http: mockHttpServletRequest.setParameter("ts", "-197"); mockHttpServletRequest.setParameter("d", "518"); mockHttpServletRequest.setParameter("sp", "0"); mockHttpServletRequest.setParameter("t_unl", "0"); mockHttpServletRequest.setParameter("t_red", "500"); mockHttpServletRequest.setParameter("t_apc", "5"); mockHttpServletRequest.setParameter("t_dns", "0"); mockHttpServletRequest.setParameter("t_tcp", "0"); mockHttpServletRequest.setParameter("t_ssl", "2"); mockHttpServletRequest.setParameter("t_req", "38"); mockHttpServletRequest.setParameter("t_rsp", "4"); mockHttpServletRequest.setParameter("t_pro", "471"); mockHttpServletRequest.setParameter("t_loa", "5"); mockHttpServletRequest.setParameter("t_fp", "151"); mockHttpServletRequest.setParameter("t_fp", "151"); servlet.doPost(mockHttpServletRequest, new MockHttpServletResponse()); assertSpanIsDiscarded(); }
@Test public void testConvertWeaselBeaconToSpan_withUnsampledBackendSpanFlagIsDiscarded() throws ServletException, IOException { MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setParameter("ty", "pl"); mockHttpServletRequest.setParameter("r", "1496751574200"); mockHttpServletRequest.setParameter("u", "http: mockHttpServletRequest.setParameter("ts", "-197"); mockHttpServletRequest.setParameter("d", "518"); mockHttpServletRequest.setParameter("sp", "1"); mockHttpServletRequest.setParameter("m_bsp", "0"); mockHttpServletRequest.setParameter("t_unl", "0"); mockHttpServletRequest.setParameter("t_red", "500"); mockHttpServletRequest.setParameter("t_apc", "5"); mockHttpServletRequest.setParameter("t_dns", "0"); mockHttpServletRequest.setParameter("t_tcp", "0"); mockHttpServletRequest.setParameter("t_ssl", "2"); mockHttpServletRequest.setParameter("t_req", "38"); mockHttpServletRequest.setParameter("t_rsp", "4"); mockHttpServletRequest.setParameter("t_pro", "471"); mockHttpServletRequest.setParameter("t_loa", "5"); mockHttpServletRequest.setParameter("t_fp", "151"); mockHttpServletRequest.setParameter("t_fp", "151"); servlet.doPost(mockHttpServletRequest, new MockHttpServletResponse()); assertSpanIsDiscarded(); }
@Test public void testConvertWeaselBeaconToSpan_skipsTagProcessorsIfSpanIsNotSampled() throws ServletException, IOException { when(tracingPlugin.isSampled(any())).thenReturn(false); MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setParameter("ty", "pl"); mockHttpServletRequest.setParameter("r", "1496751574200"); mockHttpServletRequest.setParameter("u", "http: mockHttpServletRequest.setParameter("m_user", "tom.mason@example.com"); mockHttpServletRequest.setParameter("ts", "-197"); mockHttpServletRequest.setParameter("d", "518"); mockHttpServletRequest.setParameter("t_unl", "0"); mockHttpServletRequest.setParameter("t_red", "0"); mockHttpServletRequest.setParameter("t_apc", "5"); mockHttpServletRequest.setParameter("t_dns", "0"); mockHttpServletRequest.setParameter("t_tcp", "0"); mockHttpServletRequest.setParameter("t_ssl", "0"); mockHttpServletRequest.setParameter("t_req", "38"); mockHttpServletRequest.setParameter("t_rsp", "4"); mockHttpServletRequest.setParameter("t_pro", "471"); mockHttpServletRequest.setParameter("t_loa", "5"); mockHttpServletRequest.setParameter("t_fp", "151"); servlet.doPost(mockHttpServletRequest, new MockHttpServletResponse()); assertSoftly(softly -> { final List<MockSpan> finishedSpans = mockTracer.finishedSpans(); softly.assertThat(finishedSpans).hasSize(1); MockSpan span = finishedSpans.get(0); softly.assertThat(span.tags()) .containsEntry("type", "pageload") .doesNotContainKeys(TIMING_UNLOAD, TIMING_REDIRECT, TIMING_APP_CACHE_LOOKUP, TIMING_DNS_LOOKUP, TIMING_TCP, TIMING_REQUEST, TIMING_RESPONSE, TIMING_PROCESSING, TIMING_LOAD, TIMING_TIME_TO_FIRST_PAINT, TIMING_RESOURCE); }); }
@Test public void testJsessionId() throws ServletException, IOException { MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setParameter("ty", "pl"); mockHttpServletRequest.setParameter("r", "1496751574200"); mockHttpServletRequest.setParameter("u", "http: mockHttpServletRequest.setParameter("d", "518"); servlet.doPost(mockHttpServletRequest, new MockHttpServletResponse()); assertThat(mockTracer.finishedSpans().get(0).operationName()).isEqualTo("/petclinic"); }
@Test public void testQueryParameter() throws ServletException, IOException { MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setParameter("ty", "pl"); mockHttpServletRequest.setParameter("r", "1496751574200"); mockHttpServletRequest.setParameter("u", "http: mockHttpServletRequest.setParameter("d", "518"); servlet.doPost(mockHttpServletRequest, new MockHttpServletResponse()); assertThat(mockTracer.finishedSpans().get(0).operationName()).isEqualTo("/petclinic"); }