Skip to content

Commit d0f7aa7

Browse files
authored
feat: add content-type checks for servlet instrumentations to ensure it's presence in span all times (#417)
* adding explicit checks for content-type * nit fix
1 parent 76362dc commit d0f7aa7

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30AndFilterInstrumentation.java

+11
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ public static void exit(
186186
if (throwable == null && !httpResponse.isCommitted()) {
187187
httpResponse.flushBuffer();
188188
}
189+
if (httpResponse.getContentType() != null && !httpResponse.getContentType().isEmpty()) {
190+
currentSpan.setAttribute(
191+
HypertraceSemanticAttributes.HTTP_RESPONSE_HEADER_CONTENT_TYPE,
192+
httpResponse.getContentType());
193+
}
194+
if (httpResponse.getCharacterEncoding() != null
195+
&& !httpResponse.getCharacterEncoding().isEmpty()) {
196+
currentSpan.setAttribute(
197+
HypertraceSemanticAttributes.HTTP_RESPONSE_HEADER_CONTENT_ENCODING,
198+
httpResponse.getCharacterEncoding());
199+
}
189200
for (String headerName : httpResponse.getHeaderNames()) {
190201
String headerValue = httpResponse.getHeader(headerName);
191202
currentSpan.setAttribute(

instrumentation/servlet/servlet-5.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v5_0/Servlet50AndFilterInstrumentation.java

+11
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ public static void exit(
190190
if (throwable == null && !httpResponse.isCommitted()) {
191191
httpResponse.flushBuffer();
192192
}
193+
if (httpResponse.getContentType() != null && !httpResponse.getContentType().isEmpty()) {
194+
currentSpan.setAttribute(
195+
HypertraceSemanticAttributes.HTTP_RESPONSE_HEADER_CONTENT_TYPE,
196+
httpResponse.getContentType());
197+
}
198+
if (httpResponse.getCharacterEncoding() != null
199+
&& !httpResponse.getCharacterEncoding().isEmpty()) {
200+
currentSpan.setAttribute(
201+
HypertraceSemanticAttributes.HTTP_RESPONSE_HEADER_CONTENT_ENCODING,
202+
httpResponse.getCharacterEncoding());
203+
}
193204
for (String headerName : httpResponse.getHeaderNames()) {
194205
String headerValue = httpResponse.getHeader(headerName);
195206
currentSpan.setAttribute(

0 commit comments

Comments
 (0)