如何从连接字符串确定 Application Insights 实例?

Tre*_*ack 4 azure azure-application-insights

我有一个 Application Insights 连接字符串,并且想要找到访问 Azure 门户中的实例的方式,以便可以查看使用该连接字符串运行的应用程序的日志。我们在多个订阅、多个帐户中有许多 Application Insights 实例,这意味着我不能只单击每个实例并检查连接字符串是否匹配。

连接字符串看起来像InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://southcentralus.in.applicationinsights.azure.com/

有一个 URL,但该 URL 对于该区域中的所有实例都是通用的。唯一独特的是 InstrumentationKey。

我尝试登录门户并在搜索框中输入 InstrumentationKey,但没有找到任何帐户。

我运气不好吗?

sil*_*ent 5

您可以通过资源图查询来完成此操作,例如在 Azure CLI 中

az graph query -q "Resources | where type =~ 'Microsoft.Insights/components' | where properties['ConnectionString'] == 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://southcentralus.in.applicationinsights.azure.com/' | project id, resourceGroup, name"
Run Code Online (Sandbox Code Playgroud)

//编辑:正如 ZakiMa 评论中所建议的,更可靠的方法是检查 Instrumentation Key 属性:

az graph query -q "Resources | where type =~ 'Microsoft.Insights/components' | where 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://southcentralus.in.applicationinsights.azure.com/' contains properties['InstrumentationKey'] | project id, resourceGroup, name"
Run Code Online (Sandbox Code Playgroud)

  • 连接字符串可能会随着时间的推移而改变(例如,可以添加新端点)。更简化的方法是针对“instrumentationkey”属性执行此查询(并从连接字符串中获取它)。 (2认同)