Skip to content

Instantly share code, notes, and snippets.

@debugthings
debugthings / Global.asax.cs
Created March 6, 2017 15:39
Disable AI Telemetry when Debugging
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
if (System.Diagnostics.Debugger.IsAttached)
{
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = true;
}
}
}
using Owin;
using System;
using System.Runtime.Remoting.Messaging;
using Microsoft.Owin;
using Microsoft.Owin.Hosting;
using ApplicationInsights.OwinExtensions;
using Microsoft.ApplicationInsights.Channel;
public class GetBrowserOnServerOwinSelfHost : Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
@debugthings
debugthings / ai.sharepoint.aspx
Created December 30, 2016 15:45
Updated Application Insights Sharepoint ID
<SharePoint:ScriptLink ID="ScriptLink1" name="SP.js" runat="server" localizable="false" loadafterui="true" />
<SharePoint:ScriptLink ID="ScriptLink2" name="SP.UserProfiles.js" runat="server" localizable="false" loadafterui="true" />
<script type="text/javascript">
var personProperties;
// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js');
function getUserProperties() {
@debugthings
debugthings / GetBrowserOnServer.cs
Created December 28, 2016 17:43
Set Browser on Server Side Telemetry
public class GetBrowserOnServer : Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
try
{
if (telemetry is Microsoft.ApplicationInsights.DataContracts.RequestTelemetry)
{
var telem = telemetry as Microsoft.ApplicationInsights.DataContracts.RequestTelemetry;
if (System.Web.HttpContext.Current.Request.Browser != null)
@debugthings
debugthings / NoArgumentExceptionsFilter.cs
Created October 20, 2016 18:59
No Argument Exceptions Filter
public class NoArgumentExceptionsFilter : Microsoft.ApplicationInsights.Extensibility.ITelemetryProcessor
{
private ITelemetryProcessor Next { get; set; }
private bool parsed = false;
public string ExceptionToFilter { get; set; }
public NoArgumentExceptionsFilter(ITelemetryProcessor next)
{
this.Next = next;
}
@debugthings
debugthings / ApplicationInsights.config
Created October 13, 2016 02:16
Instant Read Alert Rule
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<TelemetryProcessors>
<Add Type="SFLCC.InstantReadProcessor, SFLCC">
<RequestDurationToTriggerOnInMilliseconds>5000</RequestDurationToTriggerOnInMilliseconds>
<TimeToStayTriggeredInSeconds>60</TimeToStayTriggeredInSeconds>
</Add>
</TelemetryProcessors>
</ApplicationInsights>
public class IPAddressTelemetryInitializer : Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
if (telemetry is Microsoft.ApplicationInsights.DataContracts.RequestTelemetry)
{
var telem = telemetry as Microsoft.ApplicationInsights.DataContracts.RequestTelemetry;
var ip = System.Web.HttpContext.Current.Request.UserHostAddress;
telem.Properties.Add("IP", ip);
}
@debugthings
debugthings / CaptureStream.cs
Created September 8, 2016 20:36
Part of a solution to capture the response of a web request.
using System;
using System.IO;
using System.Text;
public class CaptureStream : Stream
{
private Stream ResponseStream = null;
private int len = 0;
private StringBuilder sb;
@debugthings
debugthings / GetSOAPActionInitializer.cs
Created September 2, 2016 15:51
Custom Telemetry Initializer that Gets the SOAP Action
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CustomTelemetryInitializer
{
public class GetSOAPActionInitializer : Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
public void Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry)
@debugthings
debugthings / AsyncPost
Created April 9, 2015 04:29
Stack Trace AsyncResult
"<unnamed thread>" tid=0x0x7fffee397700 this=0x0x7ffff4edeed0 thread handle 0x43f state : not waiting owns ()
at <unknown> <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_debugger_agent_user_break () <IL 0x0000c, 0xffffffff>
at System.Runtime.Remoting.Messaging.AsyncResult..ctor (System.Threading.WaitCallback,object,bool) [0x00014] in /home/jldgit/mono/mcs/class/corlib/System.Runtime.Remoting.Messaging/AsyncResult.cs:74
at System.Threading.ThreadPool.QueueWorkItem (System.Threading.WaitCallback,object) [0x00000] in /home/jldgit/mono/mcs/class/corlib/System.Threading/ThreadPool.cs:102
at System.Threading.Tasks.TpScheduler.QueueTask (System.Threading.Tasks.Task) [0x00041] in /home/jldgit/mono/mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs:53
at System.Threading.Tasks.Task.Schedule (bool) [0x00007] in /home/jldgit/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:395
at System.Threading.Tasks.Task.Start (System.Threading.Tasks.TaskScheduler) [0x0005b] in /home/jld