{"id":2250,"date":"2019-02-20T04:18:18","date_gmt":"2019-02-19T20:18:18","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/iotdev\/?p=2250"},"modified":"2019-02-23T01:58:40","modified_gmt":"2019-02-22T17:58:40","slug":"diagnose-issues-with-distributed-tracing-for-azure-iot-hub-preview-in-visual-studio-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/iotdev\/diagnose-issues-with-distributed-tracing-for-azure-iot-hub-preview-in-visual-studio-code\/","title":{"rendered":"Diagnose issues with Distributed Tracing for Azure IoT Hub (preview) in Visual Studio Code\u00a0"},"content":{"rendered":"<p>Effective monitoring is instrumental in understanding and troubleshooting your modern cloud solution leveraging multiple services. <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-monitor\/app\/distributed-tracing\">Distributed tracing<\/a> helps you diagnose issues in your cloud solution by providing the capability to track the flow of a call and the associated latency across these different services.<\/p>\n<p>Today, we announced the public preview of\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-monitor\/app\/distributed-tracing\">distributed tracing<\/a>\u00a0support in <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-hub\/\">Azure IoT Hub<\/a>. You can leverage the IoT Hub logs with\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-monitor\/app\/distributed-tracing\">distributed tracing<\/a> information to monitor the flow of messages through the IoT Hub and troubleshoot problems related to message loss or performance. You can further aggregate these logs to archive them in Blob storage, query the logs through Log Analytics and visualize the data flow in AppInsights as shown below.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2300\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/loganalytics-picture-300x113.jpg\" alt=\"\" width=\"508\" height=\"192\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/loganalytics-picture-300x113.jpg 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/loganalytics-picture-768x290.jpg 768w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/loganalytics-picture.jpg 849w\" sizes=\"(max-width: 508px) 100vw, 508px\" \/><img decoding=\"async\" class=\"alignnone size-medium wp-image-2301\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/appmap-pictures-300x225.jpg\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/appmap-pictures-300x225.jpg 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/appmap-pictures.jpg 457w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>You can now use VS code to enable diagnostics on a subset of your devices and choose the frequency of logging by setting a sampling rate of diagnostic logs per device\u00a0depending on your business needs. This post provides an outline to configure distributed tracing settings using VS Code. Try it today and let us know what you think.<\/p>\n<p><b>Before you begin<\/b><\/p>\n<p>Please take the following steps to ensure that you are ready to leverage distributed tracing.<\/p>\n<ol>\n<li>Ensure that you have the\u00a0Azure IoT\u00a0Hub\u00a0Toolkit\u00a0v2.x.x extension in VSCode. You can install the\u00a0<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-tools\">Azure IoT Tools<\/a>\u00a0to get this extension.<\/li>\n<li>Ensure that your devices have the latest<a href=\"https:\/\/github.com\/Azure\/azure-iot-sdk-c\/tree\/public-preview\"> device C SDK<\/a> and have the code updated to understand the distributed tracing settings. You can leverage the <a href=\"https:\/\/aka.ms\/csdksampleclientapp\">sample client application<\/a> code to make changes to your device SDK.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><b>Configure device to send diagnostic information<\/b><\/p>\n<p>After\u00a0setting up your devices with updated C SDK, now you can control distributed tracing from Visual Studio Code with the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-tools\">Azure IoT Tools<\/a> extension in VS Code.<\/p>\n<ol>\n<li>Expand \u201cAZURE IOT HUB DEVICES\u201d section inside Explorer, and follow the instructions to connect to your Azure IoT Hub.\n<img decoding=\"async\" class=\"alignnone size-medium wp-image-2251\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic1-300x72.png\" alt=\"\" width=\"300\" height=\"72\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic1-300x72.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic1.png 347w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><img decoding=\"async\" class=\"alignnone size-medium wp-image-2252\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic2-300x135.png\" alt=\"\" width=\"300\" height=\"135\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic2-300x135.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic2.png 521w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<li><span style=\"font-size: 1rem\">Create a device or expand an existing device, you can see there is a child node named \u201cDistributed Tracing Setting (Preview)\u201d\n<\/span><span style=\"font-size: 1rem\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-2285\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic3-withgreen-1-300x126.png\" alt=\"\" width=\"300\" height=\"126\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic3-withgreen-1-300x126.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic3-withgreen-1-768x322.png 768w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic3-withgreen-1.png 814w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/span><\/li>\n<li>Right click it and select \u201cUpdate Distributed Tracing Setting (Preview)\u201d\n<img decoding=\"async\" class=\"alignnone size-medium wp-image-2286\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic4-withgreen-1-300x114.png\" alt=\"\" width=\"300\" height=\"114\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic4-withgreen-1-300x114.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic4-withgreen-1-768x292.png 768w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic4-withgreen-1.png 936w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<li>Now you can enable\/disable distributed tracing and set the sampling rate<\/li>\n<li>After setting, you can expand \u201cDistributed Tracing Setting (Preview)\u201d node to see if desired property is set successfully:\n<img decoding=\"async\" class=\"alignnone size-medium wp-image-2287\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic5-1-279x300.png\" alt=\"\" width=\"279\" height=\"300\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic5-1-279x300.png 279w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic5-1-768x827.png 768w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic5-1-951x1024.png 951w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic5-1.png 1014w\" sizes=\"(max-width: 279px) 100vw, 279px\" \/><\/li>\n<li>If your device is connected to IoT Hub, you can monitor reported properties. Once this section is updated, it means your device gets and respects the distributed tracing setting you just set.\u00a0You can also right click\u00a0\u201cEnable Distributed Tracing\u201d and \u201cSampling Rate\u201d nodes under \u201cDesired\u201d to set them separately.\n<img decoding=\"async\" class=\"alignnone size-medium wp-image-2288\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic6-withgreen-300x206.png\" alt=\"\" width=\"300\" height=\"206\" srcset=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic6-withgreen-300x206.png 300w, https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2019\/02\/pic6-withgreen.png 722w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><b>Accessing the logs<\/b><\/p>\n<p>Once you have enabled distributed tracing on your devices, you can use the Azure portal to archive your logs to Azure storage, query in Log Analytics or visualize in\u00a0AppMap. More information about distributed tracing and ways to capture and analyze the logs can be found in our <a href=\"https:\/\/aka.ms\/iottracing\">documentation<\/a>.<\/p>\n<p>You can use\u00a0<a style=\"background-color: #f7f7f9;font-size: 1rem\" href=\"https:\/\/github.com\/Azure-Samples\/e2e-diagnostic-provision-cli\">this sample<\/a><span style=\"font-size: 1rem\">\u00a0to get started on\u00a0how you can configure and access the logs (and visualize the data) using AppInsights.<\/span><\/p>\n<p><strong>More useful resources on Azure IoT Hub<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/iotdev\/introducing-azure-iot-tools-for-visual-studio-code\/\">Azure IoT Tools for Visual Studio<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Microsoft\/vscode-azure-iot-toolkit\/wiki\">Wiki page of Azure IoT Hub Toolkit<\/a><\/li>\n<li><a href=\"https:\/\/channel9.msdn.com\/Shows\/Internet-of-Things-Show\/Whats-new-in-the-IoT-Toolkit-extension-for-VS-Code\">Channel 9 video: What&#8217;s new in the IoT Hub Toolkit extension for VS Code<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-hub\/iot-hub-vscode-iot-toolkit-cloud-device-messaging\">Use Azure IoT Hub Toolkit to send and receive messages between your device and IoT Hub<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-hub\/iot-hub-device-management-iot-toolkit\">Use Azure IoT Hub Toolkit for Azure IoT Hub device management<\/a><\/li>\n<li><a href=\"https:\/\/blogs.msdn.microsoft.com\/iotdev\/2018\/07\/12\/use-vs-code-as-iot-hub-device-simulator-say-hello-to-azure-iot-hub-in-5-minutes\/\">Use VS Code as IoT Hub Device Simulator<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Microsoft\/vscode-azure-iot-toolkit\/wiki\/Quickstart-Node.js\">Create and control an IoT device connected to an IoT hub (Node.js)<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Microsoft\/vscode-azure-iot-toolkit\/wiki\/Quickstart-.NET\">Create and control an IoT device connected to an IoT hub (.NET)<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Effective monitoring is instrumental in understanding and troubleshooting your modern cloud solution leveraging multiple services. Distributed tracing helps you diagnose issues in your cloud solution by providing the capability to track the flow of a call and the associated latency across these different services. Today, we announced the public preview of\u00a0distributed tracing\u00a0support in Azure IoT [&hellip;]<\/p>\n","protected":false},"author":838,"featured_media":2005,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[290,291],"tags":[7,293,292],"class_list":["post-2250","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-iot-hub","category-diagnostics","tag-azure-iot-hub","tag-diagnostics","tag-distributed-tracing"],"acf":[],"blog_post_summary":"<p>Effective monitoring is instrumental in understanding and troubleshooting your modern cloud solution leveraging multiple services. Distributed tracing helps you diagnose issues in your cloud solution by providing the capability to track the flow of a call and the associated latency across these different services. Today, we announced the public preview of\u00a0distributed tracing\u00a0support in Azure IoT [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts\/2250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/users\/838"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/comments?post=2250"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts\/2250\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/media\/2005"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/media?parent=2250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/categories?post=2250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/tags?post=2250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}