6
votes

I'd like to know how I can get a unique identifier for the "slot instance" that an Azure App Service slot has loaded into it.

Note that I am not referring to the name of the slot.

For example:

  • My Azure App Service has two slots named "App" (Production) and "App-Staging" (Staging).
  • I then deploy version 1 of my project to the "App" slot.
  • I then deploy version 2 of my project to the "App-Staging" slot.
  • I then perform a Slot Swap operation from the Azure Portal:

    • Both instances of my app are running simultaneously (imagine they run in a container of some kind).
    • Both "containers" are immediately "detached" from their associated slot while still running.
    • Both "containers" are then immediately re-attached to the opposing slot.
      • i.e. version 1 stops receiving HTTP requests for app.azurewebsites.net and suddenly starts receiving requests for app-staging.azurewebsites.net.
      • and version 2 stops receiving HTTP requests for app-staging.azurewebsites.net and suddenly starts receiving requests for app.azurewebsites.net.
  • In order to investigate some issues I was having, I created a text file at D:\home\SlotName.txt. In the "App" slot I entered "SlotA" and in the "App-Staging" slot I entered "SlotB".

  • This SlotName.txt moves with the application instance, and allows my application to detect which filesystem or "container" instance it's living in - and this doesn't change when a slot-swap is performed.
  • I find this information essential when trying to uniquely identify deployments or when investigating logging continuity issues (as the staging slot won't be logging production data, for example).
  • However, my SlotName.txt file seems like a hack - but I can't see any information in the Environment Variables for my app's instance that reveals the same information.
    • Environment variables do reveal the slot name, e.g. "App" and "App-Staging" which is mutable - of course, but it doesn't uniquely identify the "container" or filesystem instance that the app is deployed into.

Here's the two Kudu Environment pages from the Production and Staging slots - notice that the values are either identical (like Machine name), slot-specific, or refer to the deployed application code and none of them refer to the filesystem / container instance they live in:

enter image description here

Is there any way to get this information without using my SlotName.txt trick?

2

2 Answers

3
votes

The answer hiding right under my nose - and different terminology.

What I was calling a "slot instance name" is actually referred to as a "Deployment Id" (I know this is an overloaded term as it's also used in the context of Azure's (now legacy) "Cloud Services" PaaS too).

This information is visible in the Kudu environment page and is also an exposed as an environment-variable: WEBSITE_DEPLOYMENT_ID.

The WEBSITE_DEPLOYMENT_ID value is of the form {SiteName}[__{Random}], with the __{Random} prefix omitted for the first deployment space.

If you look closely at the screenshot I posted, you'll notice the left-hand screenshot has the site-slot-name Site1__e928 whereas the right-hand screenshot is of the "first" slot-space and so its name is just Site1.

It is unfortunate that this information is not documented by Microsoft publicly - at least so far as Google can see (searching for the term right now yields zero useful relevant results):

Mystery solved!

0
votes

You have something called deployment slot setting values as shown in below image:

Attach a key-value pair in each slot with different value.

here
Here, this setting sticks to the specific app, even if you swap.
This can be trick you're looking for.

Source