地理位置和 IP 地址处理
本文会介绍 Application Insights 中的地理位置查找和 IP 地址处理的工作方式。
默认情况下,系统会暂时收集 IP 地址,而不会存储。
将遥测数据发送到 Azure 后,将使用 IP 地址进行地理位置查找。 结果用于填充字段 client_City
、client_StateOrProvince
以及 client_CountryOrRegion
。 然后放弃该地址,并将 0.0.0.0
写入 client_IP
字段。
遥测类型包括:
- 浏览器遥测:Application Insights 收集发送方的 IP 地址。 ingestion 终结点计算 IP 地址。
- 服务器遥测:在未设置
X-Forwarded-For
标头时,Application Insights 遥测模块会暂时收集客户端 IP 地址。 当传入 IP 地址列表具有多个 IP 地址时,最后一个 IP 地址用于填充地理位置字段。
此行为是有意设计的,目的是帮助避免对个人数据和 IP 地址位置信息进行不必要的收集。
如果未收集 IP 地址,也不会收集城市和其他地理位置属性。
若要启用 IP 收集和存储,必须将 Application Insights 组件的 DisableIpMasking
属性设置为 true
。
用于设置此属性的选项包括:
{
"id": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<resource-name>",
"name": "<resource-name>",
"type": "microsoft.insights/components",
"location": "chinaeast2",
"tags": {
},
"kind": "web",
"properties": {
"Application_Type": "web",
"Flow_Type": "Redfield",
"Request_Source": "IbizaAIExtension",
// ...
"DisableIpMasking": true
}
}
如果只需修改单个 Application Insights 资源的行为,请使用 Azure 门户。
转到 Application Insights 资源,然后选择“自动化”>“导出模板”。
选择“部署”。
选择“编辑模板”。
备注
上述屏幕截图中所显示的错误是可以解决的。 该错误表示:“资源组所在的位置不受模板中的一个或多个资源支持。” 请选择其他资源组。”暂时从下拉列表中选择其他资源组,然后重新选择原始资源组。
在 JSON 模板中,找到
resources
中的properties
。 在最后一个 JSON 字段添加一个逗号,然后添加以下新行:"DisableIpMasking": true
。 再选择“保存”。选择“查看 + 创建”>“创建”。
备注
如果看到“部署失败”,请查看部署详细信息,查找类型为
microsoft.insights/components
的部署详细信息,并检查状态。 如果成功,则部署对DisableIpMasking
做的更改。部署完成后,将会记录新的遥测数据。
如果再次选择并编辑模板,则仅显示默认模板,而不会显示新添加的属性。 如果看不到 IP 地址数据,并且想要确认
"DisableIpMasking": true
已设置,请运行以下 PowerShell 命令:# Replace `Fabrikam-dev` with the appropriate resource and resource group name. # Connect-AzAccount $AppInsights = Get-AzResource -Name 'Fabrikam-dev' -ResourceType 'microsoft.insights/components' -ResourceGroupName 'Fabrikam-dev' $AppInsights.Properties
最后返回一份属性列表。 其中一个属性显示为
DisableIpMasking: true
。 如果在使用 Azure 资源管理器部署新属性之前运行 PowerShell 命令,该属性将不存在。
以下 REST API 有效负载进行相同的修改:
PATCH https://management.chinacloudapi.cn/subscriptions/<sub-id>/resourceGroups/<rg-name>/providers/microsoft.insights/components/<resource-name>?api-version=2018-05-01-preview HTTP/1.1
Host: management.chinacloudapi.cn
Authorization: AUTH_TOKEN
Content-Type: application/json
Content-Length: 54
{
"location": "<resource location>",
"kind": "web",
"properties": {
"Application_Type": "web",
"DisableIpMasking": true
}
}
PowerShell Update-AzApplicationInsights
cmdlet 可以使用 DisableIPMasking
参数禁用 IP 掩码。
Update-AzApplicationInsights -Name "aiName" -ResourceGroupName "rgName" -DisableIPMasking:$true
有关 Update-AzApplicationInsights
cmdlet 的详细信息,请参阅 Update-AzApplicationInsights