Skip to content

Commit

Permalink
Update: As per #2006 Empty body being redacted is confusing (#2225)
Browse files Browse the repository at this point in the history
Co-authored-by: Martijn Laarman <[email protected]>
  • Loading branch information
redcinelli and Mpdreamz authored Jun 4, 2024
1 parent 879a339 commit 5542b34
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Elastic.Apm/Extensions/TransactionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ 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 t && t.IsContextCreated) || transaction.Context != null;
var hasContext = transaction is Transaction { IsContextCreated: true } || transaction.Context != null;
if (hasContext
&& transaction.Context.Request.Body != null
&& !ReferenceEquals(transaction.Context.Request.Body, Consts.Redacted))
return;

if (transaction.Configuration.CaptureBody.Equals(ConfigConsts.SupportedValues.CaptureBodyOff))
body = Consts.Redacted;

if (transaction.IsCaptureRequestBodyEnabled(isForError) && IsCaptureRequestBodyEnabledForContentType(transaction, httpRequest?.ContentType, logger))
body = httpRequest.ExtractBody(logger, transaction.Configuration);

// According to the documentation - the default value of 'body' is '[Redacted]'
transaction.Context.Request.Body = body ?? Consts.Redacted;
if (transaction.Context != null)
transaction.Context.Request.Body = body;
}

internal static bool IsCaptureRequestBodyEnabled(this ITransaction transaction, bool isForError) =>
Expand Down

0 comments on commit 5542b34

Please sign in to comment.