Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Elsakrishi29 opened this issue Aug 7, 2024 · 3 comments · Fixed by #2505
Closed

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

Elsakrishi29 opened this issue Aug 7, 2024 · 3 comments · Fixed by #2505
Labels
bug Something isn't working community triage

Comments

@Elsakrishi29
Copy link

Elsakrishi29 commented Aug 7, 2024

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?

@Elsakrishi29 Elsakrishi29 added the bug Something isn't working label Aug 7, 2024
@Mpdreamz
Copy link
Member

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

@Elsakrishi29
Copy link
Author

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
Copy link

Seems to be a duplicate of #2311

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

Does it work without the ConfigureFunctionsWebApplication call?

stevejgordon added a commit that referenced this issue Nov 29, 2024
This PR fixes several things in Azure Functions (isolated worker) which
occur when using the latest templates for Azure Functions.

- Newer versions of the Functions library prefer the gRPC-based
implementation, which throws when `Url` is accessed. Instead, we read
these from other data on the `FunctionContext`.
- Address Functions library changes that break distributed tracing. We
now parse the original headers from the `BindingContext` instead of the
request, which may contain a `traceparent` with the sampling flag set to
false when the user request does not include a specific `traceparent`.
- We explicitly don't record activities from the Azure functions library
as these are pretty broken
(Azure/azure-functions-dotnet-worker#2733) and
are redundant when using our middleware.
- Downgrade several packages as the newer ones are now deprecated
(thanks for the confusion, Microsoft!).
- Update some outdated compiler pre-processor directives.
- The final few commits focus on CI integration test hangs on Linux. We
don't have a perfect solution for those, but after reviewing the hang
dumps, I've avoided some of the potential causes of the hangs. We'll
monitor subsequent PRs, and if they remain stable, we will readdress the
original causes.

A follow-up PR will update our documentation.

Closes #2407 
Closes #2311
Closes #2218
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants