我正在尝试通过 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 请求中指定查询的范围/资源组?我试图找到详细信息here和 here但没有提及范围。如有任何帮助,我们将不胜感激。
最佳答案
我发现了,我在查询中使用了不正确的语法。
下面的语法给了我我所期望的结果,而无需指定范围:
{
"query": "AppRequests | where Name has '<request-name>' | project Name, Properties"
}
关于azure - 如何通过 Log Analytics API 访问 AppInsights 请求数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75006732/