HttpClient calls from .NET Framework not always auto wrapped
See original GitHub issueDescribe the bug .NET Framework calls made using HttpClient are not automatically wrapped in a span within a ASP.NET Web API web app.
To Reproduce Steps to reproduce the behavior:
- Clone this repo
- Add a ASP.NET Web Application (.NET Framework) project to the sample folder (.NET 4.6.1). Select Web API template, uncheck configure for HTTPS.
- Add the following existing projects as references: Elastic.AP, Elastic.Apm.AspNetFullFramework
- Add to the
<system.webserver>
section in the Web.config:
<modules>
<add name="ElasticApmModule" type="Elastic.Apm.AspNetFullFramework.ElasticApmModule, Elastic.Apm.AspNetFullFramework"/>
</modules>
- Edit Web.config to have a ElasticApm:ServerUrls appSetting pointing at your instance of APM server.
- Edit ValuesController.Get() to contain:
// GET api/values
public IEnumerable<string> Get()
{
var client = new HttpClient();
var x = client.GetAsync("http://www.google.com").Result.Content.ReadAsStringAsync().Result;
return new [] { $"Length: {x.Length}" };
}
- Run service and send a request:
GET /api/values
Expected behavior When the /api/values transaction is logged to the APM server, it should contain a span from the HttpClient call to google. A transaction for /api/values is logged just fine, it just has no spans.
I have only seen this work out of the box with the AspNetFullFrameworkSampleApp and haven’t been able to get it to work in any of my existing .Net framework services by just adding the module reference in the web.configs (in addition to installing the nuget packages). There is so much extra going on in AspNetFullFrameworkSampleApp that it is hard for me to compare what might be causing the issue.
I have put breakpoints on various methods in HttpDiagnosticListenerImplBase like OnNext, ProcessStartEvent, etc, with none getting hit.
The following breakpoints are hit while testing:
- ElasticApmModule.InitOnceForAllInstancesUnderLock (line 312)
- HttpDiagnosticListener.New (line 23)
I’m guessing I’m missing something simple. Please advise.
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (7 by maintainers)
So you were right about version issues, but for me it was the
System.Diagnostics.DiagnosticSource
dll.If I added
System.Memory.dll
, added binding redirects into my web.config forSystem.memory
andSystem.Diagnostics.DiagnosticSource
, and then swapped out the version ofSystem.Diagnostics.DiagnosticSource
from AspNetFullFrameworkSampleApp to my test app after building, it works!I just need to figure out how to gracefully do that without my hackory.
It started working without adding
System.Memory
, it just threw exceptions complaining about it missing later on.@gregkalapos, I did fast check, and yes it seems
System.Diagnostics.DiagnosticSource
of4.0.0
version is enough fornetstandard2.0
for getting event fromHttpClient
.