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

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 【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

 

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
2天前
|
Java
日志框架log4j打印异常堆栈信息携带traceId,方便接口异常排查
日常项目运行日志,异常栈打印是不带traceId,导致排查问题查找异常栈很麻烦。
|
9天前
【Azure Policy】分享Policy实现对Azure Activity Log导出到Log A workspace中
在Policy Rule部分中,选择资源的类型为 "Microsoft.Resources/subscriptions", 效果使用 DeployIfNotExists (如果不存在,则通过修复任务进行修正。 在 existenceCondition 条件中,如果当前订阅已经启用了 diagnostic setting并且输出日志到同一个Log A workspace,表示满足Policy要求,不需要进行修正。 在 deployment 中,使用了 ARM 模板, 为订阅添加Diagnostic Setting并且所有的日志Category均启用。
|
20天前
【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode mode enabled Traces。它是什么意思呢?
【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode mode enabled Traces。它是什么意思呢?
|
20天前
|
存储 大数据 索引
【Azure Contianer Apps】在云上使用容器应用时收集日志遇见延迟问题
【Azure Contianer Apps】在云上使用容器应用时收集日志遇见延迟问题
|
20天前
【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大于1MB的文件的日志没有记录在Application Insights中
【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大于1MB的文件的日志没有记录在Application Insights中
|
20天前
|
网络安全
【Azure Service Bus】启用诊断日志来获取客户端访问Azure Service Bus的IP地址 [2024-03-26 实验结果失败]
【Azure Service Bus】启用诊断日志来获取客户端访问Azure Service Bus的IP地址 [2024-03-26 实验结果失败]
|
20天前
|
存储
【Azure Log A workspace】Azure上很多应用日志收集到Log A workspace后如何来分别各自的占比呢?
【Azure Log A workspace】Azure上很多应用日志收集到Log A workspace后如何来分别各自的占比呢?
|
20天前
|
存储 Kubernetes API
【APIM】Azure API Management Self-Host Gateway是否可以把请求的日志发送到Application Insights呢?让它和使用Azure上托管的 Gateway一样呢?
【APIM】Azure API Management Self-Host Gateway是否可以把请求的日志发送到Application Insights呢?让它和使用Azure上托管的 Gateway一样呢?
|
20天前
|
Kubernetes Ubuntu Windows
【Azure K8S | AKS】分享从AKS集群的Node中查看日志的方法(/var/log)
【Azure K8S | AKS】分享从AKS集群的Node中查看日志的方法(/var/log)
|
12天前
|
存储 监控 数据可视化
SLS 虽然不是直接使用 OSS 作为底层存储,但它凭借自身独特的存储架构和功能,为用户提供了一种专业、高效的日志服务解决方案。
【9月更文挑战第2天】SLS 虽然不是直接使用 OSS 作为底层存储,但它凭借自身独特的存储架构和功能,为用户提供了一种专业、高效的日志服务解决方案。
49 9