Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test case ensuring client body capturing is dynamic #3831

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public final void setUpWiremock() {
wireMockRule.stubFor(any(urlEqualTo("/"))
.willReturn(dummyResponse()
.withStatus(200)));
wireMockRule.stubFor(any(urlEqualTo("/dummy"))
.willReturn(dummyResponse()
.withStatus(200)));
wireMockRule.stubFor(get(urlEqualTo("/error"))
.willReturn(dummyResponse()
.withStatus(515)));
Expand Down Expand Up @@ -125,11 +128,19 @@ public void testPostBodyCapture() throws Exception {
if (!isBodyCapturingSupported()) {
return;
}
doReturn(5).when(config.getConfig(WebConfiguration.class)).getCaptureClientRequestBytes();
byte[] content = "Hello World!".getBytes(StandardCharsets.UTF_8);
String path = "/";
performPost(getBaseUrl() + path, content, "text/plain; charset=utf-8");
expectSpan(path)

// Ensure that the setting can be turned on dynamically by first issuing a request with the feature disabled
doReturn(0).when(config.getConfig(WebConfiguration.class)).getCaptureClientRequestBytes();
performPost(getBaseUrl() + "/dummy", content, "text/plain; charset=utf-8");
expectSpan("/dummy")
.withRequestBodySatisfying(body -> assertThat(body.getBody()).isNull())
.verify();
reporter.reset();

doReturn(5).when(config.getConfig(WebConfiguration.class)).getCaptureClientRequestBytes();
performPost(getBaseUrl() + "/", content, "text/plain; charset=utf-8");
expectSpan("/")
.withRequestBodySatisfying(body -> {
ByteBuffer buffer = body.getBody();
assertThat(buffer).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.springwebclient;

import co.elastic.apm.agent.httpclient.RequestBodyRecordingHelper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.springwebclient;

import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter;
Expand Down
Loading