Context : Log external activities to Application Insights in an Azure Function v2.
There is no "built-in" way to customize the DependencyTrackingTelemetryModule class configuration.
By default the DependencyTrackingTelemetryModule class is only configured to track the "Microsoft.Azure.ServiceBus" diagnostic source activies, while it could also handle the "Microsoft.Azure.EventHubs" diagnostic source.
In my case, I want to log both ServiceBus and EventHub activities.
I had to change the DependencyTrackingTelemetryModule class instanciation with a new one :
ServiceDescriptor serviceDescriptorToDelete = null;
var serviceDescriptors = serviceCollection.Where(s => s.ServiceType == typeof(ITelemetryModule)).ToList();
foreach (var service in serviceDescriptors)
{
if (service.ImplementationFactory != null &&
service.ImplementationFactory.Method.ReturnType == typeof(DependencyTrackingTelemetryModule))
{
serviceDescriptorToDelete = service;
}
}
if (serviceDescriptorToDelete != null)
{
serviceCollection.Remove(serviceDescriptorToDelete);
}
serviceCollection.AddSingleton<ITelemetryModule, DependencyTrackingTelemetryModule>(provider =>
{
var dependencyCollector = new DependencyTrackingTelemetryModule();
var excludedDomains = dependencyCollector.ExcludeComponentCorrelationHttpHeadersOnDomains;
excludedDomains.Add("core.windows.net");
excludedDomains.Add("core.chinacloudapi.cn");
excludedDomains.Add("core.cloudapi.de");
excludedDomains.Add("core.usgovcloudapi.net");
excludedDomains.Add("localhost");
excludedDomains.Add("127.0.0.1");
var includedActivities = dependencyCollector.IncludeDiagnosticSourceActivities;
includedActivities.Add("Microsoft.Azure.ServiceBus");
includedActivities.Add("Microsoft.Azure.EventHubs"); // <- Change here
return dependencyCollector;
});
Are there any reasons for excluding the "Microsoft.Azure.EventHubs" diagnostics sources ?
Is there a better way to implement this behavior ?
Context : Log external activities to Application Insights in an Azure Function v2.
There is no "built-in" way to customize the DependencyTrackingTelemetryModule class configuration.
By default the DependencyTrackingTelemetryModule class is only configured to track the "Microsoft.Azure.ServiceBus" diagnostic source activies, while it could also handle the "Microsoft.Azure.EventHubs" diagnostic source.
In my case, I want to log both ServiceBus and EventHub activities.
I had to change the DependencyTrackingTelemetryModule class instanciation with a new one :
Are there any reasons for excluding the "Microsoft.Azure.EventHubs" diagnostics sources ?
Is there a better way to implement this behavior ?
Thanks,
Romain