Apm-agent-dotnet: ASP.NET Core request body capturing erases the body

Created on 26 Aug 2019  路  11Comments  路  Source: elastic/apm-agent-dotnet

Reported here by @brezaie.

Reproducer also included in the comment - copying here:

[HttpPost("send")]
public JsonResult Send([FromBody] BaseReportFilter<SendMessageFilter> filter)
{
    //Do something
    return new JsonResult("");
}


public class BaseReportFilter<T>
{
    public T ReportFilter { get; set; }
}

public class SendMessageFilter{
    public string SenderApplicationCode { get; set; }
    public string MediaType { get; set; }
    public string Body { get; set; }
    public List<string> Recipients { get; set; }
}

//appsettings.json:
"ElasticApm": {
    "ServerUrls": "http://localhost:8200",
    "ServiceName": "ServiceName",
    "CaptureHeaders": true,
    "CaptureBody": "all",
    "CaptureBodyContentTypes": "application/x-www-form-urlencoded*, text/*, application/json*, application/xml*",
    "LogLevel": "Info",
    "StackTraceLimit": -1
  }

"CaptureBodyContentTypes": "application/x-www-form-urlencoded*, text/*, application/json*, application/xml*",

Without agent the filter parameter is populated, once the agent is activated it became null.

bug from a real user

Most helpful comment

I'm running a version from my computer because this broken my production environment.
Yes... Yes.... I need to evaluate it first..... ^^

I'm very sorry about that! To be fair: this feature is off by default and you could immediately recover by turning the feature off, right? Or do I miss something? Not that I want to make this sound like a non-issue - it was indeed an important fix-, but I want to make sure I see the impact of this correctly.

The release is out: https://github.com/elastic/apm-agent-dotnet/releases/tag/1.1.2

Version 1.1.2 packages include the fix. Also updated on nuget.org.

All 11 comments

Here we have the test that covers this feature - the test case is a bit simpler, I don't see yet how it makes a difference, but as it seems it does make a difference.

This works fine if I comment out request.Body = initialBody in ExtractRequestBody method in RequestExtentions.cs. I hope this helps solve the problem.

Hi!

I am using the latest version and continues with this problem.

"ElasticApm": {
"ServerUrls": "#####",
"TransactionSampleRate": 1.0,
"CaptureBody": "all",
"CaptureBodyContentTypes": "application/x-www-form-urlencoded, text/, application/json, application/xml"
},

You are right!

All tests passed when comment this line.

I think is not necessary to do this and an accepted pull request.

https://devblogs.microsoft.com/aspnet/re-reading-asp-net-core-request-bodies-with-enablebuffering/

I need this ASAP so i'll pull a request, okay?

Thank you!

This works fine if I comment out request.Body = initialBody in ExtractRequestBody method in RequestExtentions.cs. I hope this helps solve the problem.

Thanks for the help everyone!

The PR from @iquirino (#539) seems ok to me, very much appreciated!

I also opened #542 - as mentioned our existing automated test did not discover this issue. I was unable to repro it with the way we tested previously. On the other hand hosting the sample app with WebHost reproduced the problem, so #542 also adds a test covering this scenario.

When it will be available on nugget?

When it will be available on nugget?

We don't have a fix date for the next release, so unfortunately I can't tell you a specific date.

I'm running a version from my computer because this broken my production environment.
Yes... Yes.... I need to evaluate it first..... ^^

I'm running a version from my computer because this broken my production environment.
Yes... Yes.... I need to evaluate it first..... ^^

I'm very sorry about that! To be fair: this feature is off by default and you could immediately recover by turning the feature off, right? Or do I miss something? Not that I want to make this sound like a non-issue - it was indeed an important fix-, but I want to make sure I see the impact of this correctly.

The release is out: https://github.com/elastic/apm-agent-dotnet/releases/tag/1.1.2

Version 1.1.2 packages include the fix. Also updated on nuget.org.

Uhull! You are awesome! Thank you Greg!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mterwoord picture mterwoord  路  7Comments

gregkalapos picture gregkalapos  路  5Comments

v1v picture v1v  路  3Comments

fernandolamp picture fernandolamp  路  7Comments

graphaelli picture graphaelli  路  8Comments