Skip to content

Instantly share code, notes, and snippets.

@debugthings
debugthings / ActivityCorrelationBehavior.cs
Created July 31, 2018 12:33
Wcf Activity correlation
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Threading.Tasks;
@debugthings
debugthings / WebTestCommands.ps1
Created December 5, 2017 20:23
Retrieve the URL inside of an Availability Test using a partial name or a partial URL
function Get-WebTestByURL {
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='The Azure subscription id to search.')]
[Alias('SubId')]
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using System;
public class NoAzureBlobLoggingCalls : Microsoft.ApplicationInsights.Extensibility.ITelemetryProcessor
{
private ITelemetryProcessor Next { get; set; }
private bool parsed = false;
public const string AzureBlob = "Azure blob";
public const string AccountName = "kmshdprodlogs";
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.ComponentModel;
namespace CustomPlugin
{
[DisplayName("Replace Encoded Slash")]
[Description("Replaces %2F with %252F to avoid the doubleslash (//) escape.")]
public class FixFilter : WebTestRequestPlugin
{
public FixFilter() { }
@debugthings
debugthings / NotMyHostnameFilter.cs
Created July 17, 2017 01:20
Filter out request telemetry that is not to my hostname
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using System;
public class NotMyHostNameFilter : Microsoft.ApplicationInsights.Extensibility.ITelemetryProcessor
{
private ITelemetryProcessor Next { get; set; }
private bool parsed = false;
public string ExceptionToFilter { get; set; }
@debugthings
debugthings / GetUserInitializer.cs
Created July 5, 2017 18:40
Get Authenticated User Id
using System;
using System.Web;
using Microsoft.ApplicationInsights.Channel;
public class GetUserInitializer :
Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
if (telemetry is Microsoft.ApplicationInsights.DataContracts.RequestTelemetry)
@debugthings
debugthings / AppInsightsFilter.cs
Created March 12, 2017 02:05
Enable Application Insights on Migraged Azure Mobile Services applications
internal static class RequestTrackingConstants
{
/// <summary>
/// Name of the HttpContext item containing RequestTelemetry object.
/// </summary>
internal const string RequestTelemetryItemName = "Microsoft.ApplicationInsights.RequestTelemetry";
internal const string EndRequestCallFlag = "Microsoft.ApplicationInsights.EndRequestCallFlag";
/// <summary>
@debugthings
debugthings / AddQuickPulseNakedMethod.cs
Created March 9, 2017 18:30
Add QuickPulse programatically
public void EnableQuickPulse()
{
var qpmod = new Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule();
qpmod.Initialize(actConfig);
Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryModules.Instance.Modules.Add(qpmod);
actConfig.TelemetryProcessorChainBuilder.Use((next) =>
{
@debugthings
debugthings / Global.asax.cs
Created March 9, 2017 17:53
Implement Application Insights in Code as the HttpModule does
// Constants stolen from
// https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/v2.2.0/Src/Web/Web.Shared.Net/Implementation/RequestTrackingConstants.cs
internal static class RequestTrackingConstants
{
/// <summary>
/// Name of the HttpContext item containing RequestTelemetry object.
/// </summary>
internal const string RequestTelemetryItemName = "Microsoft.ApplicationInsights.RequestTelemetry";
internal const string EndRequestCallFlag = "Microsoft.ApplicationInsights.EndRequestCallFlag";
@debugthings
debugthings / Global.asax.cs
Created March 6, 2017 15:41
Disable Telemetry when build in DEBUG mode
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
#if DEBUG
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = true;
#endif
}
}