【APIM】Azure API Management Self-Host Gateway是否可以把请求的日志发送到Application Insights呢?让它和使用Azure上托管的 Gateway一样呢?

问题描述

Azure API Management Self-Host Gateway是否可以把请求的日志发送到Application Insights呢?让它和使用Azure上托管的 Gateway一样呢?

这是在APIM门户上配置API,设置的Diagnostics Logs,当选择Application Insights时,就可以把对接口请求时候所携带的Header/Body等信息发送到Applciation Insights中进行存储并分析。

但是,在自建网关在K8S中,确无法发送日志到Applicaiton Insights,有什么办法呢? 

 

问题解答

因为APIM Self-Host Gateway默认使用Application Insights的Endpoint ( https://dc.services.visualstudio.com/ ) 是Global Application Insights。而且在默认生产的YAML文件中,初始化并没有包含对Application Insights的设置项:

复制代码
# NOTE: Before deploying to a production environment, please review the documentation -> https://aka.ms/self-hosted-gateway-production
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: testselfhost-env
  labels:
    app: testselfhost
data:
  config.service.endpoint: "xxxxxxxxxx.configuration.azure-api.cn"
  neighborhood.host: "testselfhost-instance-discovery"
  runtime.deployment.artifact.source: "Azure Portal"
  runtime.deployment.mechanism: "YAML"
  runtime.deployment.orchestrator.type: "Kubernetes"
---
复制代码

所以如果需要发送请求日志到中国区指定的Application Insights中,需要修改YAML文件,在configMap中添加  logs.applicationinsights.endpoint: "https://dc.applicationinsights.azure.cn/v2/track"   效果如下图所示:

 

如上修改后,就能实现本地网关也发送数据到Appliation Insights中。

 

参考资料

如何将 Azure API 管理与 Azure Application Insights 集成:https://docs.azure.cn/zh-cn/api-management/api-management-howto-app-insights?tabs=rest#enable-application-insights-logging-for-your-api

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

 

posted @   路边两盏灯  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2022-03-19 【Azure 环境】IntelliJ IDEA Community Edition 2021.2.3登陆Azure账号时,无法切换到中国区
2022-03-19 【Azure 应用服务】App Service 的.NET Version选择为.NET6,是否可以同时支持运行ASP.NET V4.8的应用呢?
点击右上角即可分享
微信分享提示