本文会介绍 Application Insights 中的地理位置查找和 IP 地址处理的工作方式。
默认情况下,系统会暂时收集 IP 地址,而不会存储。
将遥测数据发送到 Azure 后,将使用 IP 地址进行地理位置查找。 结果用于填充字段 client_City
、client_StateOrProvince
以及 client_CountryOrRegion
。 然后放弃该地址,并将 0.0.0.0
写入 client_IP
字段。
遥测类型包括:
- 浏览器遥测:Application Insights 收集发送方的 IP 地址。 引入终结点计算 IP 地址。
- 服务器遥测:在未设置 标头时,Application Insights 遥测模块会暂时收集客户端 IP 地址
X-Forwarded-For
。 当传入 IP 地址列表具有多个 IP 地址时,最后一个 IP 地址用于填充地理位置字段。
此行为是有意设计的,目的是帮助避免对个人数据和 IP 地址位置信息进行不必要的收集。
如果未收集 IP 地址,也不会收集城市和其他地理位置属性。
警告
默认值和建议不收集 IP 地址。 如果你替代此行为,请确保集合不会违反任何合规性要求或本地法规。
若要了解有关处理个人数据的详细信息,请参阅个人数据指南。
注意
启用 DisableIpMasking
属性之前引入的与遥测关联的 IP 地址继续显示为 0.0.0.0
。 只有在此更改后引入的遥测反映实际 IP 地址信息。
若要启用 IP 收集和存储,必须将 Application Insights 组件的 DisableIpMasking
属性设置为 true
。
提示
如果只需修改单个 Application Insights 资源的行为,请使用 Azure 门户。
转到 Application Insights 资源,然后选择自动化>导出模板。
选择“部署”。
选择“编辑模板”。
注意
如果遇到前一屏幕截图中显示的错误,则可以解决该错误。 它指出:“资源组位于模板中的一个或多个资源不支持的位置。 请选择其他资源组。暂时从下拉列表中选择其他资源组,然后重新选择原始资源组。
在 JSON 模板中,找到 properties
中的 resources
。 在最后一个 JSON 字段添加一个逗号,然后添加以下新行:"DisableIpMasking": true
。 再选择“保存”。
选择查看并创建>创建。
注意
如果看到“部署失败”,请查看部署详细信息,查找类型为 microsoft.insights/components
的部署详细信息,并检查状态。 如果部署成功,则表示已部署对 DisableIpMasking
所做的更改。
部署完成后,将会记录新的遥测数据。
如果再次选择并编辑模板,则仅显示默认模板,而不会显示新添加的属性。 如果看不到 IP 地址数据,并且想要确认 "DisableIpMasking": true
已设置,请运行以下 PowerShell 命令:
# Replace <application-insights-resource-name> and <resource-group-name> with the appropriate resource and resource group name.
# Connect-AzAccount
$AppInsights = Get-AzResource -Name '<application-insights-resource-name>' -ResourceType 'microsoft.insights/components' -ResourceGroupName '<resource-group-name>'
$AppInsights.Properties
最后返回一份属性列表。 其中一个属性显示为 DisableIpMasking: true
。 如果在使用 Azure 资源管理器部署新属性之前运行 PowerShell 命令,该属性将不存在。
注意
目前,Azure 不提供通过 Azure CLI 为 Application Insights 禁用 IP 掩码的方法。 若要以编程方式禁用 IP 掩码,请使用 Azure PowerShell。
若要使用 Azure PowerShell 禁用 IP 掩码,请使用以下命令,并将占位符<application-insights-resource-name>
<resource-group-name>
替换为特定值:
Update-AzApplicationInsights -Name "<application-insights-resource-name>" -ResourceGroupName "<resource-group-name>" -DisableIPMasking:$true
有关 cmdlet 的详细信息 Update-AzApplicationInsights
,请参阅 Azure PowerShell 文档。
若要使用 REST API 禁用 IP 掩码,请使用以下请求,并将占位符 <subscription-id>
、 <resource-group-name>
、 <application-insights-resource-name>
、 <access-token>
以及 <azure-region-name>
替换为特定值:
PATCH https://management.chinacloudapi.cn/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>?api-version=2018-05-01-preview HTTP/1.1
Host: management.chinacloudapi.cn
Authorization: Bearer <access-token>
Content-Type: application/json
{
"location": "<azure-region-name>",
"kind": "web",
"properties": {
"Application_Type": "web",
"DisableIpMasking": true
}
}
有关使用 REST API 配置 Application Insights 资源的详细信息,请参阅 REST API 文档。
若要使用 Bicep 禁用 IP 掩码,请使用以下模板,并将占位符<application-insights-resource-name>
<azure-region-name>
替换为特定值:
resource appInsights 'microsoft.insights/components@2020-02-02' = {
name: '<application-insights-resource-name>'
location: '<azure-region-name>'
kind: 'web'
properties: {
Application_Type: 'web'
DisableIpMasking: true
}
}
若要使用 ARM(JSON)禁用 IP 掩码,请使用以下模板,并将占位符 <subscription-id>
、<resource-group-name>
、<application-insights-resource-name>
和 <azure-region-name>
替换为你的特定值:
{
"id": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<application-insights-resource-name>",
"name": "<application-insights-resource-name>",
"type": "microsoft.insights/components",
"location": "<azure-region-name>",
"kind": "web",
"properties": {
"Application_Type": "web",
"DisableIpMasking": true
}
}