【Azure APIM】APIM Self-Hosted网关中,添加网关日志以记录请求头信息(Request Header / Response Header)

问题描述

在APIM Gateway 日志中, 对于发送到APIM Host的请求,只记录了一些常规的URL, Status, Time, IP等信息。关于请求Header, Body中的信息,因为隐私保护的原因,默认没有记录。

复制代码
[Info] 2023-11-16T06:19:28.482 [GatewayLogs], 
isRequestSuccess: True, 
totalTime: 2196,
category: GatewayLogs, 
callerIpAddress: xxx.xxx.xxx.xxx, 
timeGenerated: 2023-11-16T06:19:28.482, 
region: ChinaNorth3, 
correlationId:  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, 
method: GET, 
url: https://xxx.xxx.xxx.xxx/echo/resource?param1=sample,
backendResponseCode: 200, 
responseCode: 200, 
responseSize: 674, 
cache: none,
backendTime: 2004, 
apiId: echo-api, 
operationId: retrieve-resource, 
apimSubscriptionId: master, 
clientTime: 3, 
clientProtocol: HTTP/1.1, 
backendProtocol: HTTP/1.1, 
apiRevision: 1, 
clientTlsVersion: 1.2, 
backendMethod: GET, 
backendUrl: http://echoapi.cloudapp.net/api/resource?param1=sample, 
correlationId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
复制代码

那么,是否有办法增加日志内容,让Gateways日志中记录请求的Header,Body信息呢?


问题解答

当然可以,在APIM中,在配置APIs时,可以在Settings(设置)页面启用 Diagnostics Logs(诊断日志)来实现需求:

第一步:在APIs Diagnostics Logs中启用日志(Local 中的设置就是为自建网关(Self-hosted Gateway)适用)

 

第二步:启用后,进入 Self-hosted Gateway(如AKS POD), 就可以查看到上图配置的Name信息

 

 

参考资料 

诊断日志设置参考: https://docs.azure.cn/zh-cn/api-management/diagnostic-logs-reference

将自承载网关部署到 Kubernetes : https://docs.azure.cn/zh-cn/api-management/how-to-deploy-self-hosted-gateway-kubernetes

 

【END】

 

posted @   路边两盏灯  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2022-11-14 【Azure 服务总线】Azure.Messaging.ServiceBus 多次发送消息报超时错误,是否可以配置重新发送?是否有内置重试机制?
2021-11-14 【Azure 环境】用 PowerShell 调用 AAD Token, 以及调用Azure REST API(如资源组列表)
点击右上角即可分享
微信分享提示