当前位置:网站首页>【應用程式見解 Application Insights】Application Insights 使用 Application Maps 構建請求鏈路檢視
【應用程式見解 Application Insights】Application Insights 使用 Application Maps 構建請求鏈路檢視
2020-11-06 21:13:26 【itread01】
Applicaotn Insigths 使用 Application Maps 構建請求鏈路檢視
構建系統時,請求的邏輯操作大多數情況下都需要在不同的服務,或介面中完成整個請求鏈路。一個請求可以經歷多個元件,極有可能出現客戶端請求站點1,站點1請求站點2, … 站點N才是最終處理資料然後依次返回。
在這樣的情況,如果有一個直觀的檢視來展示請求在每一個站點上的狀態(成功,失敗),當問題發生時,非常有幫助定位問題發生的地點。藉助Azure 應用程式見解(Application Insights)中的遙測關聯建立的Application Maps就能實現
效果展示
實現原理
Application Insights定義了用於分配遙測關聯的資料模型,每個傳出操作(例如,對另一個元件的 HTTP 呼叫)是由依賴項遙測表示的。 依賴項遙測也定義了自身的全域性獨一無二的 id,此依賴項呼叫發起的請求遙測將此 id 用作其 operation_parentId。通過operation_Id、operation_parentId 和 request.id,即可以生成分散式邏輯操作的檢視 (這些欄位也定義了遙測呼叫的因果關係順序)。
例項構建Application Maps
在例項中,這一個請求進行了4段轉發。
第一段:原生代碼訪問APIM(test01.azure-api.cn),
第二段:APIM訪問站點1(lbphptest.chinacloudsites.cn)
第三段:站點1訪問站點2(lbjavatest.chinacloudsites.cn)
第四段:站點2訪問最終處理請求的Azure Function(Http Trigger)( functionapp120201013155425.chinacloudsites.cn).
準備條件
- 建立Application Insights (lbphptest202011050549)
- 建立APIM(test01)
- 建立兩個App Service (lbphptest 和lbjavatest)
- 建立一個Azure Function(functionapp120201013155425)
注:如不熟悉如何建立以上資源,可以導航到文末的參考資料部分
步驟一:在Azure Funciton中啟用並關聯Application Insights服務
進入Azure Funciton門戶,選擇Application Insights功能,根據頁面提示選擇已建立好的Application Insights (lbphptest202011050549).
建立的Function為預設的HttpTrigger模式,測試目的,程式碼可以不需任何修改。參考下圖獲取到Function的URL,用於下一步在站點2中呼叫。
步驟二:在站點2(lbjavatest)中啟用並關聯Application Insights服務,並部署程式碼請求Azure Function
進入站點2的門戶頁面,在Application Insights目錄中根據提示Enable Application Insights並選擇相同的Application Insights。
部署程式碼呼叫步驟一中的Azure Function
//Level 3 [HttpGet] [Route("[Action]")] public string Fun([FromQuery] string name) { using (HttpClient httpClient = new HttpClient()) { var url = $"https://functionapp120201013155425.chinacloudsites.cn/api/HttpTrigger1?name={name}"; HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, url); httpRequest.Headers.Add("Accept", "application/json, text/plain, */*"); var response = httpClient.SendAsync(httpRequest).Result; string responseContent = response.Content.ReadAsStringAsync().Result; return responseContent; } }
步驟三:在站點1(lbphptest)中啟用並關聯Application Insights服務,並部署程式碼請求站點2
進入站點1的門戶頁面,在Application Insights目錄中根據提示Enable Application Insights並選擇相同的Application Insights。
部署程式碼呼叫步驟二中的站點2的URL,程式碼與訪問Azure Function相似。
//Level 2 [HttpGet] [Route("[Action]")] public string FunSub([FromQuery] string name) { using (HttpClient httpClient = new HttpClient()) { var url = $"https://lbjavatest.chinacloudsites.cn/WeatherForecast/fun?name={name}"; HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, url); httpRequest.Headers.Add("Accept", "application/json, text/plain, */*"); var response = httpClient.SendAsync(httpRequest).Result; string responseContent = response.Content.ReadAsStringAsync().Result; return responseContent; } }
步驟四:在APIM中啟用並關聯Application Insights服務, 並設定API訪問站點1
進入APIM的門戶頁面,在Application Insights目錄中新增相同的Application Insights。
在APIM配置API訪問站點1(lbphptest)
- 點選“Add API” 按鈕
- 選擇從App Service中建立
- 選擇站點1(lbphptest)
在介面中新增操作一個新操作,訪問站點1中的介面/weatherforecast/funsub?name={name}
步驟五:在ASP.NET Core程式碼中新增Application Insights SDK並配置連線字串,在介面中訪問APIM.
在原生代碼中新增Application Insights SDK
配置連線字串(字串中Application Insights的Overview頁面複製)
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "ApplicationInsights": { "ConnectionString": "InstrumentationKey=xxx-xxx-xxx-xxx-xxxxx;EndpointSuffix=applicationinsights.azure.cn;IngestionEndpoint=https://chinaeast2-0.in.applicationinsights.azure.cn/" }, "AllowedHosts": "*" }
啟動本地程式,並通過在瀏覽器中訪問 https://localhost:44323/weatherforecast/Funsubfornt?name=test from local -- apim -- app 1 – app 2 -- function
檢視最終效果圖:
【END】
參考文件:
在 Azure 門戶中建立第一個函式: https://docs.azure.cn/zh-cn/azure-functions/functions-create-first-azure-function
適用於 ASP.NET Core 應用程式的 Application Insights : https://docs.azure.cn/zh-cn/azure-monitor/app/asp-net-core
關於 API 管理: https://docs.azure.cn/zh-cn/api-management/api-management-key-concepts
在 Azure 中建立 ASP.NET Core Web 應用: https://docs.azure.cn/zh-cn/app-service/quickstart-dotnetcore?pivots=platform-linux
&n
版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
https://www.itread01.com/content/1604668025.html
边栏推荐
- C++ 数字、string和char*的转换
- C++学习——centos7上部署C++开发环境
- C++学习——一步步学会写Makefile
- C++学习——临时对象的产生与优化
- C++学习——对象的引用的用法
- C++编程经验(6):使用C++风格的类型转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
猜你喜欢
-
C + + programming experience (6): using C + + style type conversion
-
Latest party and government work report ppt - Park ppt
-
在线身份证号码提取生日工具
-
Online ID number extraction birthday tool
-
️野指针?悬空指针?️ 一文带你搞懂!
-
Field pointer? Dangling pointer? This article will help you understand!
-
HCNA Routing&Switching之GVRP
-
GVRP of hcna Routing & Switching
-
Seq2Seq实现闲聊机器人
-
【闲聊机器人】seq2seq模型的原理
随机推荐
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing&Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+#1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11:如何处理标定助手品质问题
- HALCON 20.11:标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- “十大科学技术问题”揭晓!|青年科学家50²论坛
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- 求反转链表
- Reverse linked list
- js的数据类型
- JS data type
- 记一次文件读写遇到的bug
- Remember the bug encountered in reading and writing a file
- 单例模式
- Singleton mode
- 在这个 N 多编程语言争霸的世界,C++ 究竟还有没有未来?
- In this world of N programming languages, is there a future for C + +?
- es6模板字符
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World