本文会介绍 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 地址数据
警告
默认值和建议不收集 IP 地址。 如果你替代此行为,请确保集合不会违反任何合规性要求或本地法规。
若要了解有关处理个人数据的详细信息,请参阅个人数据指南。
注意
启用 DisableIpMasking 属性之前引入的与遥测关联的 IP 地址继续显示为 0.0.0.0。 只有在此更改后引入的遥测反映实际 IP 地址信息。
若要启用 IP 收集和存储,必须将 Application Insights 组件的 DisableIpMasking 属性设置为 true。
如果使用 OpenTelemetry,则还可以通过设置 client.address span 属性来填充用于地理位置的请求 IP。 除非client_IP已启用,否则存储DisableIpMasking的值仍遵循本文中所述的掩码行为。 有关详细信息,请参阅 “设置用户 IP”。
注意
DisableIpMasking 适用于经典 Application Insights 数据引入。 通过原生 OTLP 路径(从 OTLP 终结点到数据收集终结点,再到数据收集规则,并存储在 ClientIP 和 0.0.0.0 表中)引入的遥测数据都会在 OTelSpans 中记录 OTelLogs,无论 DisableIpMasking 的值如何。 该 client.address 属性仍用于该路径上的地理位置查找,但地址本身不会保留。
禁用 IP 掩码
小提示
如果只需修改单个 Application Insights 资源的行为,请使用 Azure 门户。
转到 Application Insights 资源,然后选择自动化>导出模板。
选择“部署”。
选择“编辑模板”。
注意
如果遇到前一屏幕截图中显示的错误,则可以解决该错误。 它指出:“资源组位于模板中的一个或多个资源不支持的位置。 请选择其他资源组。暂时从下拉列表中选择其他资源组,然后重新选择原始资源组。
在 JSON 模板中,找到 properties 中的 resources。 在最后一个 JSON 字段添加一个逗号,然后添加以下新行:"DisableIpMasking": true。 再选择“保存”。
选择查看并创建>创建。
注意
如果看到“部署失败”,请查看部署详细信息,查找类型为 microsoft.insights/components 的部署详细信息,并检查状态。 如果部署成功,则表示已部署对 DisableIpMasking 所做的更改。
部署完成后,将会记录新的遥测数据。
如果再次选择并编辑模板,则仅显示没有新添加属性的默认模板。 如果未看到 IP 地址数据,请确认 "DisableIpMasking": true 是否已设置。
以下Azure PowerShell示例使用 Get-AzResource cmdlet。 它显示 Application Insights 资源属性。
# Set variables
$resourceGroupName = "<ResourceGroupName>"
$resourceName = "<ResourceName>"
# Define parameters for Get-AzResource
$getAzResourceParams = @{
Name = $resourceName
ResourceType = "Microsoft.Insights/components"
ResourceGroupName = $resourceGroupName
ExpandProperties = $true
}
# Retrieve the Application Insights resource and display its properties
$appInsights = Get-AzResource @getAzResourceParams
$appInsights.Properties
注意
Azure PowerShell cmdlet 使用当前 Az 上下文中的Azure 资源管理器终结点,因此无需在 cmdlet 语法中指定management.chinacloudapi.cn。
最后返回一份属性列表。 其中一个属性显示为 DisableIpMasking: true。 如果在使用 Azure 资源管理器部署新属性之前运行 PowerShell 命令,该属性将不存在。
以下 Azure CLI 示例使用 az rest 调用 Components - Create Or Update REST API 操作。 这是创建或更新请求,而不是部分更新。 包括需要在有效负载中保留的资源设置。
对于该 WorkspaceResourceId 属性,请使用 2020-02-02 API 版本。
# Set variables
resourceGroupName="<ResourceGroupName>"
resourceName="<ResourceName>"
apiVersion="<ApiVersion>"
# Get the subscription ID from the current Azure CLI context
subscriptionId=$(az account show --query id --output tsv)
# Build request URL
apiEndpoint="https://management.chinacloudapi.cn"
path="/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName"
provider="Microsoft.Insights/components/$resourceName"
queryString="?api-version=$apiVersion"
url="$apiEndpoint$path/providers/$provider$queryString"
# Disable IP masking on the Application Insights resource
az rest --method put --url "$url" --body @components.json
负载文件 components.json:
{
"location": "<AzureRegion>",
"kind": "web",
"properties": {
"Application_Type": "web",
"DisableIpMasking": true,
"WorkspaceResourceId": "/subscriptions/<SubscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.OperationalInsights/workspaces/<WorkspaceName>"
}
}
以下Azure PowerShell示例使用 Update-AzApplicationInsights cmdlet。 它使用 -DisableIPMasking 参数禁用 IP 掩码。
# Set variables
$resourceGroupName = "<ResourceGroupName>"
$resourceName = "<ResourceName>"
# Define parameters for Update-AzApplicationInsights
$updateAzApplicationInsightsParams = @{
ResourceGroupName = $resourceGroupName
Name = $resourceName
DisableIPMasking = $true
}
# Disable IP masking on the Application Insights resource
Update-AzApplicationInsights @updateAzApplicationInsightsParams
注意
Azure PowerShell cmdlet 使用当前 Az 上下文中的Azure 资源管理器终结点,因此无需在 cmdlet 语法中指定management.chinacloudapi.cn。
以下 REST 示例使用 Components - Create Or Update REST API 操作。 这是创建或更新请求,而不是部分更新。 包括需要在有效负载中保留的资源设置。
对于该 WorkspaceResourceId 属性,请使用 2020-02-02 API 版本。
PUT https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}?api-version={apiVersion}
Authorization: Bearer {accessToken}
Content-Type: application/json
{
"location": "<AzureRegion>",
"kind": "web",
"properties": {
"Application_Type": "web",
"DisableIpMasking": true,
"WorkspaceResourceId": "/subscriptions/<SubscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.OperationalInsights/workspaces/<WorkspaceName>"
}
}
注意
模板部署是创建或更新操作,而不是部分 PATCH 操作。 对于现有资源,请包含需要保留的设置。
以下Bicep示例使用Microsoft.Insights/components资源类型。 它通过将 true 设置为 DisableIpMasking 来禁用 IP 掩码。
在现有的 Microsoft.Insights/components 资源声明中,仅将 properties.DisableIpMasking 更改为 true。 此摘录属于内部 properties;它不是独立模板。 保留name、location、kind和tags,并保留所有其他properties成员,包括Application_Type、WorkspaceResourceId以及任何身份验证、保留、采样和网络访问设置。 将其他资源声明保留在完整的模板中。
DisableIpMasking: true
注意
模板部署是创建或更新操作,而不是部分 PATCH 操作。 对于现有资源,请包含需要保留的设置。
以下 ARM 模板示例使用 Microsoft.Insights/components 资源类型。 它通过将 true 设置为 DisableIpMasking 来禁用 IP 掩码。
在模板的Microsoft.Insights/components数组中的现有resources资源里,仅将properties.DisableIpMasking更改为true。 此对象显示一个成员 properties;它不是独立模板,也不是整个 properties 对象的替代对象。 保留name、location、kind和tags,并保留所有其他properties成员,包括Application_Type、WorkspaceResourceId以及任何身份验证、保留、采样和网络访问设置。 将其他条目保留在resources中。
{
"DisableIpMasking": true
}
后续步骤