Skip to content

Commit 9b08ab6

Browse files
committed
Add config property for disabling REST Client stacktrace capture
Closes: quarkusio#36092
1 parent af4208a commit 9b08ab6

File tree

8 files changed

+50
-6
lines changed

8 files changed

+50
-6
lines changed

extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class RestClientConfig {
5151
EMPTY.userAgent = Optional.empty();
5252
EMPTY.http2 = Optional.empty();
5353
EMPTY.alpn = Optional.empty();
54+
EMPTY.captureStacktrace = Optional.empty();
5455
}
5556

5657
public RestClientMultipartConfig multipart;
@@ -267,6 +268,13 @@ public class RestClientConfig {
267268
@ConfigItem
268269
public Optional<Boolean> alpn;
269270

271+
/**
272+
* If {@code true}, the stacktrace of the invocation of the REST Client method is captured.
273+
* This stacktrace will be used if the invocation throws an exception
274+
*/
275+
@ConfigItem
276+
public Optional<Boolean> captureStacktrace;
277+
270278
public static RestClientConfig load(String configKey) {
271279
final RestClientConfig instance = new RestClientConfig();
272280

@@ -299,6 +307,7 @@ public static RestClientConfig load(String configKey) {
299307
instance.name = getConfigValue(configKey, "name", String.class);
300308
instance.userAgent = getConfigValue(configKey, "user-agent", String.class);
301309
instance.http2 = getConfigValue(configKey, "http2", Boolean.class);
310+
instance.captureStacktrace = getConfigValue(configKey, "capture-stacktrace", Boolean.class);
302311

303312
instance.multipart = new RestClientMultipartConfig();
304313
instance.multipart.maxChunkSize = getConfigValue(configKey, "multipart.max-chunk-size", Integer.class);
@@ -339,6 +348,7 @@ public static RestClientConfig load(Class<?> interfaceClass) {
339348
instance.userAgent = getConfigValue(interfaceClass, "user-agent", String.class);
340349
instance.http2 = getConfigValue(interfaceClass, "http2", Boolean.class);
341350
instance.alpn = getConfigValue(interfaceClass, "alpn", Boolean.class);
351+
instance.captureStacktrace = getConfigValue(interfaceClass, "capture-stacktrace", Boolean.class);
342352

343353
instance.multipart = new RestClientMultipartConfig();
344354
instance.multipart.maxChunkSize = getConfigValue(interfaceClass, "multipart.max-chunk-size", Integer.class);

extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RestClientsConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ public class RestClientsConfig {
300300
@ConfigItem
301301
public Optional<Boolean> alpn;
302302

303+
/**
304+
* If {@code true}, the stacktrace of the invocation of the REST Client method is captured.
305+
* This stacktrace will be used if the invocation throws an exception
306+
*/
307+
@ConfigItem(defaultValue = "true")
308+
public boolean captureStacktrace;
309+
303310
public RestClientConfig getClientConfig(String configKey) {
304311
if (configKey == null) {
305312
return RestClientConfig.EMPTY;

extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientCDIDelegateBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ private void configureCustomProperties(QuarkusRestClientBuilder builder) {
135135
if (alpn.isPresent()) {
136136
builder.property(QuarkusRestClientProperties.ALPN, alpn.get());
137137
}
138+
139+
Boolean captureStacktrace = oneOf(clientConfigByClassName().captureStacktrace,
140+
clientConfigByConfigKey().captureStacktrace).orElse(configRoot.captureStacktrace);
141+
builder.property(QuarkusRestClientProperties.CAPTURE_STACKTRACE, captureStacktrace);
138142
}
139143

140144
private void configureProxy(QuarkusRestClientBuilder builder) {

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/api/QuarkusRestClientProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ public class QuarkusRestClientProperties {
7878
*/
7979
public static final String ALPN = "io.quarkus.rest.client.alpn";
8080

81+
/**
82+
* If set to true, the stacktrace of the invocation of the REST Client method is captured
83+
*/
84+
public static final String CAPTURE_STACKTRACE = "io.quarkus.rest.client.capture-stacktrace";
85+
8186
}

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientCaptureCurrentContextRestHandler.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public class ClientCaptureCurrentContextRestHandler implements ClientRestHandler
1515

1616
private static final String RESTEASY_REACTIVE_PACKAGE = "org.jboss.resteasy.reactive";
1717
private static final String AUTOGENERATED_TAG = "$$";
18+
private static final StackTraceElement[] EMPTY_ARRAY = new StackTraceElement[0];
19+
private final boolean captureStacktrace;
20+
21+
public ClientCaptureCurrentContextRestHandler(boolean captureStacktrace) {
22+
this.captureStacktrace = captureStacktrace;
23+
}
1824

1925
@Override
2026
public void handle(RestClientRequestContext requestContext) throws Exception {
@@ -23,7 +29,9 @@ public void handle(RestClientRequestContext requestContext) throws Exception {
2329
return;
2430
}
2531

26-
captureCallerStackTrace(clientRequestContext);
32+
if (captureStacktrace) {
33+
captureCallerStackTrace(clientRequestContext);
34+
}
2735
}
2836

2937
private void captureCallerStackTrace(ClientRequestContextImpl clientRequestContext) {
@@ -44,6 +52,6 @@ private void captureCallerStackTrace(ClientRequestContextImpl clientRequestConte
4452
}
4553

4654
clientRequestContext.getRestClientRequestContext()
47-
.setCallerStackTrace(effectiveStackTrace.toArray(new StackTraceElement[0]));
55+
.setCallerStackTrace(effectiveStackTrace.toArray(EMPTY_ARRAY));
4856
}
4957
}

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jboss.resteasy.reactive.client.impl;
22

3+
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CAPTURE_STACKTRACE;
34
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECTION_POOL_SIZE;
45
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECTION_TTL;
56
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECT_TIMEOUT;
@@ -201,10 +202,19 @@ public Vertx get() {
201202
});
202203
}
203204

204-
handlerChain = new HandlerChain(options.getMaxChunkSize(), followRedirects, loggingScope,
205+
handlerChain = new HandlerChain(isCaptureStacktrace(configuration), options.getMaxChunkSize(), followRedirects,
206+
loggingScope,
205207
clientContext.getMultipartResponsesData(), clientLogger);
206208
}
207209

210+
private boolean isCaptureStacktrace(ConfigurationImpl configuration) {
211+
Object captureStacktraceObj = configuration.getProperty(CAPTURE_STACKTRACE);
212+
if (captureStacktraceObj == null) {
213+
return false;
214+
}
215+
return (boolean) captureStacktraceObj;
216+
}
217+
208218
public ClientContext getClientContext() {
209219
return clientContext;
210220
}

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/HandlerChain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class HandlerChain {
3636

3737
private ClientRestHandler preClientSendHandler = null;
3838

39-
public HandlerChain(int maxChunkSize, boolean followRedirects, LoggingScope loggingScope,
39+
public HandlerChain(boolean captureStacktrace, int maxChunkSize, boolean followRedirects, LoggingScope loggingScope,
4040
Map<Class<?>, MultipartResponseData> multipartData, ClientLogger clientLogger) {
41-
this.clientCaptureCurrentContextRestHandler = new ClientCaptureCurrentContextRestHandler();
41+
this.clientCaptureCurrentContextRestHandler = new ClientCaptureCurrentContextRestHandler(captureStacktrace);
4242
this.clientSwitchToRequestContextRestHandler = new ClientSwitchToRequestContextRestHandler();
4343
this.clientSendHandler = new ClientSendRequestHandler(maxChunkSize, followRedirects, loggingScope, clientLogger,
4444
multipartData);

independent-projects/resteasy-reactive/client/runtime/src/test/java/org/jboss/resteasy/reactive/client/impl/HandlerChainTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class HandlerChainTest {
2020
@Test
2121
public void preSendHandlerIsAlwaysFirst() throws Exception {
2222

23-
var chain = new HandlerChain(8096, true, LoggingScope.NONE, Collections.emptyMap(), new DefaultClientLogger());
23+
var chain = new HandlerChain(false, 8096, true, LoggingScope.NONE, Collections.emptyMap(), new DefaultClientLogger());
2424

2525
ClientRestHandler preHandler = ctx -> {
2626
};

0 commit comments

Comments
 (0)