Installing Azure App Service site extensions using Kudu API
In this brief article, we look at how to install Azure Function or Azure App Service “Site Extensions” directly using Kudu REST APIs.
Some Independent Software Vendors (ISVs) such as Datadog and Dynatrace package their monitoring agents as “site extensions” for Azure App Services.
Site extensions can be installed using ARM or Bicep template by including a resource of type Microsoft.Web/sites/extensions.
As of December 2022, it is possible that some small percentage of the ARM API invocations for installing the site extension returns a GatewayTimeout (504), Conflict (409), or BadRequest (400) errors causing the template deployment to fail.
These intermittent failures can happen if the extension installation process takes longer than 60 seconds or if there are multiple concurrent modification requests (PUT/POST/PATCH) that are executed on the same Microsoft.Web/site resource while the extension installation process is running.
For example, if you have a background process that is adding tags to all newly created resources and this process executes a PATCH operation to add tags to the newly created Microsoft.Web/site resource while Microsoft.Web/site/extensions request is still executing, this concurrent operation can cause the site extension process to be interrupted and fail.
Workaround
As a workaround, we can install the site extension directly using Kudu APIs instead of going through ARM (internally ARM uses the same Kudu APIs).
You can find the sample code for invoking Kudu APIs to install the site extension in this repo https://github.com/arsenvlad/azure-functions-siteextensions
Thank you!
Please leave feedback and questions below or at https://twitter.com/ArsenVlad