You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Functions集成Application Insights:无ADX权限时如何导出完整日志至Excel

无Azure Data Explorer权限时,导出Application Insights完整日志到Excel的方法

方法1:通过日志查询分批导出CSV后合并

Application Insights默认导出存在行数限制(通常约2000条),可通过拆分查询范围或分页查询分批导出,再合并到Excel:

  • 按时间范围拆分:进入Application Insights日志查询界面,编写针对目标表(如traces、requests)的查询,缩小时间范围(按天/小时划分),每次导出该时间段的数据为CSV。示例查询:
    traces 
    | where timestamp between (datetime(2024-05-01 00:00:00) .. datetime(2024-05-01 23:59:59))
    | project timestamp, message, severityLevel, operation_Id
    
    点击查询结果右上角的「导出」→「导出到CSV」,重复操作覆盖所有时间范围后,将所有CSV文件导入Excel合并。
  • 分页查询:使用offset和limit关键字实现分页,比如:
    第一页:
    traces | limit 2000
    
    第二页:
    traces | offset 2000 | limit 2000
    
    依次类推直到查询结果为空,再将所有导出的CSV合并到Excel。

方法2:用Excel Power Query直接连接Application Insights

利用Excel的Power Query功能对接Application Insights API,自动处理分页拉取完整数据:

  • 打开Excel,切换到「数据」选项卡,点击「获取数据」→「从其他来源」→「从Azure」→「从Azure Application Insights」。
  • 在弹出窗口中选择对应Azure订阅、资源组和Application Insights实例,点击「确定」。
  • 在Power Query编辑器中编写Kusto查询(或直接选择要加载的表),点击「关闭并上载」,数据会自动加载到Excel中,Power Query将自动处理API分页限制,拉取所有符合条件的数据。

方法3:用脚本批量导出(PowerShell示例)

通过脚本调用Application Insights日志API批量获取数据,保存为CSV后导入Excel:

# 配置参数
$resourceId = "/subscriptions/{你的订阅ID}/resourceGroups/{资源组名称}/providers/microsoft.insights/components/{Application Insights名称}"
$apiKey = "{你的Application Insights API密钥}" # 在AI的「API访问」中生成
$query = "traces | project timestamp, message, severityLevel"
$skip = 0
$pageSize = 2000
$allResults = @()

do {
    # 构建查询URL
    $url = "https://api.applicationinsights.io/v1/apps/$($resourceId.Split('/')[-1])/query?query=$([Uri]::EscapeDataString("$query | offset $skip | limit $pageSize"))"
    
    # 发送请求
    $response = Invoke-RestMethod -Uri $url -Headers @{"x-api-key" = $apiKey} -Method Get
    
    # 提取结果
    if ($response.tables.rows.Count -gt 0) {
        $allResults += $response.tables.rows
        $skip += $pageSize
    } else {
        break
    }
} while ($true)

# 导出到CSV
$allResults | Export-Csv -Path "AI_Logs.csv" -NoTypeInformation -Encoding UTF8

运行脚本后,将生成的CSV文件导入Excel即可。

内容的提问来源于stack exchange,提问作者Venkatesh N

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 21:05:23