All posts by Kevin

About Kevin

IoT & Azure ML Learner

Azure Application Insights customEvents and .NET 6

Getting customEvents with Azure Application Insights customEvents and .NET 6

dotnet new mvc -o videowebapp
cd videowebapp
dotnet add package Microsoft.ApplicationInsights.AspNetCore

Program.cs: Adding builder.Services.AddApplicationInsightsTelemetry();

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
IServiceCollection serviceCollection = builder.Services.AddApplicationInsightsTelemetry();
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

Getting InstrumentationKey

az resource show \
    --resource-group <resource_group_name> \
    --name <resource_name> \
    --resource-type "Microsoft.Insights/components" \
    --query properties.InstrumentationKey

appsettings.json : adding InstrumentationKey

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ApplicationInsights": {
    "InstrumentationKey": "0000000000000000000000000000000",
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Error"
    }
  }
}

HomeController.cs : Adding ” this.aiClient.TrackEvent(“CommentSubmitted”); ”

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using videowebapp.Models;
using Microsoft.ApplicationInsights;

namespace videowebapp.Controllers;

public class HomeController : Controller
{
    private TelemetryClient aiClient;
 //   private readonly ILogger<HomeController> _logger;

public HomeController(TelemetryClient aiClient)
{
    this.aiClient = aiClient;
}
/*    public HomeController(ILogger<HomeController> logger)
    {
        _logger = logger;
    }
*/
    public IActionResult Index()
    {
       // _logger.LogWarning("fujuTE: An example of a Warning trace..");
       // _logger.LogError("fujuTE: An example of an Error level message");
        return View();
    }

    public IActionResult Privacy()
    { 
        // _logger.LogInformation("fujuTE: An example of a Information trace..");
        // Track an event
        this.aiClient.TrackEvent("CommentSubmitted");

        // Track an event with properties
        this.aiClient.TrackEvent("VideoUploaded", new Dictionary<string, string> {{"Category", "Sports"}, {"Format", "mp4"}});

        return View();
    }

    [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
    public IActionResult Error()
    {
        return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
    }
}
Application Insight – Transaction Search
Getting customEvents vai Log Analytics Workspace

See Also:

Create Azure Service Principal and “az login”

Sample of creating Resource Group and then create Service Principle with contributor role under the RG for DevOps Pipeline

#MY_RG=1myResourceGroup
#az group create --name $MY_RG --location southeastasia
#RG_ID=$(az group show --name $MY_RG --query "id" --output tsv)
# or 
MY_RG=1myResourceGroup
RG_ID=$(az group create --name $MY_RG  --location southeastasia --query "id" --output tsv)
SERVICE_PRINCIPAL_NAME=Exzilla-sp-21022022
PASSWORD=$(az ad sp create-for-rbac --name $SERVICE_PRINCIPAL_NAME --role contributor --scopes $RG_ID  --query "password" --output tsv)
USER_NAME=$(az ad sp list --display-name $SERVICE_PRINCIPAL_NAME --query "[].appId" --output tsv)

az login --service-principal -u $USER_NAME -p $PASSWORD --tenant <mytenant>.onmicrosoft.com

How to build real world cloud applications using Windows Azure

How to build real world cloud applications using Windows Azure
 

Video:
Part 1: Building Real World Cloud Apps with Azure
http://channel9.msdn.com/Events/TechEd/Australia/2013/AZR324
 
  Part 2: Building Real World Cloud Apps with Azure
 http://channel9.msdn.com/Events/TechEd/Australia/2013/AZR325
 
 
Free ebook: Building Cloud Apps with Microsoft Azure
 http://weblogs.asp.net/scottgu/free-ebook-building-cloud-apps-with-microsoft-azure

Four Principles of Engineering Scalable, Big Data Software Systems from CMU

 

Four Principles of Engineering Scalable, Big Data Software Systems By Ian Gorton
Senior Member of the Technical Staff
Software Solutions Division

  • First Principle: System Costs Must Grow More Slowly Than System Capacity
  • Second Principle: The More Complex a Solution, the Less Likely it Will Scale
  • Third Principle: Avoid Managing Conversational State Outside the Data Tier
  • Fourth Principle: You Can’t Manage What You Don’t Monitor

http://blog.sei.cmu.edu/post.cfm/four-principles-engineering-big-data-systems-195

Steps to Success

ได้มาจากข้อความที่ติดในโรงเรียนอนุบาล เข้าใจว่าให้ทั้งคุณครูและนักเรียนอนุบาลอ่าน

The Top 10  Steps to Success
 1.Try
 2.Try again
 3.Try once more
 4.Try it a little differently
 5.Try it again tomorrow
 6.Try and ask for help
 7.Try to find someone who’s done it
 8.Try to determine what is not working
 9.Try to determine what is working
 10.Just keep trying

ไม่ว่าจะผ่านไปกี่ปีการต่อสู้กับตนเองก็ยังเกิดขึ้นทุกว้น เกิดขึ้นกับรูปแบบของปัญหาที่ซับซ้อนมากขึ้น และกับความต้องการที่ซับซ้อนมากขั้นด้วยเช่นกัน

(ref: http://www.narisa.com/forums/index.php?app=blog&module=display&section=blog&blogid=4&showentry=1815 )