# ASP .NET 6.0 Agent seems to fail instantiation occasionally. No errors in logs

**URL:** <https://discuss.elastic.co/t/asp-net-6-0-agent-seems-to-fail-instantiation-occasionally-no-errors-in-logs/320890>\
**Category:** APM\
**Tags:** dotnet, language-clients\
**Created:** [December 9, 2022, 2:10pm UTC](https://discuss.elastic.co/t/asp-net-6-0-agent-seems-to-fail-instantiation-occasionally-no-errors-in-logs/320890 "2022-12-09T14:10:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mellow](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@Mellow](https://discuss.elastic.co/u/Mellow)\
**Post date:** [December 9, 2022, 2:10pm UTC](https://discuss.elastic.co/t/asp-net-6-0-agent-seems-to-fail-instantiation-occasionally-no-errors-in-logs/320890/1 "2022-12-09T14:10:01Z")

</div>

**APM Agent language and version** : Elastic.Apm.NetCoreAll (1.16.0) and .NET 6.0

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**: Nuget

**Fresh install or upgraded from other version?** Fresh

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

When I run my solution locally sometimes it seems that the APM Agent does not start. Seems to happen 10-20% of the times.

After calling

```
        DiagnosticListener.AllListeners.Subscribe(new Subscriber());
        return builder.UseElasticApm(configuration, new HttpDiagnosticsSubscriber());

```

I have tried running loglevel at trace and the log files seem nearly identical except we get the following when APM works

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/1/11a54d8a858d4e601f6cb0ab147b789395061247.png)

When the Agent does not generate Transactions or Spans it seems like it still is collecting metric data.

Agent Initialization stack

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/d/cdbdc9ba53b236a922240801b2aeb6b9c0deba5f.png)

---

<div class="post-metadata">

**Author:** ![Wolfgang\_Ziegler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfgang_ziegler/32/109929_2.png) [@Wolfgang\_Ziegler](https://discuss.elastic.co/u/Wolfgang_Ziegler)\
**Post date:** [December 12, 2022, 10:58am UTC](https://discuss.elastic.co/t/asp-net-6-0-agent-seems-to-fail-instantiation-occasionally-no-errors-in-logs/320890/2 "2022-12-12T10:58:27Z")

</div>

Hi @Mellow,

that's correct, the agent will collect metric data independently of transactions/spans.

From the log screenshots, it's hard to tell why you get transaction data in some cases and in others not. Can you confirm that the application and the scenario you are testing are always the same?  
If you have a simple reproducer project, I can take a look.

---

<div class="post-metadata">

**Author:** ![Mellow](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@Mellow](https://discuss.elastic.co/u/Mellow)\
**Post date:** [December 15, 2022, 9:51am UTC](https://discuss.elastic.co/t/asp-net-6-0-agent-seems-to-fail-instantiation-occasionally-no-errors-in-logs/320890/3 "2022-12-15T09:51:02Z")

</div>

Hey, It seems that I had missed this sentence in the documentation.

> The `app.UseAllElasticApm(...)` line **must** be the first line in the `Configure` method, otherwise the agent won’t be able to properly measure the timing of your requests, and complete requests may potentially be missed by the agent

After I moved the line to the top it seems to fix the issue.

---

<div class="post-metadata">

**Author:** ![Wolfgang\_Ziegler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfgang_ziegler/32/109929_2.png) [@Wolfgang\_Ziegler](https://discuss.elastic.co/u/Wolfgang_Ziegler)\
**Post date:** [December 15, 2022, 1:33pm UTC](https://discuss.elastic.co/t/asp-net-6-0-agent-seems-to-fail-instantiation-occasionally-no-errors-in-logs/320890/4 "2022-12-15T13:33:26Z")

</div>

Thanks for reporting back @Mellow.  
I'm glad you could resolve your issue!

---

<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:** [January 5, 2023, 9:33am UTC](https://discuss.elastic.co/t/asp-net-6-0-agent-seems-to-fail-instantiation-occasionally-no-errors-in-logs/320890/5 "2023-01-05T09:33:44Z")

</div>

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