0
votes

I have a .NET Core web app which is sending some custom events telemetry to Application Insights. The custom events are sent using telemetry client instace, e.g. like that:

  telemetryClient.TrackEvent(Names.FileDownload, new Dictionary<string, string>()
            {
                {PropertyKeys.ProjectName, project.ProjectName},
                {PropertyKeys.ProjectUri, project.ProjectUri},
                {PropertyKeys.IsLocal, isLocal.ToString() },
                {PropertyKeys.FileSize, fileSize?.ToString() },
            });

Most of the data events that occur are in massive numbers and I don't care about all of them, so I have set up sampling to 50%.

However, I have one or two events that occur very infrequently, and for those I want each occurrence to be tracked.

With sampling enabled, I see that this crucial event is almost never stored. When I disable the sampling, it starts to work.

Is it possible to somehow exclude certain telemetry items from being filtered by sampling?

Regards,
Bartosz

1
what's kind of the web app? .net core or .net framework or others? - Ivan Yang
@IvanYang - .NET Core - Bartosz

1 Answers

1
votes

Yes, it is possible. You can write a custom TelemetryInitializer, which sets the SamplingPercentage to 100 on the telemetry item you want retained.

Here is the sample code:

public class MyTelemetryInitializer : ITelemetryInitializer
{
    public void Initialize(ITelemetry telemetry)
    {
        #write your own logic for somecondition
        if(somecondition)
        {
            ((ISupportSampling)telemetry).SamplingPercentage = 100;
        }
    }
}

For more details, please refer to this article, in section "There are certain rare events I always want to see. How can I get them past the sampling module?".