@Test public void testParseUserAgent() throws Exception { doReturn(true).when(servletPlugin).isParseUserAgent(); final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test.js"); request.addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"); final MonitoredHttpRequest monitoredHttpRequest = createMonitoredHttpRequest(request); Span span = monitoredHttpRequest.createSpan(); Scope scope = tracer.scopeManager().activate(span); span.finish(); scope.close(); assertEquals(1, tracer.finishedSpans().size()); final MockSpan mockSpan = tracer.finishedSpans().get(0); assertThat(mockSpan.tags()).containsEntry("user_agent.browser", "Chrome"); }
@Override public Span createSpan() { boolean sample = true; if (servletPlugin.isHonorDoNotTrackHeader() && "1".equals(httpServletRequest.getHeader("dnt"))) { sample = false; } final Tracer tracer = tracingPlugin.getTracer(); io.opentracing.SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, new HttpServletRequestTextMapExtractAdapter(httpServletRequest)); Tracer.SpanBuilder spanBuilder = tracer.buildSpan(getRequestName()) .asChildOf(spanCtx) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); if (widgetAndStagemonitorEndpointsAllowed) { spanBuilder = spanBuilder.withTag(WIDGET_ALLOWED_ATTRIBUTE, (String) null); } if (!sample) { spanBuilder = spanBuilder.withTag(Tags.SAMPLING_PRIORITY.getKey(), 0); } spanBuilder.withTag(SpanUtils.OPERATION_TYPE, "http"); final Span span = spanBuilder.start(); Tags.HTTP_URL.set(span, httpServletRequest.getRequestURI()); Tags.PEER_PORT.set(span, httpServletRequest.getRemotePort()); span.setTag("method", httpServletRequest.getMethod()); span.setTag("http.referring_site", getReferringSite()); if (servletPlugin.isCollectHttpHeaders()) { SpanUtils.setHttpHeaders(span, getHeaders(httpServletRequest)); } SpanContextInformation info = SpanContextInformation.forSpan(span); info.addRequestAttribute(CONNECTION_ID_ATTRIBUTE, connectionId); info.addRequestAttribute(MONITORED_HTTP_REQUEST_ATTRIBUTE, this); if (tracingPlugin.isSampled(span) && servletPlugin.isParseUserAgent() && StringUtils.isNotEmpty(userAgentHeader)) { parseUserAgentAsync(span, info); } return span; }
MonitoredHttpRequest extends MonitoredRequest { @Override public Span createSpan() { boolean sample = true; if (servletPlugin.isHonorDoNotTrackHeader() && "1".equals(httpServletRequest.getHeader("dnt"))) { sample = false; } final Tracer tracer = tracingPlugin.getTracer(); io.opentracing.SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, new HttpServletRequestTextMapExtractAdapter(httpServletRequest)); Tracer.SpanBuilder spanBuilder = tracer.buildSpan(getRequestName()) .asChildOf(spanCtx) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); if (widgetAndStagemonitorEndpointsAllowed) { spanBuilder = spanBuilder.withTag(WIDGET_ALLOWED_ATTRIBUTE, (String) null); } if (!sample) { spanBuilder = spanBuilder.withTag(Tags.SAMPLING_PRIORITY.getKey(), 0); } spanBuilder.withTag(SpanUtils.OPERATION_TYPE, "http"); final Span span = spanBuilder.start(); Tags.HTTP_URL.set(span, httpServletRequest.getRequestURI()); Tags.PEER_PORT.set(span, httpServletRequest.getRemotePort()); span.setTag("method", httpServletRequest.getMethod()); span.setTag("http.referring_site", getReferringSite()); if (servletPlugin.isCollectHttpHeaders()) { SpanUtils.setHttpHeaders(span, getHeaders(httpServletRequest)); } SpanContextInformation info = SpanContextInformation.forSpan(span); info.addRequestAttribute(CONNECTION_ID_ATTRIBUTE, connectionId); info.addRequestAttribute(MONITORED_HTTP_REQUEST_ATTRIBUTE, this); if (tracingPlugin.isSampled(span) && servletPlugin.isParseUserAgent() && StringUtils.isNotEmpty(userAgentHeader)) { parseUserAgentAsync(span, info); } return span; } }
MonitoredHttpRequest extends MonitoredRequest { @Override public Span createSpan() { boolean sample = true; if (servletPlugin.isHonorDoNotTrackHeader() && "1".equals(httpServletRequest.getHeader("dnt"))) { sample = false; } final Tracer tracer = tracingPlugin.getTracer(); io.opentracing.SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, new HttpServletRequestTextMapExtractAdapter(httpServletRequest)); Tracer.SpanBuilder spanBuilder = tracer.buildSpan(getRequestName()) .asChildOf(spanCtx) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); if (widgetAndStagemonitorEndpointsAllowed) { spanBuilder = spanBuilder.withTag(WIDGET_ALLOWED_ATTRIBUTE, (String) null); } if (!sample) { spanBuilder = spanBuilder.withTag(Tags.SAMPLING_PRIORITY.getKey(), 0); } spanBuilder.withTag(SpanUtils.OPERATION_TYPE, "http"); final Span span = spanBuilder.start(); Tags.HTTP_URL.set(span, httpServletRequest.getRequestURI()); Tags.PEER_PORT.set(span, httpServletRequest.getRemotePort()); span.setTag("method", httpServletRequest.getMethod()); span.setTag("http.referring_site", getReferringSite()); if (servletPlugin.isCollectHttpHeaders()) { SpanUtils.setHttpHeaders(span, getHeaders(httpServletRequest)); } SpanContextInformation info = SpanContextInformation.forSpan(span); info.addRequestAttribute(CONNECTION_ID_ATTRIBUTE, connectionId); info.addRequestAttribute(MONITORED_HTTP_REQUEST_ATTRIBUTE, this); if (tracingPlugin.isSampled(span) && servletPlugin.isParseUserAgent() && StringUtils.isNotEmpty(userAgentHeader)) { parseUserAgentAsync(span, info); } return span; } MonitoredHttpRequest(HttpServletRequest httpServletRequest,
								StatusExposingByteCountingServletResponse responseWrapper,
								FilterChain filterChain, ConfigurationRegistry configuration, ExecutorService userAgentParsingExecutor); }
