Elastic APM auto instrumentation not capturing DB and http calls in WCF service

APM Agent language and version : .NET Framework / 1.6.1

I've created a test project with a .NET WCF service (Framework 4.7.1), I can see the ElasticAPM agent auto creates spans for WCF calls but it did not included full trace for the DB call and other http call made withing the service.
I have included below three packages in the project and updated web.config as per instruction.
"Elastic.Apm" version="1.6.1"
"Elastic.Apm.AspNetFullFramework" version="1.6.1"
"Elastic.Apm.EntityFramework6" version="1.6.1"

I enabled the trace and found that the spans are not created, not sure if any additional code is required in WCF service as same setup is working fine in ASP.NET Web application project.

2020-08-31 12:08:09.517 -04:00 | TRACE | 49                             | {HttpDiagnosticListenerImplBase} Called with key: System.Net.Http.Desktop.HttpRequestOut.Start
2020-08-31 12:08:09.517 -04:00 | TRACE | 49                             | {HttpDiagnosticListenerImplBase} Processing start event... Request URL: https://stage.service.com/product/Product.svc
2020-08-31 12:08:09.531 -04:00 | DEBUG | 49                             | {HttpDiagnosticListenerImplBase} No current transaction, skip creating span for outgoing HTTP request
2020-08-31 12:08:09.763 -04:00 | TRACE | 49                             | {HttpDiagnosticListenerImplBase} Called with key: System.Net.Http.Desktop.HttpRequestOut.Stop
2020-08-31 12:08:09.763 -04:00 | TRACE | 49                             | {HttpDiagnosticListenerImplBase} Processing stop event... Request URL: https://stage.service.com/product/Product.svc
2020-08-31 12:08:09.763 -04:00 | DEBUG | 49                             | {HttpDiagnosticListenerImplBase} ProcessStopEvent called with no active current transaction, url: https://stage.service.com/product/Product.svc - skipping event
2020-08-31 12:08:09.772 -04:00 | DEBUG | 49                             | {Ef6Interceptor.Impl#67AC83} There no current transaction - skipping starting span for DB-operation-started event
2020-08-31 12:08:09.820 -04:00 | DEBUG | 49                             | {Ef6Interceptor.Impl#67AC83} Span is not found in DbCommandInterceptionContext's UserState - skipping ending the corresponding span for DB-operation-ended event
2020-08-31 12:08:09.820 -04:00 | DEBUG | 25                             | {ElasticApmModule.#1} Incoming request processing finished - ending trace...
2020-08-31 12:08:09.820 -04:00 | TRACE | 25                             | {Transaction} Ended Transaction{Id: c5ae2f7dd504e215, TraceId: 6a1b3fbdc7c3d47da03f8da7a31c1eae, ParentId: null, Name: POST /WcfApmPoc/Service.svc GetData, Type: request, IsSampled: True}. Start time: 2020-08-31 16:08:09.5231290 UTC (as timestamp: 1598890089523129), End time: 2020-08-31 16:08:09.8255670 UTC (as timestamp: 1598890089825567), Duration: 302.438ms

Hi @sanjay71

According to the logs there is no active transaction when the span for the outgoing HTTP call is created. This is a good doc on the span vs. transaction teminology.

Regarding the database call: I see you added the EFCore 6 pacakge, did you also enabled it as it's described here? Also, to be sure: does your app use EF6?

Hi @GregKalapos ,
Thanks for looking into the request, I found Agent.Tracer.CurrentTransaction is null inside IDispatchMessageInspector, hence it is failing to create transactions and spans, I think similar bug is tracked here https://github.com/elastic/apm-agent-dotnet/issues/934.

The same setup for auto instrumentation works fine in asp.net web application but not in WCF application. I was wondering if there is easy work around to address this issue.

Oh I see, yeah then the GitHub issue is very likely related.

I think the best workaround is to store Agent.Tracer.CurrentTransaction on the HttpContext and access it through that in the IDispatchMessageInspector similarly to the code from the issue description on GitHub.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.