Skip to content

Instantly share code, notes, and snippets.

@taddison
Created December 20, 2018 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taddison/4bcd73c79aa09d686d3f22adef5e9ea1 to your computer and use it in GitHub Desktop.
Save taddison/4bcd73c79aa09d686d3f22adef5e9ea1 to your computer and use it in GitHub Desktop.
appinsights sql check
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DependencyCollector;
using Microsoft.ApplicationInsights.Extensibility;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var config = TelemetryConfiguration.Active;
config.InstrumentationKey = "nope";
var client = new TelemetryClient();
var module = new DependencyTrackingTelemetryModule();
module.Initialize(config);
using (var conn = new SqlConnection("server=server;initial catalog=master;trusted_connection=true"))
{
conn.Open();
for (var i = 0; i < 600; i += 10)
{
var ts = new TimeSpan(0, 0, i);
using (var cmd = new SqlCommand($"waitfor delay '00:{ts.Minutes:00}:{ts.Seconds:00}'", conn))
{
cmd.CommandTimeout = Int32.MaxValue;
client.TrackTrace($"Running SQL query for {ts.TotalSeconds} seconds");
cmd.ExecuteNonQuery();
}
}
}
client.Flush();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment