I think i found what i was looking for and if you want to share this or possibly add this to your code generation here is what i found.
to start to get full application insights that identify the user and the pages they view you need to do several things.
this is with dot net core 7 right now and i do not know if they will change in v8
first in program cs one needs to hookup Application Insights
builder.Services.AddApplicationInsightsTelemetry();
now i found a package that helps activate some parts of what ai can do so i also added this from nuget:
then i had to modify
_host.chtml
adding the javascript for application insights
right now this is not ideal in how i am doing it, theconnection sting for ai is hard coded in my file.
need to find a better way to do that for getting the connection string from app config.
then in program.cs i also added this:
builder.Services.AddBlazorApplicationInsights(async applicationInsights =>
{
var telemetryItem = new TelemetryItem() {
Tags = new Dictionary<string, object>()
{
{ "ai.cloud.role", "SPA" },
{ "ai.cloud.roleInstance", "Blazor Server" },
}
};
await applicationInsights.AddTelemetryInitializer(telemetryItem);
});
and then to track the user login / logout i had to modify the security service.cs
setup to inject
private readonly IApplicationInsights AppInsights;
public SecurityService(NavigationManager navigationManager, IHttpClientFactory factory, IApplicationInsights Insights) {
this.httpClient = factory.CreateClient("RiaApp");
this.navigationManager = navigationManager;
this.AppInsights = Insights;
then...
in initalize
public bool Initialize(AuthenticationState result) {
Principal = result.User;
var name = Principal.FindFirstValue(ClaimTypes.Name) ?? Principal.FindFirstValue("name");
if (name != null) {
var foo = Principal.FindFirst("preferred_username")?.Value;
AppInsights.SetAuthenticatedUserContext(foo);
User = new ApplicationUser { Name = name, preferred_username=foo };
}
return IsAuthenticated();
}
and logout:
public void Logout() {
AppInsights.ClearAuthenticatedUserContext();
navigationManager.NavigateTo("Account/Logout", true);
}
all of this may not be the best way but it looks like it works right now.....
it might be worth seeing if RadZen Blazor Studio might get an added option to do something like this by letting the user select "Add Application Insights" and provide the ai key.