IvanJosipovic / BlazorApplicationInsights

Application Insights for Blazor web applications

Home Page:https://BlazorApplicationInsights.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Everything working but TrackEvent?

bluisanajmr opened this issue · comments

I have implemented everything exactly as shown from the Install section.

I can see events when I refresh my page in the app. I am getting page hits, dependencies and all of the built in app insights data.

I wrote a very simple method to track a custom event on the main page that is already sending good page data to insights. It executes with no error but I don't see any custom events in the app insights portal. I also don't see this custom event being sent to appinsights in the developer network calls. Have I missed a configuration step?

private async Task TrackEvent()
{
await AppInsights.TrackEvent("My Event");
await AppInsights.Flush();
}

protected override async Task OnInitializedAsync()
{
await TrackEvent();
}

To make this even weirder, I just checked application insights again this morning. I have been testing this app all morning. There is now 1 of my custom events in application insights. I have probably ran this app 100 times and have tons of data in my app insights portal. I can't get another custom event to be sent and have no idea how that one got there. I can refresh my initial page and see the page/depency data all show up in app insights within a few seconds. The trackevent code from above is in my main index.razor page and gets called everytime the app loads.

I found out what is going on but still don't know how to fix my scenario. The index.razor page of my app contains that code shown at the top of this issue and nothing else. If I open the app it navigates to index.razor, OnInitializedAsync fires and calls the TrackEvent method. The custom event is never sent to app insights but all other telementry is sent. If I go to another page in my app and then navigate back to index.razor the custom event is sent along with all other telemetry. If I manually refresh the index.razor page in the browser the Trackevent code is called but no custom event is sent. If I create a button on the page that calls the trackevent method the custom event is sent.

Try moving your code to the OnAfterRenderAsync event.