Skip to content

Latest commit

 

History

History
105 lines (74 loc) · 3.86 KB

File metadata and controls

105 lines (74 loc) · 3.86 KB

Exercise 4 - Application Insights

Learnings

  1. Basics about Application Insights
  2. Connecting to Application Insights using instrumentation key
  3. Analyze Application Insights data in the Azure Portal and Visual Studio

Create Application Insights

  1. Discussion points:

    • Discuss why telemetry and logging are important especially in Microservices architectures
    • Describe the basics of Application Insights (e.g. high-level features, architecture, pricing models, etc.)
  2. Open Azure Portal and sign in.

  3. Add Application Insights named PracticalDevOps-Dev to the resource group PracticalDevOps-Dev.
    Add App Insights

  4. Copy Instrumentation Key from Azure Portal
    Copy Instrumentation Key

Configure Application to Use Application Insights

  1. Add the InstrumentationKey setting to your web.config file.

     <?xml version="1.0" encoding="utf-8"?>
     ...
     <configuration>
         <appSettings>
             <add key="MinimumNumberOfBooks" value="1"/>
             <add key="MaximumNumberOfBooks" value="5"/>
             <add key="BookNameTokenUrl" value="..."/>
             <add key="InstrumentationKey" value="ba2c0764-5cfb-4741-a8e1-fb150b175a7d"/>
         </appSettings>
         ...
     </configuration>
    
  2. Add code setting the instrumentation key to Startup.cs:

     public void Configuration(IAppBuilder app)
     {
         TelemetryConfiguration.Active.InstrumentationKey = ConfigurationManager.AppSettings["InstrumentationKey"];
    
         // Allow CORS
         app.UseCors(CorsOptions.AllowAll);
         ...
     }
    
  3. Add custom event tracking to Controllers/BooksController.cs:

     [HttpGet]
     [Route("books")]
     public async Task<IEnumerable<Book>> Get()
     {
         var numberOfBooks = new Random().Next(this.options.MinimumNumberOfBooks, this.options.MaximumNumberOfBooks + 1);
    
         var telemetryClient = new TelemetryClient();
         telemetryClient.TrackEvent($"Generating {numberOfBooks} books");
    
         var result = new Book[numberOfBooks];
         ...
     }
    
  4. Discussion points:

    • Describe basics of Application Insights SDK (e.g. exception logging, metrics)

Run Application and View Telemetry

  1. Run all your tests to make sure you did not break something.

  2. Run application locally and refresh http://localhost:2690/api/books multiple times.

  3. Open Search in Application Insights.
    Search AppInsights

  4. See if your application telemetry appears.

  5. Discussion points:

    • Let people play a bit with building Application Insights dashboards in the Azure portal
    • Describe concept of custom processing of Application Insights data
    • Brief overview about other Application Insights modules (e.g. for IaaS)
  6. Open Application Insights Search in Visual Studio while debugging your application. Refresh http://localhost:2690/api/books multiple times. See if your application telemetry appears.
    Application Insights Search

  7. Discussion points:

    • Point out how calls to dependent services are tracked automatically
    • Show how unnecessary calls to Blob Storage in our app become visible by analyzing Application Insights telemetry data

Further Ideas

If you have time left, you could additionally cover topics like: