Last active
August 29, 2015 14:23
-
-
Save pksorensen/4858e5f3e54db62e8d1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } |
Author
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
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).