Find Azure Application Insights by instrumentation key
In our team we where used to configure multiple Application Insights in our ASPNET Core applications, but some times it was not easy to find the resource name related to an instrumentation key. We where losing thime searching for the names manualy. In order to avoid this waste, we decided to generate an script based in the Azure Cli.
To run this automatism, first you need to install the resource-graph extension:
az extension add --name resource-graph
Then, you can run the resource graph query script parametrizing the InstrumentationKey
, for example 00000000-aaaa-bbbb-cccc-dddddddddddd
:
az graph query -q "Resources
| where type =~ 'microsoft.insights/components'
| where properties.InstrumentationKey =~ '00000000-aaaa-bbbb-cccc-dddddddddddd'
| project name, properties.InstrumentationKey "
You will get the resource name that match that with that key.
Notes:
- Make sure you are using the right subscription.
- Make sure you write the whole script in a single line.