diff --git a/instrumentation/servlet/servlet-5.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v5_0/Servlet50AndFilterInstrumentation.java b/instrumentation/servlet/servlet-5.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v5_0/Servlet50AndFilterInstrumentation.java index 6200c286..58945054 100644 --- a/instrumentation/servlet/servlet-5.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v5_0/Servlet50AndFilterInstrumentation.java +++ b/instrumentation/servlet/servlet-5.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v5_0/Servlet50AndFilterInstrumentation.java @@ -187,6 +187,9 @@ public static void exit( if (!request.isAsyncStarted()) { if (instrumentationConfig.httpHeaders().response()) { + if (throwable == null && !httpResponse.isCommitted()) { + httpResponse.flushBuffer(); + } for (String headerName : httpResponse.getHeaderNames()) { String headerValue = httpResponse.getHeader(headerName); currentSpan.setAttribute( @@ -216,6 +219,7 @@ public static void exit( urlEncodedMapContextStore); } } + } catch (IOException ignored) { } finally { Throwable tmp = throwable; while (tmp != null) { // loop in case our exception is nested (eg. springframework)