Application Insights not logging SQL Dependencies queries - asp.net-core

I'm using an App service hosted in Azure using Asp.Net Core & .Net5. I turned on SQL dependency tracking using below settings in appSettings.config. But I see SQL dependencies logged without SQL command Text. Is there any other settings to enable to see SQL commands in the log?
"ApplicationInsights": {
"InstrumentationKey": "my guid key",
"EnableDependencyTracking": true,
"DependencyTrackingOptions": {
"EnableSqlCommandTextInstrumentation": true
},
"sampling": {
"isEnabled": true,
"maxTelemetryItemsPerSecond": 5
}
},

Your settings in appSettings.config is for Azure Function, not ASP.NET Core applications.
For ASP.NET Core applications, It is now required to opt-in to SQL Text collection by using
services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) => { module. EnableSqlCommandTextInstrumentation = true; });
For more details, you can refer official doc
Advanced SQL tracking to get full SQL Query

Related

Why is the Azure App Configuration feature flag not found?

Azure Functions app, runtime v3.
The application has a FunctionsStartup class that first enables Azure App Configuration in its ConfigureAppConfiguration method:
builder.ConfigurationBuilder.AddAzureAppConfiguration(options =>
{
options
.Connect(appConfigurationConnectionString)
.UseFeatureFlags();
});
And in its Configure method it enables feature management, and it adds the Azure App Configuration services (so we can refresh settings at runtime):
builder.Services
.AddAzureAppConfiguration()
.AddFeatureManagement()
.AddFeatureFilter<ContextualTargetingFilter>();
On the Azure Portal there is a feature flag, which is enabled, called CardExpirationNotice. The code uses IFeatureManagerSnapshot to check if the feature is enabled:
feature = nameof(Features.CardExpirationNotice);
var isEnabled = await _featureManagerSnapshot.IsEnabledAsync(feature);
isEnabled is false, and this log message is output:
The feature declaration for the feature 'CardExpirationNotice' was not found.
I tried configuring a flag locally in local.settings.json:
"FeatureManagement__CardExpirationNotice": true
Then isEnabled is true, so I can narrow the problem to Azure App Configuration, and exclude the feature management implementation.
As it turns out, when you add a feature flag in Azure App Configuration, you can set a label. But if you do that, then you need to specify that label in your code as well:
builder.ConfigurationBuilder.AddAzureAppConfiguration(options =>
{
options
.Connect(appConfigurationConnectionString)
.UseFeatureFlags(options => options.Label = "payments");
});

How can we disable ANSI/VT100 color codes added to ASP.NET Core logs

We are hosting our ASP.NET Core services in Google Cloud, and the logs from Stack Driver always use ANSI/VT100 color codes, like this:
[40m[32minfo[39m[22m[49m
Is there a way to tell the ASP.NET default logger to not use those codes?
(P.S.: I know we should move to structured logging, that's next)
based on the github issue,
set ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS env to true or add this to your appsettings.json:
"Logging": {
"Console": {
"DisableColors": true
}
}

Refesh data in InMemory Mode In SSAS

I have created a tabular project in "In Memory" Mode. I want to refresh the data on daily basis. Is there any way to schedule a job which will refresh the data on daily basis?
Your options are rather limited atm
You can't automate it directly from portal (you can vote here for such functionality)
You can trigger refresh from azure function
#r "D:\home\site\wwwroot\yourfunccatalog\bin\Microsoft.AnalysisServices.DLL"
#r "D:\home\site\wwwroot\yourfunccatalog\bin\Microsoft.AnalysisServices.Core.DLL"
#r "D:\home\site\wwwroot\yourfunccatalog\bin\Microsoft.AnalysisServices.Tabular.DLL"
using System;
public static void Run(string input, TraceWriter log)
{
var server = new Microsoft.AnalysisServices.Tabular.Server();
server.Connect("Provider=MSOLAP;Data Source=asazure://[...];User ID=[...];Password=[...];Catalog=[...];Persist Security Info=True; Impersonation Level=Impersonate;");
var model = server.Databases[0].Model;
model.RequestRefresh(Microsoft.AnalysisServices.Tabular.RefreshType.Full);
model.SaveChanges();
server.Disconnect();
}
You will have to upload dlls before you run it (In my case c:\Program Files (x86)\Microsoft SQL Server\130\SDK\Assemblies)
Azure automation might be an option if powershell is your thing. use invoke-ASCmd servlet
xmla script should look like this (haven't tested it!)
<Statement xmlns="urn:schemas-microsoft-com:xml-analysis">
{
"refresh": {
"type": "full",
"objects": [
{
"database": "Your database name here"
}
]
}
}
</Statement>
use c# tabular object model

Enterprise Library default connection is not define in ASP.net MVC Core

Enterprise Library default connection is not picking ASP.net MVC Core from AppSetting.json I'm getting below error
The configuration file does not define a default database.
"ConnectionStrings": { "DefaultConnection":
"Server=(localdb)\mssqllocaldb;Database=CustomConfiguration‌​Provider-D02F4CA7-9E‌​25-4121-BF38-195FCAE‌​674DE;Trusted_Connec‌​tion=True;MultipleAc‌​tiveResultSets=true"
}, "DataConfiguration": { "DefaultDatabase": "DefaultConnection",
"providerName": "System.Data.SqlClient" }

How to log sql queries when app startup

How to log the sql queries ( insert, create ,alter ) in grails application when the app start for the first time. I tried with log_sql true but it logging only when application is running not when application starting?
In your Datasource.groovy file add this to your hibernate closure:
hibernate{
show_sql=true
}
All your queries, even those executed during bootstrap (startup), should be shown.
Assuming you only want this to happen in the development environment, add the following to DataSource.groovy
environments {
development {
dataSource {
logSql = true
}
hibernate {
format_sql = true
}
}
}