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

**URL:** <https://discuss.elastic.co/t/elastic-apm-auto-instrumentation-not-capturing-db-and-http-calls-in-wcf-service/247018>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [August 31, 2020, 9:23pm UTC](https://discuss.elastic.co/t/elastic-apm-auto-instrumentation-not-capturing-db-and-http-calls-in-wcf-service/247018 "2020-08-31T21:23:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjay71](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@sanjay71](https://discuss.elastic.co/u/sanjay71)\
**Post date:** [August 31, 2020, 9:23pm UTC](https://discuss.elastic.co/t/elastic-apm-auto-instrumentation-not-capturing-db-and-http-calls-in-wcf-service/247018/1 "2020-08-31T21:23:18Z")

</div>

**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](http://ASP.NET) Web application project.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [September 4, 2020, 6:41pm UTC](https://discuss.elastic.co/t/elastic-apm-auto-instrumentation-not-capturing-db-and-http-calls-in-wcf-service/247018/2 "2020-09-04T18:41:26Z")

</div>

Hi @sanjay71

According to the logs there is no active transaction when the span for the outgoing HTTP call is created. [This](https://www.elastic.co/guide/en/apm/get-started/current/distributed-tracing.html) 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](https://www.elastic.co/guide/en/apm/agent/dotnet/current/setup.html#setup-ef6)? Also, to be sure: does your app use EF6?

---

<div class="post-metadata">

**Author:** ![sanjay71](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@sanjay71](https://discuss.elastic.co/u/sanjay71)\
**Post date:** [September 4, 2020, 7:08pm UTC](https://discuss.elastic.co/t/elastic-apm-auto-instrumentation-not-capturing-db-and-http-calls-in-wcf-service/247018/3 "2020-09-04T19:08:15Z")

</div>

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](https://github.com/elastic/apm-agent-dotnet/issues/934).

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

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [September 4, 2020, 8:00pm UTC](https://discuss.elastic.co/t/elastic-apm-auto-instrumentation-not-capturing-db-and-http-calls-in-wcf-service/247018/4 "2020-09-04T20:00:35Z")

</div>

Oh I see, yeah then the [GitHub issue](https://github.com/elastic/apm-agent-dotnet/issues/934) 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 25, 2020, 4:00pm UTC](https://discuss.elastic.co/t/elastic-apm-auto-instrumentation-not-capturing-db-and-http-calls-in-wcf-service/247018/5 "2020-09-25T16:00:36Z")

</div>

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