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
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?
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).
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
Cool. I will leave some more feedback here. (just disccussed some owin stuff here https://jabbr.net/#/rooms/owin) not sure if its easy to find again so will just summarize
I was playing with RemoteDependencyModule and on the azure portal the dependencies are not grouped under requests.
I believe this is a result of using
and
since the initializers are not getting the CallContext from the owin request. (its null for dependency telemetry).
I inspected the code for Web Extensions for WebOperationIdTelemetryInitializer and realized it uses HttpContext.Current to get the operationid (using system.web)
I dont want system.web into my application and at this point it do not seem like it's possible in any way to get the owin context and update the properties.
I havent been able to come up with an extension point that would make sense at this point for how to use the existing code. I am considering to do a simple owin middleware that logs dependencies in the same way that RemoteDependencyModule is getting them from ETW