MonitoredHttpRequest extends MonitoredRequest { @Override public Span createSpan() { boolean sample = true; if (servletPlugin.isHonorDoNotTrackHeader() && "1".equals(httpServletRequest.getHeader("dnt"))) { sample = false; } final Tracer tracer = tracingPlugin.getTracer(); io.opentracing.SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, new HttpServletRequestTextMapExtractAdapter(httpServletRequest)); Tracer.SpanBuilder spanBuilder = tracer.buildSpan(getRequestName()) .asChildOf(spanCtx) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); if (widgetAndStagemonitorEndpointsAllowed) { spanBuilder = spanBuilder.withTag(WIDGET_ALLOWED_ATTRIBUTE, (String) null); } if (!sample) { spanBuilder = spanBuilder.withTag(Tags.SAMPLING_PRIORITY.getKey(), 0); } spanBuilder.withTag(SpanUtils.OPERATION_TYPE, "http"); final Span span = spanBuilder.start(); Tags.HTTP_URL.set(span, httpServletRequest.getRequestURI()); Tags.PEER_PORT.set(span, httpServletRequest.getRemotePort()); span.setTag("method", httpServletRequest.getMethod()); span.setTag("http.referring_site", getReferringSite()); if (servletPlugin.isCollectHttpHeaders()) { SpanUtils.setHttpHeaders(span, getHeaders(httpServletRequest)); } SpanContextInformation info = SpanContextInformation.forSpan(span); info.addRequestAttribute(CONNECTION_ID_ATTRIBUTE, connectionId); info.addRequestAttribute(MONITORED_HTTP_REQUEST_ATTRIBUTE, this); if (tracingPlugin.isSampled(span) && servletPlugin.isParseUserAgent() && StringUtils.isNotEmpty(userAgentHeader)) { parseUserAgentAsync(span, info); } return span; } MonitoredHttpRequest(HttpServletRequest httpServletRequest,
								StatusExposingByteCountingServletResponse responseWrapper,
								FilterChain filterChain, ConfigurationRegistry configuration, ExecutorService userAgentParsingExecutor); @Override Span createSpan(); static String getClientIp(HttpServletRequest request); String getRequestName(); static String getRequestNameByRequest(HttpServletRequest request, ServletPlugin servletPlugin); static String removeSemicolonContent(String requestUri); @Override void execute(); }
MonitoredHttpRequest extends MonitoredRequest { @Override public Span createSpan() { boolean sample = true; if (servletPlugin.isHonorDoNotTrackHeader() && "1".equals(httpServletRequest.getHeader("dnt"))) { sample = false; } final Tracer tracer = tracingPlugin.getTracer(); io.opentracing.SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, new HttpServletRequestTextMapExtractAdapter(httpServletRequest)); Tracer.SpanBuilder spanBuilder = tracer.buildSpan(getRequestName()) .asChildOf(spanCtx) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); if (widgetAndStagemonitorEndpointsAllowed) { spanBuilder = spanBuilder.withTag(WIDGET_ALLOWED_ATTRIBUTE, (String) null); } if (!sample) { spanBuilder = spanBuilder.withTag(Tags.SAMPLING_PRIORITY.getKey(), 0); } spanBuilder.withTag(SpanUtils.OPERATION_TYPE, "http"); final Span span = spanBuilder.start(); Tags.HTTP_URL.set(span, httpServletRequest.getRequestURI()); Tags.PEER_PORT.set(span, httpServletRequest.getRemotePort()); span.setTag("method", httpServletRequest.getMethod()); span.setTag("http.referring_site", getReferringSite()); if (servletPlugin.isCollectHttpHeaders()) { SpanUtils.setHttpHeaders(span, getHeaders(httpServletRequest)); } SpanContextInformation info = SpanContextInformation.forSpan(span); info.addRequestAttribute(CONNECTION_ID_ATTRIBUTE, connectionId); info.addRequestAttribute(MONITORED_HTTP_REQUEST_ATTRIBUTE, this); if (tracingPlugin.isSampled(span) && servletPlugin.isParseUserAgent() && StringUtils.isNotEmpty(userAgentHeader)) { parseUserAgentAsync(span, info); } return span; } MonitoredHttpRequest(HttpServletRequest httpServletRequest,
								StatusExposingByteCountingServletResponse responseWrapper,
								FilterChain filterChain, ConfigurationRegistry configuration, ExecutorService userAgentParsingExecutor); @Override Span createSpan(); static String getClientIp(HttpServletRequest request); String getRequestName(); static String getRequestNameByRequest(HttpServletRequest request, ServletPlugin servletPlugin); static String removeSemicolonContent(String requestUri); @Override void execute(); static final String CONNECTION_ID_ATTRIBUTE; static final String WIDGET_ALLOWED_ATTRIBUTE; static final String MONITORED_HTTP_REQUEST_ATTRIBUTE; static final String USER_AGENT_PARSED_FUTURE_ATTRIBUTE; }