# Elastic APM Azure Functions DiagnosticsSubscribers not working after first execution

**URL:** <https://discuss.elastic.co/t/elastic-apm-azure-functions-diagnosticssubscribers-not-working-after-first-execution/355594>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [March 18, 2024, 11:25am UTC](https://discuss.elastic.co/t/elastic-apm-azure-functions-diagnosticssubscribers-not-working-after-first-execution/355594 "2024-03-18T11:25:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrisarkameru](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrisarkameru/32/112242_2.png) [@andrisarkameru](https://discuss.elastic.co/u/andrisarkameru)\
**Post date:** [March 18, 2024, 11:25am UTC](https://discuss.elastic.co/t/elastic-apm-azure-functions-diagnosticssubscribers-not-working-after-first-execution/355594/1 "2024-03-18T11:25:24Z")

</div>

Hi!

I'm trying to add Elastic APM to Azure functions, but I'm having limited success.

Could you please tell me If this is not supported, or am I doing something wrong?

I have azure functions that are successfully reporting the call of the http-triggered function. But I'm having trouble with other diagnostic subscribers working only on cold start. Could you please clarify the proper useage or if it's maybe not even intended to work like that? As I see in the manual [[Azure Functions | APM .NET Agent Reference [1.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/dotnet/current/setup-azure-functions.html)] that only the APMMiddleware is mentioned.

I'm using Azure Functions (.NET 6) in isolated mode with Elastic APM NuGet version 1.26.0.

Here's a a trace of same request right after Azure Functions App restart and a later (and all the next ones look similar) :

 ![apn_first_redacted](https://us1.discourse-cdn.com/elastic/original/3X/b/f/bf9b90d7615ff441e1d75051016ff2e92b8fdabd.png)  
 ![apn_second_redacted](https://us1.discourse-cdn.com/elastic/original/3X/2/c/2ccd3ade29c4682eb2a105e2400861dfb178cbd9.png)

As you see - only the first execution got CosmosDB logged. The second one (an all the next ones until I restart the app) are getting only Http Logged. Since this is a PUT request where data is changing, there is no caching involved so the CosmosDB is actually executing here.

This is how I initialize the Function app:

```auto
var host = new HostBuilder()
//some other code 
.UseAllElasticApm()
.ConfigureFunctionsWorkerDefaults(builder =>
{
    builder.UseMiddleware<ApmMiddleware>();
})
.ConfigureAppConfiguration(...)
.ConfigureServices(...)
.Build();

 await host.RunAsync();

```

P.S.  
I have also tried doing suggestions from this thread:  
[APM on Azure Functions - Elastic Observability / APM - Discuss the Elastic Stack](https://discuss.elastic.co/t/apm-on-azure-functions/327947)

And adding manual subscription to all the diagnosticSubscribers in the HttpMiddleware after the agent is configured, but I got same results locally.

Any help and suggestions appreciated. 🙂  
Thank you!

---

<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:** [April 15, 2024, 11:26am UTC](https://discuss.elastic.co/t/elastic-apm-azure-functions-diagnosticssubscribers-not-working-after-first-execution/355594/2 "2024-04-15T11:26:19Z")

</div>

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