# APM .net agent errors

**URL:** <https://discuss.elastic.co/t/apm-net-agent-errors/334095>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [May 23, 2023, 9:37am UTC](https://discuss.elastic.co/t/apm-net-agent-errors/334095 "2023-05-23T09:37:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joao\_Cardoso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joao_cardoso/32/120395_2.png) [@Joao\_Cardoso](https://discuss.elastic.co/u/Joao_Cardoso)\
**Post date:** [May 23, 2023, 9:37am UTC](https://discuss.elastic.co/t/apm-net-agent-errors/334095/1 "2023-05-23T09:37:13Z")

</div>

Hello, i have been playing arround with elastic apm .net agent and i have some questions/doubts i was hoping someone could help.  
Im using .net 6 with "UseAllElasticApm" which works just fine for my HTTP requests.  
My issue is with the exceptions handling how these are displayed in the APM errors view.

I have a custom filter in my app that captures any exception and handles it, like this:

```auto
public async override Task OnExceptionAsync(ExceptionContext context)
    {
        logger.LogError(context.Exception, context.Exception.Message);
        context.Result = new StatusCodeResult(500);
        context.ExceptionHandled = true;
    }

```

When i do this, i do not see any errors in my elastic apm view (in the errors tab). If i re throw the exception, then i see the errors but my app behavior changes (i have other middlewares that are not expecting to receive the exception).

Is this the normal behavior? If yes, what can i do in order to keep my exception filter handling my exceptions but at the same time, having my app errors being displayed in the apm view?

Thank you in advance!

EDIT:  
Is this a good approach to handle my problem?  
` Agent.Tracer.CurrentTransaction.CaptureException(context.Exception);`

---

<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:** [June 20, 2023, 9:38am UTC](https://discuss.elastic.co/t/apm-net-agent-errors/334095/2 "2023-06-20T09:38:10Z")

</div>

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