question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ASP.NET Core request body capturing erases the body

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
gregkalaposcommented, Oct 11, 2019

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.

2reactions
minbyulcatcommented, Sep 27, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I get the incoming request body and the outgoing ...
I'm writing some middleware for an ASP.NET Core 7 minimal API project. At this stage, I would just like to be able to...
Read more >
Use HttpContext in ASP.NET Core
Reads the request body. Rewinds the request body to the start so other middleware or the endpoint can read it. C# Copy.
Read more >
Logging the Body of HTTP Request and Response in ASP . ...
Logging the Body of HTTP Request and Response in ASP .NET Core · In this first post, we will explore how to capture...
Read more >
ASP.NET Core Web API - POST PUT DELETE
This part is focused on handling POST PUT DELETE requests in .NET Core by using previously created repository pattern for business logic.
Read more >
Reading the raw request body as a string in ASP.NET Core
ASP.NET MVC model binding is great, but occasionally you just need to access the body of a request as a raw string within...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found