TraceHttpResponseInterceptor { public void process(HttpResponse response, TraceContext traceContext) { if (traceContext == null) { return; } Labels.Builder labels = Labels.builder(); TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.RESPONSE_SIZE, response.getHeader(HttpHeaders.CONTENT_LENGTH)); labels.add(HttpLabels.HTTP_STATUS_CODE, Integer.toString(response.getStatus())); tracer.annotateSpan(traceContext, labels.build()); tracer.endSpan(traceContext); } TraceHttpResponseInterceptor();  TraceHttpResponseInterceptor(Tracer tracer); void process(HttpResponse response, TraceContext traceContext);  }
@Test public void testProcess_WithContext() throws IOException { TraceContext traceContext = tracer.startSpan("test"); tracer.reset(); responseInterceptor.process(response, traceContext); assertThat(tracer.endSpanEvents).hasSize(1); EndSpanEvent endEvent = tracer.endSpanEvents.get(0); assertThat(endEvent.getTraceContext()).isEqualTo(traceContext); assertThat(tracer.annotateEvents).hasSize(1); AnnotateEvent annotateEvent = tracer.annotateEvents.get(0); assertThat(annotateEvent.getLabels().getLabels()).containsAllOf( new Label("/response/size", "123"), new Label("/http/status_code", "200") ); assertThat(annotateEvent.getTraceContext()).isEqualTo(traceContext); }
@Test public void testProcess_WithoutContext() throws IOException { responseInterceptor.process(response, null); assertThat(tracer.startSpanEvents).hasSize(0); assertThat(tracer.endSpanEvents).hasSize(0); assertThat(tracer.annotateEvents).hasSize(0); }