From 8e1a70dba5fcc159cb4e0dda1c2d35b663b2b862 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Wed, 9 Jul 2025 12:23:39 +0300 Subject: [PATCH 1/7] The CaptureBody is not working as intended, not at all Fix the CaptureBody in AspNetCore. Related to the issue #2029 --- .../Extensions/TransactionExtensions.cs | 20 +++++++++++-- .../AspNetCoreHttpRequest.cs | 30 ++++++++++++++++++- .../WebRequestTransactionCreator.cs | 2 +- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Elastic.Apm/Extensions/TransactionExtensions.cs b/src/Elastic.Apm/Extensions/TransactionExtensions.cs index ef2127eba..765f27b2f 100644 --- a/src/Elastic.Apm/Extensions/TransactionExtensions.cs +++ b/src/Elastic.Apm/Extensions/TransactionExtensions.cs @@ -34,10 +34,26 @@ internal static void CollectRequestBody(this ITransaction transaction, bool isFo // Is request body already captured? // We check transaction.IsContextCreated to avoid creating empty Context (that accessing transaction.Context directly would have done). var hasContext = transaction is Transaction { IsContextCreated: true } || transaction.Context != null; - if (hasContext - && transaction.Context.Request.Body != null + var hasCapturedBody = hasContext && transaction.Context.Request != null && transaction.Context.Request.Body != null; + + // If CaptureBody is set to "transactions" and it is an error then we shouldn't capture it. + // If the body has already been captured then it has to be redacted. + if(isForError + && transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyTransactions)) + { + if (hasCapturedBody) + { + transaction.Context.Request.Body = Consts.Redacted; + } + + return; + } + + if (hasCapturedBody && !ReferenceEquals(transaction.Context.Request.Body, Consts.Redacted)) + { return; + } if (transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyOff)) body = Consts.Redacted; diff --git a/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs b/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs index 2a4b19d26..34152243e 100644 --- a/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs +++ b/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs @@ -14,12 +14,40 @@ internal class AspNetCoreHttpRequest : IHttpRequestAdapter { private readonly HttpRequest _request; + internal AspNetCoreHttpRequest(HttpRequest request, IConfiguration configuration) + { + _request = request; + if (configuration != null && configuration.CaptureBody == ConfigConsts.SupportedValues.CaptureBodyErrors) + { + _request?.EnableBuffering(); + } + } + internal AspNetCoreHttpRequest(HttpRequest request) => _request = request; public string ExtractBody(IConfiguration configuration, IApmLogger logger, out bool longerThanMaxLength) { longerThanMaxLength = false; - return _request?.ExtractRequestBody(configuration, out longerThanMaxLength); + + var shouldBeBuffered = configuration?.CaptureBody == ConfigConsts.SupportedValues.CaptureBodyErrors; + + // Enable buffering if CaptureBody is set to "errors" + if (shouldBeBuffered) + { + _request?.EnableBuffering(); + // Reset stream position to the beginning in case the body was already read + _request.Body.Position = 0; + } + + var bodyContent = _request?.ExtractRequestBody(configuration, out longerThanMaxLength); + + // Reset stream position if buffering was enabled + if (shouldBeBuffered) + { + _request.Body.Position = 0; + } + + return bodyContent; } public bool HasValue => _request != null; diff --git a/src/integrations/Elastic.Apm.AspNetCore/WebRequestTransactionCreator.cs b/src/integrations/Elastic.Apm.AspNetCore/WebRequestTransactionCreator.cs index 36adeeba1..bcd7f18ba 100644 --- a/src/integrations/Elastic.Apm.AspNetCore/WebRequestTransactionCreator.cs +++ b/src/integrations/Elastic.Apm.AspNetCore/WebRequestTransactionCreator.cs @@ -122,7 +122,7 @@ private static void FillSampledTransactionContextRequest(HttpContext context, Tr Headers = GetHeaders(context.Request.Headers, transaction.Configuration) }; - transaction.CollectRequestBody(false, new AspNetCoreHttpRequest(context.Request), logger); + transaction.CollectRequestBody(false, new AspNetCoreHttpRequest(context.Request, transaction.Configuration), logger); } catch (Exception ex) { From 11687b12e01662294316862b14b19c3acb745d34 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Wed, 9 Jul 2025 13:02:43 +0300 Subject: [PATCH 2/7] Format --- src/Elastic.Apm/Extensions/TransactionExtensions.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Elastic.Apm/Extensions/TransactionExtensions.cs b/src/Elastic.Apm/Extensions/TransactionExtensions.cs index 765f27b2f..69cf7fce7 100644 --- a/src/Elastic.Apm/Extensions/TransactionExtensions.cs +++ b/src/Elastic.Apm/Extensions/TransactionExtensions.cs @@ -24,7 +24,9 @@ internal static class TransactionExtensions internal static void CollectRequestBody(this ITransaction transaction, bool isForError, IHttpRequestAdapter httpRequest, IApmLogger logger) { if (!transaction.IsSampled) + { return; + } if (httpRequest == null || !httpRequest.HasValue) return; @@ -38,22 +40,16 @@ internal static void CollectRequestBody(this ITransaction transaction, bool isFo // If CaptureBody is set to "transactions" and it is an error then we shouldn't capture it. // If the body has already been captured then it has to be redacted. - if(isForError - && transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyTransactions)) + if (isForError && transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyTransactions)) { if (hasCapturedBody) - { transaction.Context.Request.Body = Consts.Redacted; - } return; } - if (hasCapturedBody - && !ReferenceEquals(transaction.Context.Request.Body, Consts.Redacted)) - { + if (hasCapturedBody && !ReferenceEquals(transaction.Context.Request.Body, Consts.Redacted)) return; - } if (transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyOff)) body = Consts.Redacted; From 5ec7ea4421a627e94fada734275c5d2eb85c0643 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Wed, 9 Jul 2025 12:23:39 +0300 Subject: [PATCH 3/7] The CaptureBody is not working as intended, not at all Fix the CaptureBody in AspNetCore. Related to the issue #2029 --- .../Extensions/TransactionExtensions.cs | 20 +++++++++++-- .../AspNetCoreHttpRequest.cs | 30 ++++++++++++++++++- .../WebRequestTransactionCreator.cs | 2 +- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Elastic.Apm/Extensions/TransactionExtensions.cs b/src/Elastic.Apm/Extensions/TransactionExtensions.cs index ef2127eba..765f27b2f 100644 --- a/src/Elastic.Apm/Extensions/TransactionExtensions.cs +++ b/src/Elastic.Apm/Extensions/TransactionExtensions.cs @@ -34,10 +34,26 @@ internal static void CollectRequestBody(this ITransaction transaction, bool isFo // Is request body already captured? // We check transaction.IsContextCreated to avoid creating empty Context (that accessing transaction.Context directly would have done). var hasContext = transaction is Transaction { IsContextCreated: true } || transaction.Context != null; - if (hasContext - && transaction.Context.Request.Body != null + var hasCapturedBody = hasContext && transaction.Context.Request != null && transaction.Context.Request.Body != null; + + // If CaptureBody is set to "transactions" and it is an error then we shouldn't capture it. + // If the body has already been captured then it has to be redacted. + if(isForError + && transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyTransactions)) + { + if (hasCapturedBody) + { + transaction.Context.Request.Body = Consts.Redacted; + } + + return; + } + + if (hasCapturedBody && !ReferenceEquals(transaction.Context.Request.Body, Consts.Redacted)) + { return; + } if (transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyOff)) body = Consts.Redacted; diff --git a/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs b/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs index 2a4b19d26..34152243e 100644 --- a/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs +++ b/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs @@ -14,12 +14,40 @@ internal class AspNetCoreHttpRequest : IHttpRequestAdapter { private readonly HttpRequest _request; + internal AspNetCoreHttpRequest(HttpRequest request, IConfiguration configuration) + { + _request = request; + if (configuration != null && configuration.CaptureBody == ConfigConsts.SupportedValues.CaptureBodyErrors) + { + _request?.EnableBuffering(); + } + } + internal AspNetCoreHttpRequest(HttpRequest request) => _request = request; public string ExtractBody(IConfiguration configuration, IApmLogger logger, out bool longerThanMaxLength) { longerThanMaxLength = false; - return _request?.ExtractRequestBody(configuration, out longerThanMaxLength); + + var shouldBeBuffered = configuration?.CaptureBody == ConfigConsts.SupportedValues.CaptureBodyErrors; + + // Enable buffering if CaptureBody is set to "errors" + if (shouldBeBuffered) + { + _request?.EnableBuffering(); + // Reset stream position to the beginning in case the body was already read + _request.Body.Position = 0; + } + + var bodyContent = _request?.ExtractRequestBody(configuration, out longerThanMaxLength); + + // Reset stream position if buffering was enabled + if (shouldBeBuffered) + { + _request.Body.Position = 0; + } + + return bodyContent; } public bool HasValue => _request != null; diff --git a/src/integrations/Elastic.Apm.AspNetCore/WebRequestTransactionCreator.cs b/src/integrations/Elastic.Apm.AspNetCore/WebRequestTransactionCreator.cs index 36adeeba1..bcd7f18ba 100644 --- a/src/integrations/Elastic.Apm.AspNetCore/WebRequestTransactionCreator.cs +++ b/src/integrations/Elastic.Apm.AspNetCore/WebRequestTransactionCreator.cs @@ -122,7 +122,7 @@ private static void FillSampledTransactionContextRequest(HttpContext context, Tr Headers = GetHeaders(context.Request.Headers, transaction.Configuration) }; - transaction.CollectRequestBody(false, new AspNetCoreHttpRequest(context.Request), logger); + transaction.CollectRequestBody(false, new AspNetCoreHttpRequest(context.Request, transaction.Configuration), logger); } catch (Exception ex) { From a1f2f44c1ade496e994ad8a7d8a91638dec7d2a2 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Wed, 9 Jul 2025 13:02:43 +0300 Subject: [PATCH 4/7] Format --- src/Elastic.Apm/Extensions/TransactionExtensions.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Elastic.Apm/Extensions/TransactionExtensions.cs b/src/Elastic.Apm/Extensions/TransactionExtensions.cs index 765f27b2f..69cf7fce7 100644 --- a/src/Elastic.Apm/Extensions/TransactionExtensions.cs +++ b/src/Elastic.Apm/Extensions/TransactionExtensions.cs @@ -24,7 +24,9 @@ internal static class TransactionExtensions internal static void CollectRequestBody(this ITransaction transaction, bool isForError, IHttpRequestAdapter httpRequest, IApmLogger logger) { if (!transaction.IsSampled) + { return; + } if (httpRequest == null || !httpRequest.HasValue) return; @@ -38,22 +40,16 @@ internal static void CollectRequestBody(this ITransaction transaction, bool isFo // If CaptureBody is set to "transactions" and it is an error then we shouldn't capture it. // If the body has already been captured then it has to be redacted. - if(isForError - && transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyTransactions)) + if (isForError && transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyTransactions)) { if (hasCapturedBody) - { transaction.Context.Request.Body = Consts.Redacted; - } return; } - if (hasCapturedBody - && !ReferenceEquals(transaction.Context.Request.Body, Consts.Redacted)) - { + if (hasCapturedBody && !ReferenceEquals(transaction.Context.Request.Body, Consts.Redacted)) return; - } if (transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyOff)) body = Consts.Redacted; From ed6a5e4dc3b0c64c300ac01b1bc0a433a876a6d4 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Wed, 13 Aug 2025 14:05:02 +0300 Subject: [PATCH 5/7] Fix comments Add integration tests --- .../Extensions/TransactionExtensions.cs | 2 +- .../AspNetCoreHttpRequest.cs | 6 +- .../AspNetCoreDiagnosticListener.cs | 2 +- .../BodyCapturingTests.cs | 201 ++++++++++++++++++ .../Controllers/HomeController.cs | 7 + 5 files changed, 212 insertions(+), 6 deletions(-) diff --git a/src/Elastic.Apm/Extensions/TransactionExtensions.cs b/src/Elastic.Apm/Extensions/TransactionExtensions.cs index 69cf7fce7..36aee9c0e 100644 --- a/src/Elastic.Apm/Extensions/TransactionExtensions.cs +++ b/src/Elastic.Apm/Extensions/TransactionExtensions.cs @@ -36,7 +36,7 @@ internal static void CollectRequestBody(this ITransaction transaction, bool isFo // Is request body already captured? // We check transaction.IsContextCreated to avoid creating empty Context (that accessing transaction.Context directly would have done). var hasContext = transaction is Transaction { IsContextCreated: true } || transaction.Context != null; - var hasCapturedBody = hasContext && transaction.Context.Request != null && transaction.Context.Request.Body != null; + var hasCapturedBody = hasContext && transaction.Context.Request?.Body != null; // If CaptureBody is set to "transactions" and it is an error then we shouldn't capture it. // If the body has already been captured then it has to be redacted. diff --git a/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs b/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs index 34152243e..6c9b62ad1 100644 --- a/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs +++ b/src/integrations/Elastic.Apm.AspNetCore/AspNetCoreHttpRequest.cs @@ -17,14 +17,13 @@ internal class AspNetCoreHttpRequest : IHttpRequestAdapter internal AspNetCoreHttpRequest(HttpRequest request, IConfiguration configuration) { _request = request; - if (configuration != null && configuration.CaptureBody == ConfigConsts.SupportedValues.CaptureBodyErrors) + + if (configuration?.CaptureBody == ConfigConsts.SupportedValues.CaptureBodyErrors) { _request?.EnableBuffering(); } } - internal AspNetCoreHttpRequest(HttpRequest request) => _request = request; - public string ExtractBody(IConfiguration configuration, IApmLogger logger, out bool longerThanMaxLength) { longerThanMaxLength = false; @@ -34,7 +33,6 @@ public string ExtractBody(IConfiguration configuration, IApmLogger logger, out b // Enable buffering if CaptureBody is set to "errors" if (shouldBeBuffered) { - _request?.EnableBuffering(); // Reset stream position to the beginning in case the body was already read _request.Body.Position = 0; } diff --git a/src/integrations/Elastic.Apm.AspNetCore/DiagnosticListener/AspNetCoreDiagnosticListener.cs b/src/integrations/Elastic.Apm.AspNetCore/DiagnosticListener/AspNetCoreDiagnosticListener.cs index e382a82d4..597121a15 100644 --- a/src/integrations/Elastic.Apm.AspNetCore/DiagnosticListener/AspNetCoreDiagnosticListener.cs +++ b/src/integrations/Elastic.Apm.AspNetCore/DiagnosticListener/AspNetCoreDiagnosticListener.cs @@ -96,7 +96,7 @@ private bool HandleException(PropertyFetcher propertyFetcher, PropertyFetcher ex return false; if (iTransaction is Transaction transaction) { - transaction.CollectRequestBody(true, new AspNetCoreHttpRequest(exception.Request), Logger); + transaction.CollectRequestBody(true, new AspNetCoreHttpRequest(exception.Request, transaction.Configuration), Logger); transaction.CaptureException(httpContextException, isHandled: isHandled); } diff --git a/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs b/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs index 34bee5535..5fb34b5bc 100644 --- a/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs +++ b/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs @@ -65,6 +65,207 @@ public BodyCapturingTests(ITestOutputHelper output) private MockConfiguration CreateConfiguration(string captureBody = CaptureBodyAll) => new(_logger, captureBody: captureBody, openTelemetryBridgeEnabled: "false"); + + [Fact] + public async Task When_CaptureBodyConfigurationToAllAndSuccessfulCall_Should_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("all")); + + // build test data, which we send to the sample app + var data = new { Name = "John"}; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(10)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)200); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToTransactionsAndSuccessfulCall_Should_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("transactions")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)200); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToOffAndSuccessfulCall_ShouldNot_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("off")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)200); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToErrorsAndSuccessfulCall_ShouldNot_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("errors")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)200); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().BeNull(); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToAllAndFailingCall_Should_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("all")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)500); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToErrorsAndFailingCall_Should_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("errors")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)500); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToTransactionsAndFailingCall_ShouldNot_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("transactions")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)500); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToOffAndFailingCall_ShouldNot_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("off")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)500); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); + } + /// /// Calls . /// That method returns HTTP 500 in case the request body is null in the method, otherwise HTTP 200. diff --git a/test/integrations/applications/SampleAspNetCoreApp/Controllers/HomeController.cs b/test/integrations/applications/SampleAspNetCoreApp/Controllers/HomeController.cs index 8b19dbf04..75374a478 100644 --- a/test/integrations/applications/SampleAspNetCoreApp/Controllers/HomeController.cs +++ b/test/integrations/applications/SampleAspNetCoreApp/Controllers/HomeController.cs @@ -284,6 +284,13 @@ private async Task T3() [HttpPost("api/Home/Send")] public IActionResult Send([FromBody] BaseReportFilter filter) => filter == null ? StatusCode(500) : Ok(); + /// + /// A test case to make sure that CaptureBoby is working as expected in case of failure. + /// + /// HTTP500 + [HttpPost("api/Home/SendError")] + public IActionResult SendError([FromBody] BaseReportFilter filter) => throw new Exception("This is a post method test exception!"); + /// /// A test case to make sure that setting manually is not overwritten by auto instrumentation. /// From 51e6245dc60131391e7bd31eaa7417bcdf78dd2b Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Wed, 13 Aug 2025 15:18:09 +0300 Subject: [PATCH 6/7] Fix format --- .../BodyCapturingTests.cs | 402 +++++++++--------- 1 file changed, 200 insertions(+), 202 deletions(-) diff --git a/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs b/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs index 5fb34b5bc..1fa651ca9 100644 --- a/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs +++ b/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Net; @@ -65,207 +64,6 @@ public BodyCapturingTests(ITestOutputHelper output) private MockConfiguration CreateConfiguration(string captureBody = CaptureBodyAll) => new(_logger, captureBody: captureBody, openTelemetryBridgeEnabled: "false"); - - [Fact] - public async Task When_CaptureBodyConfigurationToAllAndSuccessfulCall_Should_CaptureBody() - { - var sutEnv = StartSutEnv(CreateConfiguration("all")); - - // build test data, which we send to the sample app - var data = new { Name = "John"}; - - var body = JsonConvert.SerializeObject(data, - new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - - // send data to the sample app - var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); - - // wait for the payload sender to receive the transaction - sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(10)); - - // make sure the sample app received the data - result.StatusCode.Should().Be((HttpStatusCode)200); - - // and make sure the data is captured by the agent - sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); - sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); - } - - [Fact] - public async Task When_CaptureBodyConfigurationToTransactionsAndSuccessfulCall_Should_CaptureBody() - { - var sutEnv = StartSutEnv(CreateConfiguration("transactions")); - - // build test data, which we send to the sample app - var data = new { Name = "John" }; - - var body = JsonConvert.SerializeObject(data, - new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - - // send data to the sample app - var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); - - // wait for the payload sender to receive the transaction - sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); - - // make sure the sample app received the data - result.StatusCode.Should().Be((HttpStatusCode)200); - - // and make sure the data is captured by the agent - sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); - sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); - } - - [Fact] - public async Task When_CaptureBodyConfigurationToOffAndSuccessfulCall_ShouldNot_CaptureBody() - { - var sutEnv = StartSutEnv(CreateConfiguration("off")); - - // build test data, which we send to the sample app - var data = new { Name = "John" }; - - var body = JsonConvert.SerializeObject(data, - new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - - // send data to the sample app - var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); - - // wait for the payload sender to receive the transaction - sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); - - // make sure the sample app received the data - result.StatusCode.Should().Be((HttpStatusCode)200); - - // and make sure the data is captured by the agent - sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); - sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); - } - - [Fact] - public async Task When_CaptureBodyConfigurationToErrorsAndSuccessfulCall_ShouldNot_CaptureBody() - { - var sutEnv = StartSutEnv(CreateConfiguration("errors")); - - // build test data, which we send to the sample app - var data = new { Name = "John" }; - - var body = JsonConvert.SerializeObject(data, - new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - - // send data to the sample app - var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); - - // wait for the payload sender to receive the transaction - sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); - - // make sure the sample app received the data - result.StatusCode.Should().Be((HttpStatusCode)200); - - // and make sure the data is captured by the agent - sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); - sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().BeNull(); - } - - [Fact] - public async Task When_CaptureBodyConfigurationToAllAndFailingCall_Should_CaptureBody() - { - var sutEnv = StartSutEnv(CreateConfiguration("all")); - - // build test data, which we send to the sample app - var data = new { Name = "John" }; - - var body = JsonConvert.SerializeObject(data, - new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - - // send data to the sample app - var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); - - // wait for the payload sender to receive the transaction - sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); - - // make sure the sample app received the data - result.StatusCode.Should().Be((HttpStatusCode)500); - - // and make sure the data is captured by the agent - sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); - sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); - } - - [Fact] - public async Task When_CaptureBodyConfigurationToErrorsAndFailingCall_Should_CaptureBody() - { - var sutEnv = StartSutEnv(CreateConfiguration("errors")); - - // build test data, which we send to the sample app - var data = new { Name = "John" }; - - var body = JsonConvert.SerializeObject(data, - new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - - // send data to the sample app - var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); - - // wait for the payload sender to receive the transaction - sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); - - // make sure the sample app received the data - result.StatusCode.Should().Be((HttpStatusCode)500); - - // and make sure the data is captured by the agent - sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); - sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); - } - - [Fact] - public async Task When_CaptureBodyConfigurationToTransactionsAndFailingCall_ShouldNot_CaptureBody() - { - var sutEnv = StartSutEnv(CreateConfiguration("transactions")); - - // build test data, which we send to the sample app - var data = new { Name = "John" }; - - var body = JsonConvert.SerializeObject(data, - new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - - // send data to the sample app - var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); - - // wait for the payload sender to receive the transaction - sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); - - // make sure the sample app received the data - result.StatusCode.Should().Be((HttpStatusCode)500); - - // and make sure the data is captured by the agent - sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); - sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); - } - - [Fact] - public async Task When_CaptureBodyConfigurationToOffAndFailingCall_ShouldNot_CaptureBody() - { - var sutEnv = StartSutEnv(CreateConfiguration("off")); - - // build test data, which we send to the sample app - var data = new { Name = "John" }; - - var body = JsonConvert.SerializeObject(data, - new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - - // send data to the sample app - var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); - - // wait for the payload sender to receive the transaction - sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); - - // make sure the sample app received the data - result.StatusCode.Should().Be((HttpStatusCode)500); - - // and make sure the data is captured by the agent - sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); - sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); - } - /// /// Calls . /// That method returns HTTP 500 in case the request body is null in the method, otherwise HTTP 200. @@ -486,6 +284,206 @@ public async Task ApmMiddleware_ShouldSkipCapturing_WhenInvalidContentType() result.StatusCode.Should().Be(HttpStatusCode.UnsupportedMediaType); } + [Fact] + public async Task When_CaptureBodyConfigurationToAllAndSuccessfulCall_Should_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("all")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(10)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)200); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToTransactionsAndSuccessfulCall_Should_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("transactions")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)200); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToOffAndSuccessfulCall_ShouldNot_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("off")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)200); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToErrorsAndSuccessfulCall_ShouldNot_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("errors")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)200); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().BeNull(); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToAllAndFailingCall_Should_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("all")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)500); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToErrorsAndFailingCall_Should_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("errors")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)500); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToTransactionsAndFailingCall_ShouldNot_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("transactions")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)500); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); + } + + [Fact] + public async Task When_CaptureBodyConfigurationToOffAndFailingCall_ShouldNot_CaptureBody() + { + var sutEnv = StartSutEnv(CreateConfiguration("off")); + + // build test data, which we send to the sample app + var data = new { Name = "John" }; + + var body = JsonConvert.SerializeObject(data, + new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + + // send data to the sample app + var result = await sutEnv.HttpClient.PostAsync("api/Home/SendError", new StringContent(body, Encoding.UTF8, "application/json")); + + // wait for the payload sender to receive the transaction + sutEnv.MockPayloadSender.WaitForTransactions(TimeSpan.FromSeconds(3)); + + // make sure the sample app received the data + result.StatusCode.Should().Be((HttpStatusCode)500); + + // and make sure the data is captured by the agent + sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); + sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be("[REDACTED]"); + } + private static IEnumerable BuildOptionsTestVariants() { var captureBodyContentTypesVariants = new[] From 089adb497ca7d7689853b3a044564626fba150ac Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Mon, 18 Aug 2025 12:12:46 +0300 Subject: [PATCH 7/7] Improve code --- .../BodyCapturingTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs b/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs index 1fa651ca9..cf126d4f2 100644 --- a/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs +++ b/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs @@ -287,7 +287,7 @@ public async Task ApmMiddleware_ShouldSkipCapturing_WhenInvalidContentType() [Fact] public async Task When_CaptureBodyConfigurationToAllAndSuccessfulCall_Should_CaptureBody() { - var sutEnv = StartSutEnv(CreateConfiguration("all")); + var sutEnv = StartSutEnv(CreateConfiguration()); // build test data, which we send to the sample app var data = new { Name = "John" }; @@ -312,7 +312,7 @@ public async Task When_CaptureBodyConfigurationToAllAndSuccessfulCall_Should_Cap [Fact] public async Task When_CaptureBodyConfigurationToTransactionsAndSuccessfulCall_Should_CaptureBody() { - var sutEnv = StartSutEnv(CreateConfiguration("transactions")); + var sutEnv = StartSutEnv(CreateConfiguration(ConfigConsts.SupportedValues.CaptureBodyTransactions)); // build test data, which we send to the sample app var data = new { Name = "John" }; @@ -337,7 +337,7 @@ public async Task When_CaptureBodyConfigurationToTransactionsAndSuccessfulCall_S [Fact] public async Task When_CaptureBodyConfigurationToOffAndSuccessfulCall_ShouldNot_CaptureBody() { - var sutEnv = StartSutEnv(CreateConfiguration("off")); + var sutEnv = StartSutEnv(CreateConfiguration(ConfigConsts.SupportedValues.CaptureBodyOff)); // build test data, which we send to the sample app var data = new { Name = "John" }; @@ -362,7 +362,7 @@ public async Task When_CaptureBodyConfigurationToOffAndSuccessfulCall_ShouldNot_ [Fact] public async Task When_CaptureBodyConfigurationToErrorsAndSuccessfulCall_ShouldNot_CaptureBody() { - var sutEnv = StartSutEnv(CreateConfiguration("errors")); + var sutEnv = StartSutEnv(CreateConfiguration(ConfigConsts.SupportedValues.CaptureBodyErrors)); // build test data, which we send to the sample app var data = new { Name = "John" }; @@ -387,7 +387,7 @@ public async Task When_CaptureBodyConfigurationToErrorsAndSuccessfulCall_ShouldN [Fact] public async Task When_CaptureBodyConfigurationToAllAndFailingCall_Should_CaptureBody() { - var sutEnv = StartSutEnv(CreateConfiguration("all")); + var sutEnv = StartSutEnv(CreateConfiguration()); // build test data, which we send to the sample app var data = new { Name = "John" }; @@ -412,7 +412,7 @@ public async Task When_CaptureBodyConfigurationToAllAndFailingCall_Should_Captur [Fact] public async Task When_CaptureBodyConfigurationToErrorsAndFailingCall_Should_CaptureBody() { - var sutEnv = StartSutEnv(CreateConfiguration("errors")); + var sutEnv = StartSutEnv(CreateConfiguration(ConfigConsts.SupportedValues.CaptureBodyErrors)); // build test data, which we send to the sample app var data = new { Name = "John" }; @@ -437,7 +437,7 @@ public async Task When_CaptureBodyConfigurationToErrorsAndFailingCall_Should_Cap [Fact] public async Task When_CaptureBodyConfigurationToTransactionsAndFailingCall_ShouldNot_CaptureBody() { - var sutEnv = StartSutEnv(CreateConfiguration("transactions")); + var sutEnv = StartSutEnv(CreateConfiguration(ConfigConsts.SupportedValues.CaptureBodyTransactions)); // build test data, which we send to the sample app var data = new { Name = "John" }; @@ -462,7 +462,7 @@ public async Task When_CaptureBodyConfigurationToTransactionsAndFailingCall_Shou [Fact] public async Task When_CaptureBodyConfigurationToOffAndFailingCall_ShouldNot_CaptureBody() { - var sutEnv = StartSutEnv(CreateConfiguration("off")); + var sutEnv = StartSutEnv(CreateConfiguration(ConfigConsts.SupportedValues.CaptureBodyOff)); // build test data, which we send to the sample app var data = new { Name = "John" };