如何通过Postman向Azure Application Insights发送日志消息?
通过Postman向Azure Application Insights发送日志消息的步骤
你不需要在创建Application Insights实例的API中配置日志属性,直接使用Application Insights Ingestion API即可发送日志,具体操作如下:
1. 获取凭据
登录Azure门户,找到你的Application Insights实例:
- 在「概述」页面复制Instrumentation Key(或推荐使用的Connection String)
2. 构造Postman请求
请求基本信息
- 方法:
POST - URL:
https://dc.services.visualstudio.com/v2/track(Azure中国区请用https://dc.applicationinsights.azure.cn/v2/track)
请求头
选择以下任意一种凭据方式设置请求头:
- 使用Instrumentation Key:
Content-Type: application/jsonAuthorization: InstrumentationKey=你的Instrumentation密钥
- 使用Connection String:
Content-Type: application/jsonx-ms-AI-ConnectionString: 你的Connection String
请求体(JSON格式)
替换其中的你的Instrumentation密钥和时间字段,发送一条简单的信息日志:
{ "name": "Microsoft.ApplicationInsights.你的Instrumentation密钥.Trace", "time": "2024-05-20T12:34:56.789Z", "iKey": "你的Instrumentation密钥", "tags": { "ai.cloud.role": "Postman测试", "ai.cloud.roleInstance": "Postman客户端" }, "data": { "baseType": "MessageData", "baseData": { "ver": 2, "message": "这是一条来自Postman的测试日志", "severityLevel": "Information" } } }
3. 验证日志
- 发送请求后,收到
200 OK响应即表示发送成功 - 登录Azure门户,进入该Application Insights实例的「日志」页面,运行查询:
即可查询到刚发送的日志内容traces | where message contains "测试日志"
内容的提问来源于stack exchange,提问作者Nandhini Packirisamy
相关产品推荐
相关产品推荐

