Skip to content

Commit e08b840

Browse files
authored
Merge branch 'main' into merge_span_normalizer_into_grouper
2 parents 96936e0 + a3bcd18 commit e08b840

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.hypertrace.core.span.constants.v1.Http.HTTP_REQUEST_X_FORWARDED_FOR_HEADER;
2929
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_BODY_TRUNCATED;
3030
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_CONTENT_LENGTH;
31+
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_CONTENT_TYPE;
3132
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_HEADER;
3233
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_SIZE;
3334
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_STATUS_CODE;
@@ -816,6 +817,12 @@ public static Optional<String> getHttpRequestContentType(Event event) {
816817
event, List.of(RawSpanConstants.getValue(HTTP_REQUEST_CONTENT_TYPE))));
817818
}
818819

820+
public static Optional<String> getHttpResponseContentType(Event event) {
821+
return Optional.ofNullable(
822+
SpanAttributeUtils.getFirstAvailableStringAttribute(
823+
event, List.of(RawSpanConstants.getValue(HTTP_RESPONSE_CONTENT_TYPE))));
824+
}
825+
819826
public static boolean isHttpRequestCookie(String requestHeaderAttributeKey) {
820827
return requestHeaderAttributeKey.equals(REQUEST_COOKIE_HEADER_KEY);
821828
}

semantic-convention-utils/src/test/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtilsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.hypertrace.core.span.constants.v1.Http.HTTP_REQUEST_X_FORWARDED_FOR_HEADER;
2929
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_BODY_TRUNCATED;
3030
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_CONTENT_LENGTH;
31+
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_CONTENT_TYPE;
3132
import static org.hypertrace.core.span.constants.v1.Http.HTTP_RESPONSE_SIZE;
3233
import static org.hypertrace.core.span.constants.v1.Http.HTTP_USER_AGENT_REQUEST_HEADER;
3334
import static org.hypertrace.core.span.constants.v1.Http.HTTP_USER_AGENT_WITH_DASH;
@@ -513,6 +514,16 @@ public void testGetHttpRequestContentType() {
513514
HttpSemanticConventionUtils.getHttpRequestContentType(event));
514515
}
515516

517+
@Test
518+
public void testGetHttpResponseContentType() {
519+
Event event =
520+
createMockEventWithAttribute(
521+
RawSpanConstants.getValue(HTTP_RESPONSE_CONTENT_TYPE), "application/text");
522+
assertEquals(
523+
Optional.of("application/text"),
524+
HttpSemanticConventionUtils.getHttpResponseContentType(event));
525+
}
526+
516527
@Test
517528
public void testGetHttpRequestSize() {
518529
Event event = createMockEventWithAttribute(RawSpanConstants.getValue(HTTP_REQUEST_SIZE), "100");

0 commit comments

Comments
 (0)