Created
May 7, 2024 01:01
-
-
Save samuraitruong/93964d738bc1d22279262aaf1e9aadd5 to your computer and use it in GitHub Desktop.
telemetry
This file contains 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
using Microsoft.ApplicationInsights.Channel; | |
using Microsoft.ApplicationInsights.Extensibility; | |
using Microsoft.Extensions.DependencyInjection; | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// Add Application Insights telemetry | |
services.AddApplicationInsightsTelemetry(); | |
// Customize telemetry processor to exclude blob storage logs | |
services.AddSingleton<ITelemetryProcessorFactory>(provider => | |
{ | |
return new BlobStorageLogExclusionTelemetryProcessorFactory(); | |
}); | |
} | |
// Other configuration methods... | |
} | |
public class BlobStorageLogExclusionTelemetryProcessorFactory : ITelemetryProcessorFactory | |
{ | |
public ITelemetryProcessor Create(ITelemetryProcessor next) | |
{ | |
return new BlobStorageLogExclusionTelemetryProcessor(next); | |
} | |
} | |
public class BlobStorageLogExclusionTelemetryProcessor : ITelemetryProcessor | |
{ | |
private readonly ITelemetryProcessor _next; | |
public BlobStorageLogExclusionTelemetryProcessor(ITelemetryProcessor next) | |
{ | |
_next = next; | |
} | |
public void Process(ITelemetry item) | |
{ | |
// Exclude telemetry items related to blob storage logs based on your criteria | |
// Adjust the condition based on your specific requirements to identify and exclude blob storage logs | |
if (!(item is DependencyTelemetry dependencyTelemetry && | |
dependencyTelemetry.Type == "Azure blob" && | |
dependencyTelemetry.Target.Contains(".blob.core.windows.net") && | |
dependencyTelemetry.Data.Contains("your_specific_criteria_for_excluding_logs"))) | |
{ | |
// Pass telemetry items that are not related to blob storage logs to the next processor | |
_next.Process(item); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment