Skip to content

Instantly share code, notes, and snippets.

@pksorensen
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save pksorensen/4858e5f3e54db62e8d1b to your computer and use it in GitHub Desktop.

Select an option

Save pksorensen/4858e5f3e54db62e8d1b to your computer and use it in GitHub Desktop.
public class DependencyFilterChannel : ITelemetryChannel, ISupportConfiguration
{
private PersistenceChannel channel;
public int SampleEvery { get; set; }
public DependencyFilterChannel()
{
this.channel = new PersistenceChannel();
}
public void Initialize(TelemetryConfiguration configuration)
{
this.channel.Initialize(configuration);
}
private PropertyInfo _property;
public static PropertyInfo GetNameProperty()
{
var type = Type.GetType("Microsoft.ApplicationInsights.DataContracts.RemoteDependencyTelemetry, Microsoft.ApplicationInsights");
return type.GetProperty("Name");
}
public void Send(ITelemetry item)
{
if (item.GetType().Name == "RemoteDependencyTelemetry")
{
LazyInitializer.EnsureInitialized(ref _property, GetNameProperty);
string name = _property.GetValue(item) as string;
//ignore these:https://ascendxyzdatastagingweu.blob.core.windows.net/0f0f36bcf00244ce8f7096c29076d4cb-test/_FHV2872.jpg?comp=block&blockid=YmxvY2stMDAwMDEx
try
{
var url = new UriBuilder(name);
if (url.Query.Contains("blockid") && url.Query.Contains("block"))
{
return;
}
}
catch (Exception)
{
}
}
else if(item is RequestTelemetry)
{
var requst = item as RequestTelemetry;
if (requst.Url.Query.Contains("blockid") && requst.Url.Query.Contains("block"))
{
return;
}
}
this.channel.Send(item);
}
public bool? DeveloperMode
{
get
{
return this.channel.DeveloperMode;
}
set
{
this.channel.DeveloperMode = value;
}
}
public string EndpointAddress
{
get
{
return this.channel.EndpointAddress;
}
set
{
this.channel.EndpointAddress = value;
}
}
public void Flush()
{
this.channel.Flush();
}
public void Dispose()
{
this.channel.Dispose();
}
}
@SergeyKanzhelev
Copy link

Yes, CallContext will not be saved across async/await. We are working on improving Dependency correlation to Requests and generic items correlation.

For RemoteDependencies - why wouldn't you just use Microsoft.ApplicationInsights.Extensibility.RuntimeTelemetry.RemoteDependencyModule?

@pksorensen
Copy link
Author

I would but its not able to correlate the dependencies with requests unless i use the package Microsoft.ApplicationInsights.Web to set the correlation id. (I dont want to use Microsoft.ApplicationInsights.Web as it pulls in system.web).

@pksorensen
Copy link
Author

For people dropping by and wondering about CallContext: Heres a small demo that shows how it works: https://gist.github.com/s093294/8a60759d9d29d2a33b8b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment