<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Microsoft Azure &#8212; onthecode</title>
	<atom:link href="https://onthecode.co.uk/blog/category/microsoft-azure/feed" rel="self" type="application/rss+xml" />
	<link>https://onthecode.co.uk/blog/category/microsoft-azure</link>
	<description>onthecode blog</description>
	<lastBuildDate>Fri, 30 Dec 2022 00:31:43 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://onthecode.co.uk/wp-content/uploads/2019/02/onthecode-icon-1-100x100.png</url>
	<title>Microsoft Azure &#8212; onthecode</title>
	<link>https://onthecode.co.uk/blog/category/microsoft-azure</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>AZ-900 Exam Practice Questions with Answers</title>
		<link>https://onthecode.co.uk/blog/az-900-exam-practice-questions-with-answers</link>
					<comments>https://onthecode.co.uk/blog/az-900-exam-practice-questions-with-answers#respond</comments>
		
		<dc:creator><![CDATA[Umut Esen]]></dc:creator>
		<pubDate>Mon, 20 Jun 2022 09:57:15 +0000</pubDate>
				<category><![CDATA[Microsoft Azure]]></category>
		<guid isPermaLink="false">https://onthecode.co.uk/?p=4681</guid>

					<description><![CDATA[<p>This is a list of practice questions for Microsoft Azure Fundamentals (AZ-900) exam with answers. Question You need to deploy a serverless solution that meets the following requirements: Execution is triggered through an HTTP request. You pay only for the time that your code runs. You do not have to manage the application infrastructure. Which Azure service should you use? You should use Azure Functions. This is a serverless platform that lets you execute your code when needed and pay for the actual runtime only, without worrying about configuration or management of the underlying physical and application infrastructure. Azure Functions can be triggered by various event types, including HTTP requests. Question Your company plans to migrate applications and services to the cloud. You recommend for a hybrid cloud to be deployed. Why would you make this recommendation? To augment on-premises resources by providing overflow capacity By implementing a hybrid cloud, your company can augment on-premises resources by providing overflow capacity. A hybrid cloud is the combination of two or more cloud models, such as public and private, and provides benefits from both models. It can give businesses the flexibility to use public cloud resources when they need them, while also keeping sensitive data and applications on-premises in a private cloud. A hybrid cloud can also help organizations manage peaks and valleys in traffic more efficiently. By using a hybrid cloud model, businesses do not have to overprovision computing resources in anticipation of high demand; they can simply bring in extra resources from the public cloud when they need them. Question Your company has a new policy to restrict administrative access to resources at the resource group and resource scopes in a detailed, granular way. Access will be granted to various groups and individual users. You need to implement the new policy. What should you use? Role-based access control (RBAC) You should use RBAC. RBAC supports various scopes, including management groups, subscriptions, resource groups, and resources. Roles can be assigned to groups, users, other security principals, and managed identifies. RBAC has over 70 built-in roles and supports the creation and assignment of custom roles. Question Which Azure solution should you use to build a baseline behavioural profile of organisational entities to identify anomalous activity? Microsoft Sentinel Microsoft Sentinel is a security information and event manager (SIEM) platform that can analyze data across the enterprise to identify potential threats, including anomalous activities of users or applications, and help with a faster and smarter response. Question What is Azure Virtual Desktop (AVD)? Azure Virtual Desktop (AVD) supports Remote Desktop clients on MacOS and iOS. Other supported platforms include Windows Desktop, Web, Android, and Microsoft Store Client. You are not charged for the use of AVD on a monthly basis accordingly by active users. AVD is a service that does not require any additional licenses. You can use it with your existing Microsoft 365 or Windows per-user license. However, you are charged for the virtual machines where AVD runs. AVD users should exist in the same Windows Server AD that is linked to Azure AD. AVD does not support the use of Microsoft accounts or Azure AD B2B when users are sourced from a separate Azure AD tenant. Question Which three authentication types are supported by both SSPR and MFA? The authentication types supported by both SSPR and MFA are: Password SMS Voice call Question What is Azure Dedicated Hosts? A provided physical server is dedicated to your organization’s workload only. Azure Dedicated Hosts are isolated physical servers where you run your organization&#8217;s workload only. They are not shared with any other Azure customers to meet corporate compliance guidelines and standards. You cannot share provided physical servers across your multiple Azure subscriptions. The underlying physical hosts are single-tenant, so they are dedicated to one Azure subscription only. You are not charged per number of VMs deployed. Azure Dedicated Hosts are charged per dedicated host, regardless of how many VMs you run on the host. Question You need to ensure consistent performance for users who access your application, which runs on customised Linux virtual machines. What should you use to provision virtual machines automatically? You should use scale sets to provision virtual machines automatically. An Azure virtual machine scale set is a group of identical, autoscaling virtual machines in the Azure cloud. Virtual machine&#160;scale sets allow you to easily deploy and manage a large number of virtual machines as a single unit, making them ideal for scalable workloads like web servers, application servers, and batch processing jobs. You can create your own virtual machine&#160;scale sets from scratch or use pre-configured ones from the Azure Marketplace. Question What is a management group? Management groups let you organize multiple subscriptions as a single management entity to facilitate easier management. You can create managements groups in a hierarchical structure with the top level of the hierarchy at the tenant level and all of the subscriptions are contained in that tenant. Any conditions applied to a management group apply to all subscriptions contained in that management group object. Question Your company wants to ensure that it meets its internal compliance goals and that Azure resources are compliant with company standards. This will include ongoing evaluation for compliance and the identification of non-compliant resources. You need to recommend a solution. What should you use? You should use Azure Policy. Azure Policy lets a company enforce rules that apply to resources to help ensure compliance with company standards. Policies can also be used to ensure that resources meet service level agreement (SLA) requirements. Resources are evaluated based on policies and non-compliant resources are identified. Question What can Application Security Groups help you do? ASGs let you organize similar servers so you can easily define and implement security policies based on those groups. ASGs let you apply security to the group as a whole.</p>
<p>The post <a href="https://onthecode.co.uk/blog/az-900-exam-practice-questions-with-answers">AZ-900 Exam Practice Questions with Answers</a> appeared first on <a href="https://onthecode.co.uk">onthecode</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This is a list of practice questions for Microsoft Azure Fundamentals (AZ-900) exam with answers. </p>



<h2 class="wp-block-heading">Question</h2>



<p>You need to deploy a serverless solution that meets the following requirements:</p>



<ul class="wp-block-list"><li>Execution is triggered through an HTTP request.</li><li>You pay only for the time that your code runs.</li><li>You do not have to manage the application infrastructure.</li></ul>



<p>Which Azure service should you use?</p>



<p>You should use Azure Functions. This is a serverless platform that lets you execute your code when needed and pay for the actual runtime only, without worrying about configuration or management of the underlying physical and application infrastructure. Azure Functions can be triggered by various event types, including HTTP requests.</p>



<h2 class="wp-block-heading">Question</h2>



<p>Your company plans to migrate applications and services to the cloud. You recommend for a hybrid cloud to be deployed. Why would you make this recommendation?</p>



<p>To augment on-premises resources by providing overflow capacity</p>



<p>By implementing a hybrid cloud, your company can augment on-premises resources by providing overflow capacity. A hybrid cloud is the combination of two or more cloud models, such as public and private, and provides benefits from both models. It can give businesses the flexibility to use public cloud resources when they need them, while also keeping sensitive data and applications on-premises in a private cloud. A hybrid cloud can also help organizations manage peaks and valleys in traffic more efficiently. By using a hybrid cloud model, businesses do not have to overprovision computing resources in anticipation of high demand; they can simply bring in extra resources from the public cloud when they need them.</p>



<h2 class="wp-block-heading">Question</h2>



<p>Your company has a new policy to restrict administrative access to resources at the resource group and resource scopes in a detailed, granular way. Access will be granted to various groups and individual users. You need to implement the new policy. What should you use?</p>



<p>Role-based access control (RBAC)</p>



<p>You should use RBAC. RBAC supports various scopes, including management groups, subscriptions, resource groups, and resources. Roles can be assigned to groups, users, other security principals, and managed identifies. RBAC has over 70 built-in roles and supports the creation and assignment of custom roles.</p>



<h2 class="wp-block-heading">Question</h2>



<p>Which Azure solution should you use to build a baseline behavioural profile of organisational entities to identify anomalous activity?</p>



<p>Microsoft Sentinel</p>



<p>Microsoft Sentinel is a security information and event manager (SIEM) platform that can analyze data across the enterprise to identify potential threats, including anomalous activities of users or applications, and help with a faster and smarter response.</p>



<h2 class="wp-block-heading">Question</h2>



<p>What is Azure Virtual Desktop (AVD)?</p>



<p>Azure Virtual Desktop (AVD) supports Remote Desktop clients on MacOS and iOS. Other supported platforms include Windows Desktop, Web, Android, and Microsoft Store Client.<br><br>You are not charged for the use of AVD on a monthly basis accordingly by active users. AVD is a service that does not require any additional licenses. You can use it with your existing Microsoft 365 or Windows per-user license. However, you are charged for the virtual machines where AVD runs.<br><br>AVD users should exist in the same Windows Server AD that is linked to Azure AD. AVD does not support the use of Microsoft accounts or Azure AD B2B when users are sourced from a separate Azure AD tenant.</p>



<h2 class="wp-block-heading">Question</h2>



<p>Which three authentication types are supported by both SSPR and MFA?</p>



<p>The authentication types supported by both SSPR and MFA are:</p>



<ul class="wp-block-list"><li>Password</li><li>SMS</li><li>Voice call</li></ul>



<h2 class="wp-block-heading">Question</h2>



<p>What is Azure Dedicated Hosts?</p>



<p>A provided physical server is dedicated to your organization’s workload only. Azure Dedicated Hosts are isolated physical servers where you run your organization&#8217;s workload only. They are not shared with any other Azure customers to meet corporate compliance guidelines and standards.</p>



<p>You cannot share provided physical servers across your multiple Azure subscriptions. The underlying physical hosts are single-tenant, so they are dedicated to one Azure subscription only.</p>



<p>You are not charged per number of VMs deployed. Azure Dedicated Hosts are charged per dedicated host, regardless of how many VMs you run on the host.</p>



<h2 class="wp-block-heading">Question</h2>



<p>You need to ensure consistent performance for users who access your application, which runs on customised Linux virtual machines. What should you use to provision virtual machines automatically?</p>



<p>You should use scale sets to provision virtual machines automatically. An Azure virtual machine scale set is a group of identical, autoscaling virtual machines in the Azure cloud. Virtual machine&nbsp;scale sets allow you to easily deploy and manage a large number of virtual machines as a single unit, making them ideal for scalable workloads like web servers, application servers, and batch processing jobs. You can create your own virtual machine&nbsp;scale sets from scratch or use pre-configured ones from the Azure Marketplace.</p>



<h2 class="wp-block-heading">Question</h2>



<p>What is a management group?</p>



<p>Management groups let you organize multiple subscriptions as a single management entity to facilitate easier management. You can create managements groups in a hierarchical structure with the top level of the hierarchy at the tenant level and all of the subscriptions are contained in that tenant. Any conditions applied to a management group apply to all subscriptions contained in that management group object.</p>



<h2 class="wp-block-heading">Question</h2>



<p>Your company wants to ensure that it meets its internal compliance goals and that Azure resources are compliant with company standards. This will include ongoing evaluation for compliance and the identification of non-compliant resources. You need to recommend a solution.</p>



<p>What should you use?</p>



<p>You should use Azure Policy. Azure Policy lets a company enforce rules that apply to resources to help ensure compliance with company standards. Policies can also be used to ensure that resources meet service level agreement (SLA) requirements. Resources are evaluated based on policies and non-compliant resources are identified.</p>



<h2 class="wp-block-heading">Question</h2>



<p>What can Application Security Groups help you do?</p>



<p>ASGs let you organize similar servers so you can easily define and implement security policies based on those groups. ASGs let you apply security to the group as a whole.</p>
<p>The post <a href="https://onthecode.co.uk/blog/az-900-exam-practice-questions-with-answers">AZ-900 Exam Practice Questions with Answers</a> appeared first on <a href="https://onthecode.co.uk">onthecode</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://onthecode.co.uk/blog/az-900-exam-practice-questions-with-answers/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Monitoring Live Angular Apps with Application Insights</title>
		<link>https://onthecode.co.uk/blog/monitoring-live-angular-apps-with-azure-application-insights</link>
					<comments>https://onthecode.co.uk/blog/monitoring-live-angular-apps-with-azure-application-insights#comments</comments>
		
		<dc:creator><![CDATA[Umut Esen]]></dc:creator>
		<pubDate>Thu, 19 Sep 2019 19:25:58 +0000</pubDate>
				<category><![CDATA[Angular]]></category>
		<category><![CDATA[Microsoft Azure]]></category>
		<category><![CDATA[angular 8]]></category>
		<category><![CDATA[angular logging]]></category>
		<category><![CDATA[application insights]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[typescript]]></category>
		<guid isPermaLink="false">https://onthecode.co.uk/?p=2870</guid>

					<description><![CDATA[<p>In this post, I will explain how you can monitor Angular apps using Microsoft Azure Application Insights. It is not unusual for organisations to ignore monitoring single page applications. Usually, back-end applications such as APIs are monitored via logs, CPU and memory usage. When it comes to front-end, there is usually not much in the way of monitoring. Getting started with Application Insights First of all, create your free Azure account here. Head over to the portal to create a new resource. Search for &#8216;application insights&#8217; and click Create. It will take some time (usually a few seconds) to create the new Application Insights resource. Then, navigate to the resource and find your Instrumentation Key from the right hand side of the screen. The instrumentation key uniquely identifies the resource you created on Azure. You can use this key with as many components as you wish, including APIs and front end apps. Install npm package Install the official package to your Angular application: This package includes all everything you need to start monitoring your Angular app. Configure Application Insights Initialise application insights in the root module of your app. If you have a core module, initialise it there. Please import classes from @microsoft/applicationinsights-web namespace. The factory method creates an instance of ApplicationInsights client. In addition, it sets the instrumentation key from Angular environment variables. This instance is a singleton, which helps us avoid duplicate telemetry collection. Setting enableCorsCorrelation to true adds custom headers to each and every request issued by Angular application. These headers are used on the server to correlate requests end to end. If your server has a CORS configuration, be sure to allow the following headers: The great thing about App Insights is that all telemetry is buffered and automatically sent to the Azure Portal when the user session ends i.e. browser tab is closed. This is especially useful in production environment as it does not impact user experience. However, it can be annoying in development as you may need to wait or reload page to see data in the portal. That&#8217;s why I configure it above to immediately send telemetry in development environment. Create a monitoring service The configured ApplicationInsights instance in our application allows us to log messages, exceptions, track events, collect performance metrics and even custom events. Creating a wrapper service will allow us to set common properties. For example, cloud role name and user identifier can be set on each telemetry item. Regardless of the severity level, all data logged with trackTrace will appear in the Traces section of Azure Logs. Each log is classified as trace but has a severity level associated, which you can see in the Azure Portal. If you wish to only send error logs to Azure, you can add the following to configuration: Monitoring from a component With our wrapper service in place, let&#8217;s start capturing some logs in root component: Tracking page views It may be useful to know which pages are popular amongst users. Assuming your application is using deep links, we can listen to router events and log a page view using the monitoring service. It helps to have an identifier on your routed components: Logging unhandled exceptions Application Insights will automatically capture unhandled exceptions. However, this does not work for Angular applications because the framework swallows unhandled exceptions. In order to capture unhandled exceptions, you must implement a global error handler and use trackException method. Create a new file in your project, call it global-error-handler.ts and paste the following code: The error handler gets the instance of MonitoringService on the fly and logs an error. In order for this to work properly, we need to provide it in our root module. Tracking users It is important to associate telemetry items with authenticated users. You can achieve this with setAuthenticatedUserContext method, which accepts a user id. You would ideally call this function when the user session starts e.g. on successful login. Just make sure to clear user id when they log out, or whenever the session ends. Summary There you have it! It is very easy to monitor Angular applications with Application Insights. In this post, I explained how you can get started quickly. Ff you have any questions or suggestions, drop a comment below! View code on GitHub</p>
<p>The post <a href="https://onthecode.co.uk/blog/monitoring-live-angular-apps-with-azure-application-insights">Monitoring Live Angular Apps with Application Insights</a> appeared first on <a href="https://onthecode.co.uk">onthecode</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this post, I will explain how you can monitor Angular apps using Microsoft Azure Application Insights. </p>



<p>It is not unusual for organisations to ignore monitoring single page applications. Usually, back-end applications such as APIs are monitored via logs, CPU and memory usage.  </p>



<p>When it comes to front-end, there is usually not much in the way of monitoring.  </p>


<div id="ez-toc-container" class="ez-toc-v2_0_69 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction">
<div class="ez-toc-title-container">
<p class="ez-toc-title " >Table of contents</p>
<span class="ez-toc-title-toggle"></span></div>
<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-1" href="#getting-started-with-application-insights" title="Getting started with Application Insights">Getting started with Application Insights</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-2" href="#install-npm-package" title="Install npm package">Install npm package</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-3" href="#configure-application-insights" title="Configure Application Insights">Configure Application Insights</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-4" href="#create-a-monitoring-service" title="Create a monitoring service">Create a monitoring service</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-5" href="#monitoring-from-a-component" title="Monitoring from a component">Monitoring from a component</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-6" href="#tracking-page-views" title="Tracking page views">Tracking page views</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-7" href="#logging-unhandled-exceptions" title="Logging unhandled exceptions">Logging unhandled exceptions</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-8" href="#tracking-users" title="Tracking users">Tracking users</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-9" href="#summary" title="Summary">Summary</a></li></ul></nav></div>




<h2 class="wp-block-heading">Getting started with Application Insights</h2>



<p>First of all, create your free Azure account <a aria-label="here (opens in a new tab)" href="https://azure.microsoft.com/en-gb/free/NOA3fmCo66XHI" target="_blank" rel="noreferrer noopener">here</a>. </p>



<p>Head over to the <a href="http://portal.azure.com" target="_blank" rel="noreferrer noopener">portal</a> to create a new resource. Search for &#8216;application insights&#8217; and click <strong>Create</strong>.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img fetchpriority="high" decoding="async" src="https://onthecode.co.uk/wp-content/uploads/2022/02/Screenshot-2022-02-25-at-21.10.04-1024x578.png" alt="creating app insights" class="wp-image-4368" width="540" height="302"/></figure></div>


<p>It will take some time (usually a few seconds) to create the new Application Insights resource. Then, navigate to the resource and find your<strong> Instrumentation Key</strong> from the right hand side of the screen.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key-1024x390.png" alt="" class="wp-image-4377" width="530" height="201" srcset="https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key-1024x390.png 1024w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key-300x114.png 300w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key-768x292.png 768w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key.png 1492w" sizes="(max-width: 530px) 100vw, 530px" /></figure></div>


<p>The instrumentation key uniquely identifies the resource you created on Azure. You can use this key with as many components as you wish, including APIs and front end apps.</p>



<h2 class="wp-block-heading">Install npm package</h2>



<p>Install the official <a aria-label="Application Insights JavaScript SDK (opens in a new tab)" href="https://www.npmjs.com/package/@microsoft/applicationinsights-web" target="_blank" rel="noreferrer noopener">package </a>to your Angular application:</p>


<pre class="wp-block-code"><span><code class="hljs language-bash">npm install @microsoft/applicationinsights-web@latest</code></span></pre>


<p>This package includes all everything you need to start monitoring your Angular app.</p>



<h2 class="wp-block-heading">Configure Application Insights</h2>



<p>Initialise application insights in the root module of your app. If you have a core module, initialise it there.</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript"><span class="hljs-comment">// .. app.module.ts </span>
 providers: &#091;
    {
      provide: ApplicationInsights,
      useFactory: appInsightsFactory
    }
  ]

<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">appInsightsFactory</span>(<span class="hljs-params"></span>): <span class="hljs-title">ApplicationInsights</span> </span>{
  <span class="hljs-keyword">const</span> config: IConfig &amp; IConfiguration = {
    instrumentationKey: environment.appInsightsKey,
    disableTelemetry: environment.appInsightsKey === <span class="hljs-string">""</span>,
    enableCorsCorrelation: <span class="hljs-literal">true</span>
  };

  <span class="hljs-comment">// send telemetry immediately for dev environment </span>
  <span class="hljs-keyword">if</span> (!environment.production) {
    config.maxBatchInterval = <span class="hljs-number">0</span>;
    config.maxBatchSizeInBytes = <span class="hljs-number">0</span>;
    config.loggingLevelConsole = <span class="hljs-number">2</span>; <span class="hljs-comment">//log internal app insights errors to console</span>
  }

  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> ApplicationInsights({ config: config });
}</code></span></pre>


<p class="info-block">Please import classes from <code>@microsoft/applicationinsights-web</code> namespace.</p>



<p>The factory method creates an instance of ApplicationInsights client. In addition, it sets the instrumentation key from Angular environment variables. This instance is a singleton, which helps us avoid duplicate telemetry collection.</p>



<p>Setting <code>enableCorsCorrelation</code> to true adds custom headers to each and every request issued by Angular application. These headers are used on the server to correlate requests end to end. If your server has a CORS configuration, be sure to allow the following headers:</p>


<pre class="wp-block-code"><span><code class="hljs language-http">"Access-Control-Allow-Headers", "traceparent, request-id, request-context"</code></span></pre>


<p>The great thing about App Insights is that all telemetry is buffered and automatically sent to the Azure Portal when the user session ends i.e. browser tab is closed. This is especially useful in production environment as it does not impact user experience. </p>



<p>However, it can be annoying in development as you may need to wait or reload page to see data in the portal. That&#8217;s why I configure it above to immediately send telemetry in development environment.</p>



<h2 class="wp-block-heading">Create a monitoring service</h2>



<p>The configured ApplicationInsights instance in our application allows us to log messages, exceptions, track events, collect performance metrics and even custom events. </p>



<p>Creating a wrapper service will allow us to set common properties. For example, cloud role name and user identifier can be set on each telemetry item.</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript"><span class="hljs-keyword">import</span> { Injectable } <span class="hljs-keyword">from</span> <span class="hljs-string">"@angular/core"</span>;
<span class="hljs-keyword">import</span> { ApplicationInsights, SeverityLevel } <span class="hljs-keyword">from</span> <span class="hljs-string">"@microsoft/applicationinsights-web"</span>;
<span class="hljs-keyword">import</span> { environment } <span class="hljs-keyword">from</span> <span class="hljs-string">"src/environments/environment"</span>;

<span class="hljs-meta">@Injectable</span>({ providedIn: <span class="hljs-string">"root"</span> })
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> MonitoringService {
  <span class="hljs-keyword">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">private</span> appInsights: ApplicationInsights</span>) {
    <span class="hljs-keyword">this</span>.appInsights.loadAppInsights();

    <span class="hljs-keyword">this</span>.appInsights.setAuthenticatedUserContext(<span class="hljs-string">"USER_EMAIL"</span>);

    <span class="hljs-keyword">this</span>.appInsights.addTelemetryInitializer(<span class="hljs-function"><span class="hljs-params">envelope</span> =&gt;</span> {
      envelope.tags = envelope.tags || &#091;];
      envelope.tags.push({ <span class="hljs-string">"ai.cloud.role"</span>: <span class="hljs-string">"MyApp.Web"</span> });
      envelope.data = {
        environment: environment.id
      };
    });
  }

  logError(error: <span class="hljs-built_in">Error</span>): <span class="hljs-built_in">void</span> {
    <span class="hljs-keyword">this</span>.appInsights.trackException({ exception: error });
  }

  logInfo(message: <span class="hljs-built_in">string</span>): <span class="hljs-built_in">void</span> {
    <span class="hljs-keyword">this</span>.appInsights.trackTrace({ message: message, severityLevel: SeverityLevel.Information });
  }

  logPageView(componentId: <span class="hljs-built_in">string</span>, url: <span class="hljs-built_in">string</span> = <span class="hljs-built_in">window</span>.location.pathname): <span class="hljs-built_in">void</span> {
    <span class="hljs-keyword">this</span>.appInsights.trackPageView({ name: componentId, uri: url });
  }

  logEvent(name: <span class="hljs-built_in">string</span>, properties: <span class="hljs-built_in">any</span>): <span class="hljs-built_in">void</span> {
    properties.url = <span class="hljs-built_in">window</span>.location.pathname;
    <span class="hljs-keyword">this</span>.appInsights.trackEvent({ name, properties: properties });
  }
}</code></span></pre>


<p>Regardless of the severity level, all data logged with <code>trackTrace</code> will appear in the Traces section of Azure Logs. Each log is classified as <code>trace</code> but has a severity level associated, which you can see in the Azure Portal.</p>


<div class="wp-block-image">
<figure class="aligncenter is-resized"><img decoding="async" src="https://onthecode.co.uk/wp-content/uploads/2019/09/Azure-Trace-Logs-1-1024x473.png" alt="Azure App Insights Trace Logs" class="wp-image-2882" width="662" height="306" srcset="https://onthecode.co.uk/wp-content/uploads/2019/09/Azure-Trace-Logs-1-1024x473.png 1024w, https://onthecode.co.uk/wp-content/uploads/2019/09/Azure-Trace-Logs-1-300x139.png 300w, https://onthecode.co.uk/wp-content/uploads/2019/09/Azure-Trace-Logs-1-768x355.png 768w" sizes="(max-width: 662px) 100vw, 662px" /></figure></div>


<p>If you wish to only send error logs to Azure, you can add the following to configuration:</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript">loggingLevelTelemetry: SeverityLevel.Error</code></span></pre>


<h2 class="wp-block-heading">Monitoring from a component</h2>



<p>With our wrapper service in place, let&#8217;s start capturing some logs in root component:</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> AppComponent <span class="hljs-keyword">implements</span> OnInit {
  <span class="hljs-keyword">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">private</span> monitoringService: MonitoringService</span>) { }

  ngOnInit() {
   <span class="hljs-keyword">this</span>.monitoringService.logInfo(<span class="hljs-string">'App initialised at '</span> + <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().toString());
   <span class="hljs-keyword">this</span>.monitoringService.logError(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'My bug-free app throws an error'</span>));
   <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'An unhandled exception never happens, really.'</span>);
  }
}</code></span></pre>

<div class="wp-block-image">
<figure class="aligncenter is-resized"><img loading="lazy" decoding="async" src="https://onthecode.co.uk/wp-content/uploads/2019/09/Azure-Exception-Logs-1024x477.png" alt="Azure Exception Logs" class="wp-image-2884" width="586" height="273" srcset="https://onthecode.co.uk/wp-content/uploads/2019/09/Azure-Exception-Logs-1024x477.png 1024w, https://onthecode.co.uk/wp-content/uploads/2019/09/Azure-Exception-Logs-300x140.png 300w, https://onthecode.co.uk/wp-content/uploads/2019/09/Azure-Exception-Logs-768x358.png 768w" sizes="(max-width: 586px) 100vw, 586px" /></figure></div>


<h2 class="wp-block-heading">Tracking page views</h2>



<p>It may be useful to know which pages are popular amongst users. Assuming your application is using deep links, we can listen to router events and log a page view using the monitoring service.</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> AppComponent <span class="hljs-keyword">implements</span> OnInit {
  title = <span class="hljs-string">'AngularAppInsightsDemo'</span>;

  <span class="hljs-keyword">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">private</span> monitoringService: MonitoringService,
    <span class="hljs-keyword">private</span> router: Router</span>) { }

  ngOnInit() {
    <span class="hljs-keyword">this</span>.router.events
      .pipe(filter((event): event is ResolveEnd =&gt; event <span class="hljs-keyword">instanceof</span> ResolveEnd))
      .subscribe(<span class="hljs-function">(<span class="hljs-params"><span class="hljs-params">event</span></span>) =&gt;</span> {
        <span class="hljs-keyword">const</span> activatedComponent = <span class="hljs-keyword">this</span>.getActivatedComponent(event.state.root);
        <span class="hljs-keyword">if</span> (activatedComponent) {
          <span class="hljs-keyword">this</span>.monitoringService.logPageView(activatedComponent.id, event.url);
        }
      });
  }

  <span class="hljs-keyword">private</span> getActivatedComponent(snapshot: ActivatedRouteSnapshot): <span class="hljs-built_in">any</span> {
    <span class="hljs-keyword">if</span> (snapshot.firstChild) {
      <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.getActivatedComponent(snapshot.firstChild);
    }

    <span class="hljs-keyword">return</span> snapshot.component;
  }</code></span></pre>


