Skip to content

Commit 6795daa

Browse files
authored
Added test case ensuring client body capturing is dynamic (#3831)
1 parent 1fda0dd commit 6795daa

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public final void setUpWiremock() {
8383
wireMockRule.stubFor(any(urlEqualTo("/"))
8484
.willReturn(dummyResponse()
8585
.withStatus(200)));
86+
wireMockRule.stubFor(any(urlEqualTo("/dummy"))
87+
.willReturn(dummyResponse()
88+
.withStatus(200)));
8689
wireMockRule.stubFor(get(urlEqualTo("/error"))
8790
.willReturn(dummyResponse()
8891
.withStatus(515)));
@@ -125,11 +128,19 @@ public void testPostBodyCapture() throws Exception {
125128
if (!isBodyCapturingSupported()) {
126129
return;
127130
}
128-
doReturn(5).when(config.getConfig(WebConfiguration.class)).getCaptureClientRequestBytes();
129131
byte[] content = "Hello World!".getBytes(StandardCharsets.UTF_8);
130-
String path = "/";
131-
performPost(getBaseUrl() + path, content, "text/plain; charset=utf-8");
132-
expectSpan(path)
132+
133+
// Ensure that the setting can be turned on dynamically by first issuing a request with the feature disabled
134+
doReturn(0).when(config.getConfig(WebConfiguration.class)).getCaptureClientRequestBytes();
135+
performPost(getBaseUrl() + "/dummy", content, "text/plain; charset=utf-8");
136+
expectSpan("/dummy")
137+
.withRequestBodySatisfying(body -> assertThat(body.getBody()).isNull())
138+
.verify();
139+
reporter.reset();
140+
141+
doReturn(5).when(config.getConfig(WebConfiguration.class)).getCaptureClientRequestBytes();
142+
performPost(getBaseUrl() + "/", content, "text/plain; charset=utf-8");
143+
expectSpan("/")
133144
.withRequestBodySatisfying(body -> {
134145
ByteBuffer buffer = body.getBody();
135146
assertThat(buffer).isNotNull();

apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/BodyCaptureRegistry.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
119
package co.elastic.apm.agent.springwebclient;
220

321
import co.elastic.apm.agent.httpclient.RequestBodyRecordingHelper;

apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/ClientRequestHeaderGetter.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
119
package co.elastic.apm.agent.springwebclient;
220

321
import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter;

0 commit comments

Comments
 (0)