Resolves the remote ip when behind proxy; fixes gh-1683
This commit is contained in:
@@ -330,6 +330,14 @@ public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
|
||||
@Override
|
||||
public boolean parseClientIpAndPort(Span span) {
|
||||
boolean clientIpAndPortParsed = super.parseClientIpAndPort(span);
|
||||
if (clientIpAndPortParsed) {
|
||||
return true;
|
||||
}
|
||||
return resolveFromInetAddress(span);
|
||||
}
|
||||
|
||||
private boolean resolveFromInetAddress(Span span) {
|
||||
InetSocketAddress addr = delegate.getRemoteAddress();
|
||||
if (addr == null) {
|
||||
return false;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class Issue502Tests {
|
||||
then(response).isEqualTo("foo");
|
||||
// retries
|
||||
then(this.spans).hasSize(1);
|
||||
//then(this.spans.get(0).tags().get("http.path")).isEqualTo("");
|
||||
// then(this.spans.get(0).tags().get("http.path")).isEqualTo("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -93,6 +93,11 @@ public class TraceWebFluxTests {
|
||||
// then
|
||||
thenNoSpanWasReported(spans, skippedPatternResponse, controller2);
|
||||
|
||||
// when (issue #1683)
|
||||
response = whenRequestWithXForwardedForIsSent(port, "/api/fn/20");
|
||||
// then
|
||||
thenSpanWasReportedWithRemoteIpTags(spans, response);
|
||||
|
||||
// cleanup
|
||||
context.close();
|
||||
}
|
||||
@@ -110,6 +115,15 @@ public class TraceWebFluxTests {
|
||||
then(spans.get(0).name()).isEqualTo("GET /api/c2/{id}");
|
||||
then(spans.get(0).tags()).containsEntry("mvc.controller.method", "successful")
|
||||
.containsEntry("mvc.controller.class", "Controller2");
|
||||
then(spans.get(0).remoteIp()).isEqualTo("127.0.0.1");
|
||||
}
|
||||
|
||||
private void thenSpanWasReportedWithRemoteIpTags(TestSpanHandler spans,
|
||||
ClientResponse response) {
|
||||
Awaitility.await()
|
||||
.untilAsserted(() -> then(response.statusCode().value()).isEqualTo(200));
|
||||
then(spans).hasSize(1);
|
||||
then(spans.get(0).remoteIp()).isEqualTo("203.0.113.195");
|
||||
}
|
||||
|
||||
private void thenFunctionalSpanWasReportedWithTags(TestSpanHandler spans,
|
||||
@@ -138,6 +152,14 @@ public class TraceWebFluxTests {
|
||||
return exchange.block();
|
||||
}
|
||||
|
||||
private ClientResponse whenRequestWithXForwardedForIsSent(int port, String path) {
|
||||
Mono<ClientResponse> exchange = WebClient.create().get()
|
||||
.uri("http://localhost:" + port + path)
|
||||
.header("X-Forwarded-For", "203.0.113.195, 70.41.3.18, 150.172.238.178")
|
||||
.exchange();
|
||||
return exchange.block();
|
||||
}
|
||||
|
||||
private ClientResponse whenRequestIsSentToSkippedPattern(int port) {
|
||||
Mono<ClientResponse> exchange = WebClient.create().get()
|
||||
.uri("http://localhost:" + port + "/skipped").exchange();
|
||||
|
||||
Reference in New Issue
Block a user