.netkubernetesazure-application-insights

What is the behaviour of the ServerTelemetryChannel when multiple processes are using the same StorageFolder in the same disk?


More specifically, I am talking about Kubernetes pods, running different instances of the same application. I haven't found official recommendations for that scenario.

Besides attaching a Persistent Volume, it feels like I need to also care about the race conditions.

I am sending Application Insights' Events and Metrics to be consumed by an orchestrator service, so I need them to be reliable. Should I expect that if I don't care about inter-processes race conditions, duplicates might appear?


Solution

  • ServerTelemetryChannel creates a subfolder in the storage folder for process isolation. It uses a hash of user identity, process name and application directory.

    // get unique sub directory
    var userName = platform.GetEnvironmentUserName();
    var processName = platform.GetCurrentProcessName();
    var applicationDirectory = platform.GetApplicationBaseDirectory();
    string subDirectory = HashHelper.GetSHA256Hash($"{instrumentationKey};{userName};{processName};{applicationDirectory}");
    

    In a case of running multiple pods pointing to the same shared volume it depends on whether process name includes pod name or not. If yes then it should be unique and results in no conflict.

    Update (April 24th, 2025): Confirmed with the team that above scenario (when all app instances use shared folder) is supported as well. In this case telemetry might be uploaded not by an instance it was emitted by. But it still will be uploaded (and without duplicates) and all race conditions are handled by SDK itself.