<p>It helps to have an identifier on your routed components:</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> MyComponent {
  <span class="hljs-keyword">static</span> id = <span class="hljs-string">"my important page"</span>;
}</code></span></pre>


<h2 class="wp-block-heading">Logging unhandled exceptions</h2>



<p>Application Insights will automatically capture <a aria-label="automatically catches all unhandled exceptions (opens in a new tab)" href="https://github.com/Microsoft/ApplicationInsights-JS/blob/164530950b58120679e2193c8a7528d835943fee/JavaScript/JavaScriptSDK.Module/AppInsightsModule.ts#L81" target="_blank" rel="noreferrer noopener">unhandled exceptions</a>. However, this does not work for Angular applications because the framework swallows unhandled exceptions. </p>



<p>In order to capture unhandled exceptions, you must implement a <a aria-label=" implement a global error handler in your Angular app (opens in a new tab)" href="https://onthecode.co.uk/global-error-handling-angular/" target="_blank" rel="noreferrer noopener">global error handler</a> and use <code>trackException</code> method.</p>



<p>Create a new file in your project, call it <code>global-error-handler.ts</code> and paste the following code:</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript"><span class="hljs-keyword">import</span> { ErrorHandler, Injectable, Injector } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
<span class="hljs-keyword">import</span> { MonitoringService } <span class="hljs-keyword">from</span> <span class="hljs-string">'./monitoring.service'</span>;
<span class="hljs-meta">@Injectable</span>()
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> GlobalErrorHandler <span class="hljs-keyword">implements</span> ErrorHandler {
    <span class="hljs-keyword">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">private</span> injector: Injector</span>) { }
    handleError(error: <span class="hljs-built_in">Error</span>) {
        <span class="hljs-keyword">const</span> monitoringService = <span class="hljs-keyword">this</span>.injector.get(MonitoringService);
        monitoringService.logError(error);
    }
}</code></span></pre>


