LogVersionInfo: a useful subfunction to include in your Azure Functions to record the version used every day (or other interval)

by Patrick Lee on 28 Jan 2023 in categories tech with tags AzureFunctions

When deploying code, it is important to be able to have an easy way to check that the deployment worked and that the version deployed is the one you published.  This is particularly important when deploying by swapping (e.g. from stage to production): in my experience, the swaps work about 98% of the time, but in about 2% of cases they fail e.g. due to a timeout.  When that happens, how do you know what is the state of your application? Did the swap succeed or not? It is very hard to 

You can do this for WebAPI by adding a GetNameAndVersionInfo method that can be called (and only needs to be protected by an APIKey rather than requiring a user to be logged in).

But what to do for Azure Functions? You could add a subfunction triggered by a web hook, but in order to have a record of different versions, I prefer to use a LogVersionInfo function triggered by a timer, normally daily.

You can also trigger it on demand (e.g. just after a deployment to check that the expected version has been deployed) by using the Code + Test section for the sub function in the Azure portal., and clicking the Test/Run link. (For some reason, you sometimes need to run it twice - another area where the Azure portal is a bit buggy that Microsoft should fix).