<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pirmin Rehm on Medium]]></title>
        <description><![CDATA[Stories by Pirmin Rehm on Medium]]></description>
        <link>https://medium.com/@pirminmehr?source=rss-2e8a903bcd46------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5mP8qew0McziXxssvtE5_w.jpeg</url>
            <title>Stories by Pirmin Rehm on Medium</title>
            <link>https://medium.com/@pirminmehr?source=rss-2e8a903bcd46------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 01:46:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pirminmehr/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[3 Pitfalls of using Application Insights SDK for Node.js Azure Functions]]></title>
            <link>https://medium.com/@pirminmehr/3-pitfalls-of-using-application-insights-sdk-for-node-js-azure-functions-aab31bc3e3c0?source=rss-2e8a903bcd46------2</link>
            <guid isPermaLink="false">https://medium.com/p/aab31bc3e3c0</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[azure-app-insights]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[correlation]]></category>
            <dc:creator><![CDATA[Pirmin Rehm]]></dc:creator>
            <pubDate>Sun, 30 Jan 2022 09:04:02 GMT</pubDate>
            <atom:updated>2022-01-30T15:30:34.143Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZNY_6RzgDKftTsKnvDAugA.jpeg" /><figcaption>Screenshot of Application Insights “Transaction search”</figcaption></figure><p>To trace dependencies and for custom telemetry we decided to use the <a href="https://www.npmjs.com/package/applicationinsights">Application Insights SDK</a> in our Node.js Azure Function App. While some stuff is working out of the box, some glue code is necessary for the full experience. What three major pitfalls we discovered on our journey with App Insights, as well as some useful background knowledge, is described in the following.</p><h3>Clarification: App Insights with and without SDK</h3><p>You can monitor your Function App in three different ways:</p><ol><li>App Insights without SDK (runtime-based monitoring)</li><li>App Insights with SDK (runtime and code-based monitoring)</li><li>App Insights SDK only (code-based monitoring)</li></ol><p>In the further article I will focus on 2. App Insights with runtime and code-based monitoring. But first a more detailed look at the individual ways.</p><h4>App Insights without SDK (runtime-based monitoring)</h4><p>That’s a good way to start since the runtime is managing collection of data for you. Set either the instrumentation key <em>APPINSIGHTS_INSTRUMENTATIONKEY </em>or the connection string <em>APPLICATIONINSIGHTS_CONNECTION_STRING</em> as environment variable. Calls to your Functions will then be tracked as requests, whether executed via http binding or another one like the event binding. In addition, the runtime <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring#dependencies">collects data on the following dependencies</a>:</p><ul><li>Azure Cosmos DB</li><li>Azure Event Hubs</li><li>Azure Service Bus</li><li>Azure Storage services</li></ul><p>This is performed by the outer .NET runtime, which is also used by Node.js based Function Apps. In the JS code traces can be send via context.log(). Logs to the console are also stored as traces, too. You can modify the behavior of runtime-based monitoring via <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#sample-hostjson-file">hosts.json</a>.</p><h4>App Insights with SDK (runtime and code-based monitoring)</h4><p>Since not all dependencies are collected via runtime-based monitoring you can add code-based monitoring via the npm package “<a href="https://www.npmjs.com/package/applicationinsights">applicationinsights</a>”. If this SDK is enabled with default values, console logs are no longer send to App Insights as traces. The SDK can gather various custom telemetries, auto-collect exceptions and <a href="https://www.npmjs.com/package/diagnostic-channel-publishers">instrument further Node.js dependencies</a>:</p><ul><li>@azure/* <em>(latest, Currently Cognitive Search, Communication Common and Cosmos DB SDKs are not supported)</em></li><li>redis v2.x, v3.x</li><li>mysql v2.x</li><li>mongodb v2.x, v3.x</li><li>pg v6.x, v7.x, v8.x</li><li>pg-pool v1.x, v2.x</li><li>bunyan v1.x</li><li>winston v2.x, v3.x</li></ul><h4>App Insights SDK only (code-based monitoring)</h4><p>If you want to reduce the number of logs send to App Insights, especially to reduce costs, you may also run the SDK in standalone. Therefore, do not use the standard environment variables to pass the instrumentation key or connection string to the SDK. <a href="https://medium.com/u/a186fda9ed3d">Fabian Beyerlein</a> went deeper into this topic in his article “<a href="https://medium.com/@beyerleinf/azure-application-insights-how-not-to-burn-money-using-it-5f1bbe5816b4">Azure Application Insights — How not to burn money using it</a>”.</p><h3>Pitfall #1: RoleName and Instance is not populated correctly</h3><p>When we first set up the SKD, we noticed in App Insights that a strange new role was added, “Web”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DdiAht3eQJLW6tirEBp4pg.png" /></figure><p>It turned out that all the telemetry we were logging via the SDK was tagged with the wrong <em>RoleName</em>. To get this fixed, call <em>setAutoPopulateAzureProperties(true)</em> during the setup and the runtime will populate the correct values to the SDK:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a81adff7f7d157d1311d2fb693e59fa/href">https://medium.com/media/7a81adff7f7d157d1311d2fb693e59fa/href</a></iframe><h3>Pitfall #2: Custom Telemetry does not adopt the outer operationId for Correlation</h3><p>In Azure Functions correlation with the SDK is not working out of the box. Therefore, wrap the whole function call with the correlation context wrapper as shown below. Depending on how your functions are called, the context must be created a bit different. In my example you find a wrapper for http-based and timer- or event-based requests. Basic request telemetry is logged by the runtime-based monitoring, if you want to add more detailed information you can add this to the wrapper as shown in <a href="https://github.com/microsoft/ApplicationInsights-node.js#azure-functions-example">the official example</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2fb6b779701020cc170cde849b8040b/href">https://medium.com/media/b2fb6b779701020cc170cde849b8040b/href</a></iframe><h3>Pitfall #3: No correlation and wrong operationId for Dependencies</h3><p>Even with correlation wrapper we observed that some dependency calls, e.g. by <em>@azure/kevault-secret</em> or <em>@azure/app-configuration</em>, have a new <em>operationId</em>. It turned out that in some clumsy constellations the dependencies do not work correctly with each other. Central role plays the package <em>@azure/core-http</em> which is used by all <em>@azure/*</em> packages and which instrumentalizes <em>applicationinsights</em> for dependency tracing. If there is a dependency mismatch <em>@azure/core-http </em>may be installed multiple times with different versions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*-hC5QrxfcNOjs9z8FmW7RQ.png" /><figcaption>“npm list @azure/core-http” shows that there are multiple versions of the package installed (2.2.3 and 1.2.6)</figcaption></figure><p>In this case, <em>applicationinsights</em> may instrumentalizes the wrong package or will not work correctly due to incompatibilities. Updating everything to the latest version solved the issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*S_op4ocEmRinsvQStsHA5w.png" /><figcaption>“npm list @azure/core-http” shows that there is only one version of the package installed which is used by all dependent packages (2.2.3)</figcaption></figure><p>Consequently, we added a small pipeline script which is checking that only one version of @azure/core-http is installed in node_modules among the Function App.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe7cfe48fcbe1a9b7e5d81e0a63725b4/href">https://medium.com/media/fe7cfe48fcbe1a9b7e5d81e0a63725b4/href</a></iframe><h3>Conclusion</h3><p>Setting up everything correctly is sometimes tricky but possible. Remember to</p><ol><li>keep an eye on the dependencies</li><li>not forget to wrap code for telemetry correlation</li><li>populate runtime configuration during the setup</li></ol><p>Everything described in this article was successfully tested with Azure Functions 2.x on Node.js 14 and the Azure Extension Bundle 3.3 in January 2022.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aab31bc3e3c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing a simple Progress Bar with RxJS]]></title>
            <link>https://medium.com/@pirminmehr/implementing-a-simple-progress-bar-with-rxjs-4273594271d8?source=rss-2e8a903bcd46------2</link>
            <guid isPermaLink="false">https://medium.com/p/4273594271d8</guid>
            <category><![CDATA[progress-bar]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[rxjs]]></category>
            <dc:creator><![CDATA[Pirmin Rehm]]></dc:creator>
            <pubDate>Thu, 28 May 2020 23:04:08 GMT</pubDate>
            <atom:updated>2022-01-28T08:37:14.669Z</atom:updated>
            <content:encoded><![CDATA[<h4>Showing the current state of the application to users is one of the most important basics of usability. Therefore, you usually put in some nice spinners or skeletons. But if you are using lazy loading for modules in your SPA or even a micro front-end architecture you also must indicate the state of these post-loaded JS modules. But how to do this simple and nicely?</h4><p>One popular approach is the progress bar above the navigation. If you’re already using RxJS in your front-end application and you’ve got some subscribable states: Here is an easy solution without the need to add any other libraries or modules.</p><p>Edit 2022: Besides <a href="https://www.nngroup.com/articles/progress-indicators/">studies</a> that any feedback, weather fake or not, is better than no feedback, <a href="https://www.reddit.com/r/ProgrammerHumor/comments/s60to6/i_made_a_fake_progress_bar_to_shut_up_clients/">this empirical observation</a> is going viral on Reddit. The positive observation about a progress bar is based on the same principle as the example in this article: faking of progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EWa4XfdXkfFMexYKZC25Ug.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@saffu?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Saffu</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4>The Basics: HTML and CSS Styles</h4><p>Let’s keep it simple for this demo — if you need am more sophisticated solution feel free to adapt it. I’ll use two div elements — an outer one which marks the basic dimensions and an inner div whose width in percent is used as progress indicator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49f33806e338741d5d95c11f8e578412/href">https://medium.com/media/49f33806e338741d5d95c11f8e578412/href</a></iframe><p>The transition helps us to make a smooth sliding movement in the loader when updating the progress.</p><h4>Using Events to Update the Progress</h4><p>Let’s assume we have an RxJS event (Observable, Subject, …) which emits an object with the property “isNavigating: boolean”. Two main tasks can be derived from this event:</p><ol><li>If a navigation is in progress: update the progress bar</li><li>If there is no navigation: set the progress bar to 100%</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bb9b6020574d1ec49a9b91bd62d5b63/href">https://medium.com/media/4bb9b6020574d1ec49a9b91bd62d5b63/href</a></iframe><p>The general idea behind this loader is to not show the real progress of loading JS files from the server or similar, but to give the user the impression that something is going on here. Therefore, we start the progress bar at 0% and update the progress continuously until it reaches 80% by using an interval.</p><p>Our progress bar is optimistic which means: in the beginning the progress is fast and then slows down until it diverges at 80%. If you want another behavior, e.g. first slow then fast loading or to reach faster a diverging point, you must adapt the interval with the map function.</p><p>If your users have a fast connection the progress bar will go through in one movement. For slower connections it will increase more slowly and if it takes more than 10 seconds to load, it will stop at 80% progress.</p><h4>Using Angular Router as Event Source</h4><p>The Angular router provides an observable interface for routing events. We can use this for our progress bar as event source. In order to have the events in the format described above, we will filter and map the angular router events as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33cf3aee769f8d4a20e733a5123906b9/href">https://medium.com/media/33cf3aee769f8d4a20e733a5123906b9/href</a></iframe><h4>Conclusion</h4><p>With a few lines of RxJS, CSS and HTML you can easily code your own simple loading indicator. The map function gives you the freedom to customize the behavior of the loader, even dynamically. For front-end applications already using RxJS, as e.g. Angular, no extra libraries or packages are required.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Frxjs-loader-bar%3Fembed%3D1%26file%3Dindex.ts&amp;display_name=StackBlitz&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Frxjs-loader-bar%3Fembed%3D1%26file%3Dindex.ts&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/05b9dc1683480f53a9b78e7a0f354760/href">https://medium.com/media/05b9dc1683480f53a9b78e7a0f354760/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4273594271d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>