<p>The error handler gets the instance of <code>MonitoringService</code> on the fly and logs an error.</p>



<p>In order for this to work properly, we need to provide it in our root module.</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript">  providers: &#091;
    {
      provide: ApplicationInsights,
      useFactory: appInsightsFactory
    },
    {
      provide: ErrorHandler,
      useClass: GlobalErrorHandler
    }
  ]</code></span></pre>

<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-unhandled-exception-1024x416.png" alt="unhandled exception app insights" class="wp-image-4385" width="648" height="263" srcset="https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-unhandled-exception-1024x416.png 1024w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-unhandled-exception-300x122.png 300w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-unhandled-exception-768x312.png 768w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-unhandled-exception-1536x624.png 1536w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-unhandled-exception.png 1624w" sizes="(max-width: 648px) 100vw, 648px" /></figure></div>


<h2 class="wp-block-heading">Tracking users</h2>



<p>It is important to associate telemetry items with authenticated users. You can achieve this with <code>setAuthenticatedUserContext</code> method, which accepts a user id.</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript"><span class="hljs-keyword">this</span>.appInsights.setAuthenticatedUserContext(userId);</code></span></pre>


<p>You would ideally call this function when the user session starts e.g. on successful login.</p>



<p>Just make sure to clear user id when they log out, or whenever the session ends.</p>


