azure - 如何通过 Log Analytics API 访问 AppInsights 请求数据?

标签 azure azure-application-insights azure-log-analytics

我正在尝试通过 Log Analytics API 从我的 AppInsights 实例访问请求数据(自定义维度字段)。我可以通过选择 AppInsights 实例作为范围并按“请求”进行过滤,通过浏览器中的 Log Analytics UI 检索所需的数据。但是,当我尝试通过 API 按请求进行过滤时,我收到一条消息,指出 requests 是无效的表名称。

完整的错误消息是:

Failed to resolve table or column expression named 'requests'

我已将身份验证请求配置为成功检索 token ,如客户端凭据流程部分 here 中所述。 .

我的身份验证请求如下所示:

POST https://login.microsoftonline.com/<my-tenant-id>/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id=<app-client-id>
&resource=https://api.loganalytics.io
&client_secret=<app-client-secret>

我的查询请求如下所示:

POST https://api.loganalytics.io/v1/workspaces/<my-workspace-id>/query?timespan=P1D
Content-Type: application/json
Authorization: Bearer <token>

Body:
{
    "query": "requests | where success == false "
}

返回结果:

{
    "error": {
        "message": "The request had some invalid properties",
        "code": "BadArgumentError",
        "correlationId": "",
        "innererror": {
            "code": "SemanticError",
            "message": "A semantic error occurred.",
            "innererror": {
                "code": "SEM0100",
                "message": "'where' operator: Failed to resolve table or column expression named 'requests'"
            }
        }
    }
}

选择 App Insights 实例作为查询范围后,上述查询将按照 Log Analytics UI 的预期运行。

是否可以在 Log Analytics API 请求中指定查询的范围/资源组?我试图找到详细信息herehere但没有提及范围。如有任何帮助,我们将不胜感激。

最佳答案

我发现了,我在查询中使用了不正确的语法。

下面的语法给了我我所期望的结果,而无需指定范围:

{
    "query": "AppRequests | where Name has '<request-name>' | project Name, Properties"
}

关于azure - 如何通过 Log Analytics API 访问 AppInsights 请求数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75006732/

相关文章:

azure - 服务总线代理 VS 中继消息传递

azure - 无法从应用程序见解导出完整日志信息

azure - 在应用程序见解中禁用另存为查询

Azure Log Analytics - 如何查看最近 x 天但仅在特定时间之间的日志?

Azure Web 应用程序应用程序见解查询一段时间内的操作/依赖时间、持续时间和计数

azure - 在 Azure 中禁用更改跟踪

c# - 使用 C# 创建 Azure DataDisk

使用 python 读取 jpg 时出现 Azure blob UnicodeDecodeError

azure 应用程序设置-如何添加嵌套项目

javascript - 在 Application Insights 中使用 startTrackPage