Skip to main content

Posts

Azure Application Insights–Log SQL query

One of the nice features that Application Insights has to offer is the ability to automatically track dependencies . Among the list of tracked dependencies you find database calls (made through System.Data.SqlClient or Microsoft.Data.SqlClient). By default the name of the server and database are collected together with the length of the call. But no extra information like the database query is logged. To log the database query as well, you explicitly need to enable this in ASP.NET Core: After this code change, you’ll find the SQL Command in the Command section instead of the name of the server and database: Remark: For ASP.NET applications, full SQL query text is collected with the help of byte code instrumentation, which requires the Microsoft.Data.SqlClient NuGet package instead of the System.Data.SqlClient library.
Recent posts

Azure Application Insights– Collect Performance counters data

One of the features you get out-of-the-box when using Application Insights is the ability to collect performance counter data. This allows you to track statistics like CPU, memory and disk usage. In ASP.NET Core the following counters are collected by default: % Process\Processor Time % Process\Processor Time Normalized Memory\Available Bytes Process\Private Bytes Process\IO Data Bytes/sec Processor(_Total)\% Processor Time When the performance counters are collected correctly, you can use them as one of the available metrics in Application Insights: Troubleshooting performance counters collection But what if no data is returned? First thing you should check, if you have a related log message. Therefore run the following KQL query inside the Logs section: traces | where message startswith "AI: Error collecting" | limit 10 In my case it returned the following error message: AI: Error collecting 6 of the configured perf

C# 10–File scoped namespaces

Last week I had a pair programming session with a candidate. The candidate had a background in C and was new to C#. While he was writing some code, he was struggling with namespaces in C#. It even got me confused as I completely forgot that C# 10 introduced a new feature 'file scoped namespaces' . I always had written namespaces in any of the following ways: The advantage of this approach is that you could have multiple namespaces in one file. But in reality I think I never used this possibility. The disadvantage is that traditional namespaces add some extra ceremony to your code. C# 10 gets rid of this boilerplate code when you want to use only one namespace per file. So the example above can be rewritten as: All the types we write in this file will be part of the X.Y.Z namespace. Update your existing code To update your existing code in one go, you can use the dotnet format tool: dotnet tool update --global dotnet-format dotnet format Example.sln --severity

Monitor RabbitMQ metrics in ElasticSearch

One of the reasons we are using ElasticSearch is to bring all the metrics from multiple systems together in one place. One of the systems we want to monitor is our RabbitMQ cluster. Let's walk through the steps to get our RabbitMQ metrics send to ElasticSearch and available in Kibana. The RabbitMQ Metrics Integration Open up Kibana and click on the hamburger icon in the left corner. This will open up a side menu with a big ‘Add integrations’ button at the bottom. Hit this button to go to the Integrations overview page. Here you can see the list of all available integrations. Let’s search for “rabbitmq”. We get 2 results back. Click on the ‘RabbitMQ Metrics’ integration to go to the installation instructions. Install MetricBeat on Windows The RabbitMQ metrics integration is part of MetricBeat . MetricBeat is a lightweight shipper that you can install on your servers to periodically collect metrics from the operating system and from services running on those ser

ElasticSearch - setting [cluster.initial_master_nodes] is not allowed when [discovery.type] is set to [single-node]

Upgrading ElasticSearch can be quite challenging(at least for me it was). I talked about some other issues I had while upgrading before . Let's add a last one to the list... When talking about the bootstrap check failures in a previous post , I shared my final solution. But if you were paying attention as a reader you maybe noticed that I didn’t follow the suggestions mentioned inside the bootstrap check error: bootstrap check failure [1] of [2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured I didn’t set the discovery.seed_hosts , discovery.seed_providers or cluster.initial_master_nodes setting as mentioned, instead I changed the discovery.type to single-node . In fact my first attempt looked like this: However this resulted in the following error message: [2022-05-09T11:33:18,943][WARN ][stderr                   ] [SERVER1] java

ElasticSearch Bootstrap check failure

Upgrading ElasticSearch can be quite challenging(at least for me it was). I talked about some other issues I had while upgrading before. Let's add another one to the list... One of the ways how ElasticSearch helps you to do the right things is to do some bootstrap checks . These bootstrap checks inspect a variety of Elasticsearch and system settings and compare them to values that are safe for the operation of Elasticsearch. If Elasticsearch is in development mode, any bootstrap checks that fail appear as warnings in the Elasticsearch log. If Elasticsearch is in production mode, any bootstrap checks that fail will cause Elasticsearch to refuse to start. In this case the bootstrap checks returned the following errors: [2022-05-09T09:53:42,647][ERROR][o.e.b.Bootstrap          ] [SERVER1] node validation exception [2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch. bootstrap check failure [1] of [2]:

ElasticSearch- Unrecognized VM option 'UseConcMarkSweepGC'

Upgrading ElasticSearch can be quite challenging(at least for me it was). I talked about some other issues I had while upgrading before. Let's add another one to the list... After installing ElasticSearch 8.1 I couldn’t get it started. Here is the error I got instead: 12:31:34 » Exception in thread "main" java.lang.RuntimeException: starting java failed with [1] 12:31:34 » output: 12:31:34 » 12:31:34 » error: 12:31:34 » Unrecognized VM option 'UseConcMarkSweepGC' 12:31:34 » Error: Could not create the Java Virtual Machine. 12:31:34 » Error: A fatal exception has occurred. Program will exit. 12:31:34 » at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:118) 12:31:34 » at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:86) 12:31:34 » at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:59) 12:31:34 » at org.elasticsearch.tools.launchers.JvmOptionsParser.main