<pre class="wp-block-code"><span><code class="hljs language-typescript"><span class="hljs-keyword">this</span>.appInsights.clearAuthenticatedUserContext();</code></span></pre>


<h2 class="wp-block-heading">Summary</h2>



<p>There you have it! It is very easy to monitor Angular applications with Application Insights. In this post, I explained how you can get started quickly. Ff you have any questions or suggestions, drop a comment below!</p>



<p><a href="https://github.com/umutesen/angular-app-insights-demo" target="_blank" rel="noreferrer noopener">View code on GitHub</a></p>
<p>The post <a href="https://onthecode.co.uk/blog/monitoring-live-angular-apps-with-azure-application-insights">Monitoring Live Angular Apps with Application Insights</a> appeared first on <a href="https://onthecode.co.uk">onthecode</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://onthecode.co.uk/blog/monitoring-live-angular-apps-with-azure-application-insights/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Monitoring Live .NET Core APIs with Application Insights</title>
		<link>https://onthecode.co.uk/blog/setup-azure-application-insights-telemetry-for-net-core-api-visual-studio-for-mac</link>
					<comments>https://onthecode.co.uk/blog/setup-azure-application-insights-telemetry-for-net-core-api-visual-studio-for-mac#comments</comments>
		
		<dc:creator><![CDATA[Umut Esen]]></dc:creator>
		<pubDate>Fri, 21 Jun 2019 21:22:04 +0000</pubDate>
				<category><![CDATA[Angular]]></category>
		<category><![CDATA[Microsoft Azure]]></category>
		<category><![CDATA[application insights]]></category>
		<category><![CDATA[azure]]></category>
		<guid isPermaLink="false">https://onthecode.co.uk/?p=2060</guid>

					<description><![CDATA[<p>Azure Application Insights is a cloud based application monitoring service from Microsoft. You can monitor your applications in all of your environments with Application Insights, including development and production. Microsoft has been shipping Visual Studio with built-in support for Application Insights in Windows. However, Visual Studio for Mac does not yet have the ability to add Application Insights to projects. In this post, I will show you how to add Application Insights telemetry to a .NET Core API using Visual Studio for Mac. Steps to setup Azure Application Insights telemetry for .NET Core API in Visual Studio for Mac: Create the resource on Azure Manually add package reference to the API project Configure API project with the Instrumentation Key Getting started with Application Insights First of all, create your free Azure account&#160;here.&#160; Head over to the&#160;portal&#160;to create a new resource. Search for ‘application insights’ and click&#160;Create. It will take some time (usually a few seconds) to create the new Application Insights resource. Then, navigate to the resource and find your&#160;Instrumentation Key&#160;from the right hand side of the screen. The instrumentation key uniquely identifies the resource you created on Azure. You can use this key with as many components as you wish, including APIs and front end apps. Configure project If your project is open in Visual Studio, close it and open the csproj file in TextEdit or a text editor. Add the following package reference to an ItemGroup. Open the project in Visual Studio for Mac and build. This will install all necessary packages for the project to send telemetry data to Azure. Next, open the configuration file of your project &#8211; usually config.json &#8211; and add the Instrumentation Key. If you happen to have multiple environments like staging, you need to create a separate Application Insights resource for each environment. Then, add the instrumentation key in each corresponding configuration file. Finally, complete the configuration of Application Insights in ConfigureServices inside of Startup.cs: Application Insights framework reads the whole configuration and interprets your instrumentation key. 3. Monitor Your Application That&#8217;s it! Let&#8217;s see some live telemetry. Startup the project and make a few calls to the API. Head over to the resource in Azure and you&#8217;ll see the results live! Summary We have seen how easy it is to setup Azure Application Insights for .NET Core Web APIs. If you have an Angular app, you can enable end-to-end monitoring read my post on how to monitor Angular using Application Insights.</p>
<p>The post <a href="https://onthecode.co.uk/blog/setup-azure-application-insights-telemetry-for-net-core-api-visual-studio-for-mac">Monitoring Live .NET Core APIs with Application Insights</a> appeared first on <a href="https://onthecode.co.uk">onthecode</a>.</p>
]]></description>
										<content:encoded><![CDATA[</p>
<p>Azure Application Insights is a cloud based application monitoring service from Microsoft. You can monitor your applications in all of your environments with Application Insights, including development and production. Microsoft has been shipping Visual Studio with built-in support for Application Insights in Windows. However, Visual Studio for Mac does not yet have the ability to add Application Insights to projects. In this post, I will show you how to add Application Insights telemetry to a .NET Core API using Visual Studio for Mac. </p>
</p>
<p>Steps to setup Azure Application Insights telemetry for .NET Core API in Visual Studio for Mac:</p>
</p>
<ul class="wp-block-list">
<li>Create the resource on Azure</li>
<li>Manually add package reference to the API project</li>
<li>Configure API project with the Instrumentation Key</li>
</ul>
<p><div id="ez-toc-container" class="ez-toc-v2_0_69 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction">
<div class="ez-toc-title-container">
<p class="ez-toc-title " >Table of contents</p>
<span class="ez-toc-title-toggle"></span></div>
<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-1" href="#getting-started-with-application-insights" title="Getting started with Application Insights">Getting started with Application Insights</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-2" href="#configure-project" title="Configure project">Configure project</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-3" href="#3-monitor-your-application" title="3. Monitor Your Application">3. Monitor Your Application</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-4" href="#summary" title="Summary">Summary</a></li></ul></nav></div>

</p>
</p>
<h2 class="wp-block-heading">Getting started with Application Insights</h2>
</p>
<p>First of all, create your free Azure account&nbsp;<a href="https://azure.microsoft.com/en-gb/free/NOA3fmCo66XHI" target="_blank" rel="noreferrer noopener">here</a>.&nbsp;</p>
</p>
<p>Head over to the&nbsp;<a href="https://portal.azure.com" target="_blank" rel="noreferrer noopener">portal</a>&nbsp;to create a new resource. Search for ‘application insights’ and click&nbsp;<strong>Create</strong>.</p>
</p>
<figure class="wp-block-image is-resized"><img loading="lazy" decoding="async" src="https://onthecode.co.uk/wp-content/uploads/2022/02/Screenshot-2022-02-25-at-21.10.04-1024x578.png" alt="creating app insights" class="wp-image-4368" width="621" height="350" srcset="https://onthecode.co.uk/wp-content/uploads/2022/02/Screenshot-2022-02-25-at-21.10.04-1024x578.png 1024w, https://onthecode.co.uk/wp-content/uploads/2022/02/Screenshot-2022-02-25-at-21.10.04-300x169.png 300w, https://onthecode.co.uk/wp-content/uploads/2022/02/Screenshot-2022-02-25-at-21.10.04-768x433.png 768w, https://onthecode.co.uk/wp-content/uploads/2022/02/Screenshot-2022-02-25-at-21.10.04.png 1230w" sizes="(max-width: 621px) 100vw, 621px" /></figure>
</p>
<p>It will take some time (usually a few seconds) to create the new Application Insights resource. Then, navigate to the resource and find your<strong>&nbsp;Instrumentation Key</strong>&nbsp;from the right hand side of the screen.</p>
</p>
<figure class="wp-block-image is-resized"><img loading="lazy" decoding="async" src="https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key-1024x390.png" alt="" class="wp-image-4377" width="522" height="198" srcset="https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key-1024x390.png 1024w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key-300x114.png 300w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key-768x292.png 768w, https://onthecode.co.uk/wp-content/uploads/2022/02/app-insights-instrumentation-key.png 1492w" sizes="(max-width: 522px) 100vw, 522px" /></figure>
</p>
<p>The instrumentation key uniquely identifies the resource you created on Azure. You can use this key with as many components as you wish, including APIs and front end apps.</p>
</p>
<h2 class="wp-block-heading">Configure project</h2>
</p>
<p>If your project is open in Visual Studio, close it and open the <strong>csproj</strong> file in <strong>TextEdit</strong> or a text editor. </p>
</p>
<p>Add the following package reference to an ItemGroup.</p>
</p>
<pre class="wp-block-code"><code>&lt;PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.0"/&gt;</code></pre>
</p>
<p>Open the project in Visual Studio for Mac and build. This will install all necessary packages for the project to send telemetry data to Azure. </p>
</p>
<p>Next, open the configuration file of your project &#8211; usually config.json &#8211; and add the Instrumentation Key.</p>
</p>
<pre class="wp-block-code"><code>...
    },
    "ApplicationInsights": {
        "InstrumentationKey": "xxxx-yyyy-zzzz"
    }
}</code></pre>
</p>
<p>If you happen to have multiple environments like staging, you need to create a separate Application Insights resource for each environment. Then, add the instrumentation key in each corresponding configuration file. </p>
</p>
<p>Finally, complete the configuration of Application Insights in <strong>ConfigureServices</strong> inside of <strong>Startup.cs</strong>:</p>
</p>
<pre class="wp-block-code"><code>services.AddApplicationInsightsTelemetry(Configuration);</code></pre>
</p>
<p>Application Insights framework reads the whole configuration and interprets your instrumentation key.</p>
</p>
<h2 class="wp-block-heading">3. Monitor Your Application</h2>
</p>
<p>That&#8217;s it! Let&#8217;s see some live telemetry.</p>
</p>
<p>Startup the project and make a few calls to the API. Head over to the resource in Azure and you&#8217;ll see the results live!</p>
</p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="497" src="https://onthecode.co.uk/wp-content/uploads/2019/06/Azure-telemetry-1024x497.png" alt="" class="wp-image-2096" srcset="https://onthecode.co.uk/wp-content/uploads/2019/06/Azure-telemetry-1024x497.png 1024w, https://onthecode.co.uk/wp-content/uploads/2019/06/Azure-telemetry-300x146.png 300w, https://onthecode.co.uk/wp-content/uploads/2019/06/Azure-telemetry-768x373.png 768w, https://onthecode.co.uk/wp-content/uploads/2019/06/Azure-telemetry-700x340.png 700w, https://onthecode.co.uk/wp-content/uploads/2019/06/Azure-telemetry.png 1546w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</p>
<h2 class="wp-block-heading">Summary</h2>
</p>
<p>We have seen how easy it is to setup Azure Application Insights for .NET Core Web APIs. </p>
</p>
<p>If you have an Angular app, you can enable end-to-end monitoring  read my post on <a href="https://onthecode.co.uk/monitoring-live-angular-apps-with-azure-application-insights/">how to monitor Angular using Application Insights</a>.</p></p>
<p>The post <a href="https://onthecode.co.uk/blog/setup-azure-application-insights-telemetry-for-net-core-api-visual-studio-for-mac">Monitoring Live .NET Core APIs with Application Insights</a> appeared first on <a href="https://onthecode.co.uk">onthecode</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://onthecode.co.uk/blog/setup-azure-application-insights-telemetry-for-net-core-api-visual-studio-for-mac/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
