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

Add ability to turn on SQL query logging for Azure Functions #2548

Closed
krishnasingh1818 opened this issue Aug 13, 2020 · 11 comments · Fixed by #2608 or Azure/azure-functions-host#6851
Closed
Assignees

Comments

@krishnasingh1818
Copy link

krishnasingh1818 commented Aug 13, 2020

Before 28 july 2020 we were able to see the sql queries in appinsight dependencies logs, but now we are only seeing server names and no sql queries are logged from azure functions consumption plan. We have other code in aks cluster and sql queries are logged for calls done for app hosted in aks.

Expected behavior

Sql queries not logged in appinsight for azure function consumption plan.

Actual behavior

Sql queries should be logged in appinsight for azure function consumption plan.

Known workarounds

i tried this link but it didnt help
microsoft/ApplicationInsights-dotnet#1425
Also adding reference to this dll brings aspnetcore things in azurefuctions project and is not making sense

Related information

Provide any related information

  • Package version
  • Links to source
    image
@krishnasingh1818
Copy link
Author

in appinsight under command section we are just seeing server name instead of full sql query that is execute. please advise.
image

@ThejaChoudary
Copy link

@krishnasingh1818 it would be great if you share a simple repro ,we will investigate further.

@pragnagopa
Copy link
Member

More details: microsoft/ApplicationInsights-dotnet#1425

@brettsam - Do you have any more details on this? Do we have to update SDK to expose an option to enable SQL query logging?

@pragnagopa pragnagopa added this to the Triaged milestone Sep 24, 2020
@pragnagopa pragnagopa changed the title Sql query not showing up in appinsight. It stopped from 28-July-2020 Add ability to turn on SQL query logging for Azure Functions Sep 24, 2020
@brettsam
Copy link
Member

We need to expose a new setting that we flow through to the App Insights SDK -- EnableSqlCommandTextInstrumentation. Will assign this to next sprint.

@piotrzbyszynski
Copy link

@brettsam I have SQL command text instrumentation (in Azure Function Startup.cs) disabled like so:

builder.Services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((m, o) =>
            {
                m.EnableSqlCommandTextInstrumentation = configuration.GetValue<bool>("SqlQueryLoggingIsEnabled");
            });

Now, not only SQL command text is not logged, but SQL dependency is not logged at all. I would expect that dependency is still logged, bu only SQL query text is disabled. If I turn EnableSqlCommandTextInstrumentation on, both dependency and sql query text is logged

Here are dependencies I am using:

  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.15.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.15.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
    <PackageReference Include="System.Runtime" Version="4.3.1" />
  </ItemGroup>

Any thoughts would be appreciated

@krishnasingh1818
Copy link
Author

i added below code in my function startup but still its not showing sql command text. it is showing dependency in appinsight but command text is only show sql servername instead of full command text.

builder.Services.ConfigureTelemetryModule((m, o) =>
{
m.EnableSqlCommandTextInstrumentation = true;
});

image

@brettsam
Copy link
Member

@krishnasingh1818 -- doing that won't work in Functions. PR #2608 will fix this by exposing these settings in host.json.

@krishnasingh1818
Copy link
Author

Microsoft.Azure.WebJobs 3.0.24 seems has fix for this issue but I don't see it available on nuget.org . within how many days should I expect it to be available on nuget.org so that I can upgrade my version. pls advise.

thanks.
krishna

@piotrzbyszynski
Copy link

@brettsam Not sure how to use this fix, so I have few questions:

  1. Should we use it via host.json like so (I do not see this setting documented here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#applicationinsights)?
    "applicationInsights": {
      "enableDependencyTracking": true,
      "dependencyTrackingOptions": {
        "enableSqlCommandTextInstrumentation": true
      }
    }
  1. Is there ability to set enableSqlCommandTextInstrumentation in code?
  2. Do we need to explicitly include Microsoft.Azure.WebJobs and Microsoft.Azure.WebJobs.Logging.ApplicationInsights nugets in function project
  3. Even though I have dependency tracking enabled I can not see any SQL dependencies logged (with or without SQL command text included)

Any help would be highly appreciated

@cmanoliu
Copy link

@soninaren @brettsam
Hello,

Can anyone please respond to @pzbyszynski ?
I have the same problem and wasting a lot of time trying to workaround this issue. Existing documentation does not help.
An answer would be very helpfull. Thank you.

Regards,

Catalin

@piotrzbyszynski
Copy link

@cmanoliu Please have a look here: Azure/Azure-Functions#1613 (comment)

The workaround for this issue is downgrading EF & AI libraries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment