question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tracking dependencies with Application Insights

See original GitHub issue

We are deploying our .NET Core application(s) on Azure, using Azure AppServices and Azure Database for PostgreSQL server.

We’ve started to add Application Insights, and most of the external dependencies are automatically tracked/graphed, except for the database. For example, I can see all interactions and timing to the Storage accounts, or an external REST API, but not the SQL queries and number of instances in a request to a database.

According to the Azure documentation, SQL dependencies are automatically tracked via the SqlClient, with nothing more to do for .NET Core. However, I’m assuming that the Npgsql provider doesn’t use the SqlClient under the hood.

Is there anything I can configure in the Npgsql EF Core provider that will allow for the automatic tracking of Sql queries and dependencies, or is it coming in v5?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
froenscommented, Feb 2, 2022

I was able to add dependency calls by using the OpenTelemetry-package (requires net6.0): https://www.npgsql.org/doc/diagnostics/tracing.html

Then use the Azure Monitor Exporter-package (Link) to export your OpenTelemetry to Application Insights.

Add this to ConfigureServices-method:

services.AddOpenTelemetryTracing((builder) =>
            {
                builder
                .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName: serviceName, serviceVersion: serviceVersion))
                .SetSampler(new AlwaysOnSampler())
                .AddSource(serviceName)
                .AddNpgsql()
                .AddAzureMonitorTraceExporter(o =>
                {
                    o.ConnectionString = @"<INSERT FROM YOUR AZURE MONITOR CONFIGURATION>";
                });
            });
1reaction
rojicommented, Feb 2, 2022

@froens thanks, that’s great to hear!

I’m planning to further improve Npgsql’s OpenTelemetry support - this will be Npgsql’s main focus where diagnostics/observability is concerned. I’ll go ahead and close this issue as we shouldn’t need to do anything specific for Application Insights.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency tracking in Application Insights - Azure Monitor
Monitor dependency calls from your on-premises or Azure web application with Application Insights.
Read more >
Configure Dependency Collection Using Insights SDK for . ...
Application Insights can automatically track dependencies to supported targets since these libraries implement Diagnostic Source publishers.
Read more >
Disable tracking dependencies in Azure Function Application ...
Disable tracking dependencies in Azure Function Application Insights · How to disable the extra telemetry: Option 1 · How to disable the extra...
Read more >
Diagnosing issues with dependencies in Application Insights
Diagnosing issues with dependencies in Application Insights. A dependency is an external component that is called by your app.
Read more >
Application Insights - Why do custom dependencies track ...
You can start a new dependency trace by using StartOperation . This way, the operation is linked to the parent operation (the request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found