Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Oct 31, 2023
1 parent 037f8e7 commit 5258ece
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ public void extract(AddressPortSink sink, REQUEST request) {
return;
}
}

// try :authority (HTTP 2.0 pseudo-header)
for (String host : getter.getHttpRequestHeader(request, ":authority")) {
if (extractHost(sink, host, 0, host.length())) {
return;
}
}
}

private static boolean extractFromForwardedHeader(AddressPortSink sink, String forwarded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,6 @@ void shouldParseHost(
assertThat(sink.getPort()).isEqualTo(expectedPort);
}

@ParameterizedTest
@ArgumentsSource(HostArgs.class)
void shouldParsePseudoAuthority(
List<String> headers, @Nullable String expectedAddress, @Nullable Integer expectedPort) {
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "forwarded");
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "x-forwarded-host");
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "host");
doReturn(headers).when(getter).getHttpRequestHeader(REQUEST, ":authority");

AddressAndPort sink = new AddressAndPort();
underTest.extract(sink, REQUEST);

assertThat(sink.getAddress()).isEqualTo(expectedAddress);
assertThat(sink.getPort()).isEqualTo(expectedPort);
}

static final class HostArgs implements ArgumentsProvider {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ void shouldExtractServerAddressAndPortFromAuthorityPseudoHeader() {
void shouldExtractServerAddressAndPortFromHostHeader() {
Map<String, String> request = new HashMap<>();
request.put("header.host", "github.com:123");
request.put("header.:authority", "opentelemetry.io:42");

Map<String, String> response = new HashMap<>();
response.put("statusCode", "200");
Expand All @@ -505,31 +504,6 @@ void shouldExtractServerAddressAndPortFromHostHeader() {
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
}

@Test
void shouldExtractServerAddressAndPortFromAuthorityPseudoHeader() {
Map<String, String> request = new HashMap<>();
request.put("header.:authority", "opentelemetry.io:42");

Map<String, String> response = new HashMap<>();
response.put("statusCode", "200");

AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());

AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);

assertThat(startAttributes.build())
.containsOnly(
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
entry(SemanticAttributes.SERVER_PORT, 42L));

AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, response, null);
assertThat(endAttributes.build())
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
}

@Test
void shouldExtractPeerAddressEvenIfItDuplicatesClientAddress() {
Map<String, String> request = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,21 @@ void twoCamelServiceSpans() throws Exception {
equalTo(
SemanticAttributes.USER_AGENT_ORIGINAL,
"Jakarta Commons-HttpClient/3.1"),
satisfies(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
val -> val.isInstanceOf(Long.class)),
equalTo(SemanticAttributes.HTTP_ROUTE, "/serviceTwo"),
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
equalTo(SemanticAttributes.NET_HOST_NAME, "127.0.0.1"),
equalTo(SemanticAttributes.NET_HOST_PORT, portTwo),
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
satisfies(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
SemanticAttributes.NET_SOCK_PEER_PORT,
val -> val.isInstanceOf(Long.class)),
equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"),
satisfies(
SemanticAttributes.NET_SOCK_PEER_PORT,
SemanticAttributes.NET_SOCK_HOST_PORT,
val -> val.isInstanceOf(Long.class))),
span ->
span.hasName("POST /serviceTwo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,13 @@ protected SpanDataAssert assertServerSpan(
if (attrs.get(netHostPortKey) != null) {
assertThat(attrs).containsEntry(netHostPortKey, port);
}

AttributeKey<String> netSockPeerAddrKey =
getAttributeKey(SemanticAttributes.NET_SOCK_PEER_ADDR);
if (attrs.get(netSockPeerAddrKey) != null) {
assertThat(attrs)
.containsEntry(netSockPeerAddrKey, options.sockPeerAddr.apply(endpoint));
}
AttributeKey<Long> netSockPeerPortKey =
getAttributeKey(SemanticAttributes.NET_SOCK_PEER_PORT);
if (attrs.get(netSockPeerPortKey) != null) {
Expand All @@ -768,17 +775,6 @@ protected SpanDataAssert assertServerSpan(
.isInstanceOf(Long.class)
.isNotEqualTo(Long.valueOf(port)));
}
AttributeKey<String> netSockPeerAddrKey =
getAttributeKey(SemanticAttributes.NET_SOCK_PEER_ADDR);
if (attrs.get(netSockPeerAddrKey) != null) {
assertThat(attrs)
.containsEntry(netSockPeerAddrKey, options.sockPeerAddr.apply(endpoint));
}
AttributeKey<String> netSockHostAddrKey =
getAttributeKey(SemanticAttributes.NET_SOCK_PEER_ADDR);
if (attrs.get(netSockHostAddrKey) != null) {
assertThat(attrs).containsEntry(netSockHostAddrKey, "127.0.0.1");
}

assertThat(attrs)
.hasEntrySatisfying(
Expand Down

0 comments on commit 5258ece

Please sign in to comment.