Azure Application Insights in .NET Applications

Rainer Stropek | @rstropek

Introduction

Rainer Stropek

  • Passionate developer since 25+ years
     
  • Microsoft MVP, Regional Director
     
  • Trainer, Teacher, Mentor
     
  • 💕 community

Application Insights Supports Many Languages and Platforms

                               ...
but here we focus on .NET

Why Application Insights?

Application Performance Monitoring

  • Detect performance anomalies
  • Diagnose issues
  • See what users do
  • Basis for continuous improvement
    • Performance
    • Stability
    • Build what users really need

OpenTelemetry

  • Microsoft supports OpenTelemetry
  • Independent of cloud environment
    • Not just Azure
  • Disadvantage: Fewer features compared to native App Insights
  • Choose based on project needs
    • Do you value portability over features?
  • Here: Focus on App Insights

Auto-Instrumentation vs. App Insights SDKs

Auto-Instrumentation

  • aka "Codeless" approach
  • No need to change your code at all
  • Supports a large number of platforms and Azure services 🔗
  • Collects telemetry data automatically
  • Disadvantage: Functional limitations

Add App Insights SDK

  • Enable Application Insights by adding SDK
    • Microsoft.ApplicationInsights.AspNetCore
  • ​(Minimal) Code additions necessary

  • SDK will gather data

    • Auto-instrumentation will back off automatically
      if SDK is detected

  • ​Not just for ASP.NET Core

    • ​For background worker services 🔗

    • For console apps 🔗

  • ​Recommended approach if possible

Demo
Time!

ASP.NET Core BFF

  • Create new ASP.NET Core Web API
  • Discuss adding App Insights with Visual Studio tools 🔗
  • Demo manual adding of App Insights 🔗
    • Add NuGet Microsoft.ApplicationInsights.AspNetCore
    • builder.Services.AddApplicationInsightsTelemetry();
  • Demo ApplicationInsightsServiceOptions

  • Demo gathering of telemetry...

    • ...in Visual Studio

    • ...in the Azure Portal

Telemetry Initializers/Processors

  • Plugins for App Insights
  • Enrich/process/filter telemetry before it is sent
  • Differences between processors and initializers.
    In short...
    • Initializers enrich telemetry
    • Processors can completely replace or
      discard (=filter) telemetry items

Demo
Time!

Correlation

What is Correlation?

  • End-to-end view of transactions
  • Important in distributed systems
    • E.g. Microservices architecture

Demo
Time!

ASP.NET Core Backend

  • Add Backend API
  • Demonstrate Operation ID

Browser
Client

Backend

What Else?

Azure AD Authentication

  • Ensure that only authenticated telemetry is ingested
  • Important if business decisions are made based on telemetry data

Gather IP Addresses

  • By default, IP addresses are only used for geolocation lookup
    • After that, IP addresses are replaced by 0.0.0.0
    • Privacy reasons
  • You can enable storing IP addresses (disable IP masking)

Sampling

  • Adaptive sampling (recommended)
    • Volume of telemetry is adjusted automatically
    • Setting MaxTelemetryItemsPerSecond
  • Fixed-rate sampling
    • Limit telemetry based on a fixed rate (e.g. 10%)
  • Ingestion sampling
    • Sampling is done by App Insights, not before sending
    • Only use if other options are not feasilbe

Channels

  • In-memory channel
    • Lightweight
    • Buffers in memory
    • Flushed every 30 seconds or 500 items or manual Flush()
    • Good for short-running applications
  • Server telemetry channel
    • Stores data on disk, retries sending (e.g. short network outage)
    • Recommended (and default) for production web app/APIs

App Insights 🤘

Rainer Stropek | @rstropek

Azure Application Insights in .NET Applications

By Rainer Stropek

Azure Application Insights in .NET Applications

  • 446