elastic / apm-agent-dotnet

https://www.elastic.co/guide/en/apm/agent/dotnet/current/index.html
Apache License 2.0
586 stars 208 forks source link

[BUG] Dotnet Azure Function Not captured in elastic #2407

Closed Elsakrishi29 closed 2 days ago

Elsakrishi29 commented 3 months ago

We followed this link to add elastic dotnet apm agent to our azure function.

The functions are not captured in elastic, then I didn't get any logs in my azure cloud function. ( After integrating the Elastic APM tracing middleware into my Azure Functions app, the function executes successfully but does not return any data or response when accessing the endpoint. The function works correctly when the middleware is not included )

Agent instrumentation (Program.cs)

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Elastic.Apm.Azure.Functions;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults(builder =>
    {
        builder.UseMiddleware<ApmMiddleware>();
    })
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services => {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();

Could someone please help me figure out why this error is occurring?

Mpdreamz commented 3 months ago

Thanks for bringing this to our attention @Elsakrishi29 do you get any azure logs from the invocation?

Elsakrishi29 commented 3 months ago

Every time I add Elastic configuration to my application, it fails to work properly.

If i removed those configuration in my application it will work fine

logs

Connected!
2024-08-16T07:49:16Z   [Information]   Executing 'Functions.HttpExample' (Reason='This function was programmatically called via the host APIs.', Id=b65075f0-c5bc-45ec-a878-2f022a4132e1)
2024-08-16T07:49:16Z   [Information]   Executed 'Functions.HttpExample' (Succeeded, Id=b65075f0-c5bc-45ec-a878-2f022a4132e1, Duration=19ms)
2024-08-16T07:49:41Z   [Information]   Executing 'Functions.HttpExample' (Reason='This function was programmatically called via the host APIs.', Id=b9b094ec-2991-4ff3-a208-5146a7de5b50)
2024-08-16T07:49:41Z   [Information]   Executed 'Functions.HttpExample' (Succeeded, Id=b9b094ec-2991-4ff3-a208-5146a7de5b50, Duration=4ms)
2024-08-16T07:49:41Z   [Information]   Executing 'Functions.HttpExample' (Reason='This function was programmatically called via the host APIs.', Id=38e5d51d-8813-477f-9273-cba982f37d0e)
2024-08-16T07:49:41Z   [Information]   Executed 'Functions.HttpExample' (Succeeded, Id=38e5d51d-8813-477f-9273-cba982f37d0e, Duration=3ms)

Configuration

dotnetelasticapp-Microsoft-Azure

th3ragex commented 3 months ago

Seems to be a duplicate of #2311

    .ConfigureFunctionsWorkerDefaults(builder =>
    {
        builder.UseMiddleware<ApmMiddleware>();
    })
    .ConfigureFunctionsWebApplication() -> calls "ConfigureFunctionsWorkerDefaults" internally too

Does it work without the ConfigureFunctionsWebApplication call?