aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Web analytics and diagnostics

Open danroth27 opened this issue 6 years ago • 19 comments

  • [ ] Integration with web analytics systems (ex Azure Application Insights, Google Analytics)

danroth27 avatar Jan 25 '18 17:01 danroth27

Does Serilog "just work" for something like this?
https://github.com/serilog/serilog/wiki/Provided-Sinks

benhysell avatar Mar 09 '18 13:03 benhysell

In general, .NET Standard 2.0 libraries should work from a Blazor app. Which sinks are most interesting to you?

danroth27 avatar Mar 09 '18 18:03 danroth27

Azure Application Insights and Seq, https://getseq.net, are the two I use most often.

benhysell avatar Mar 09 '18 18:03 benhysell

I playing with setting up Application Insights inside Blazor. That seems trivial task if I just copy paste JS initialization code inside index.hml. Then I could interop using JS api At the same time this does not allow me to set Instrumentation Key. Same question if I attempt to run AI inside Blazor's .NET code. I need somehow pass Instrumentation Key for configuration purposes. Any ideas how this could be done right now ?

kant2002 avatar Aug 24 '18 04:08 kant2002

At the same time this does not allow me to set Instrumentation Key.

Why not? Isn't the instrumentation key typically embedded in the JS code? https://docs.microsoft.com/en-us/azure/application-insights/app-insights-javascript#add-the-sdk-script-to-your-app-or-web-pages

danroth27 avatar Aug 24 '18 05:08 danroth27

I have project which will use different AI accounts for staging and for production. (Assuming that Blazor will take off). Also I use same AI key for API and for Blazor application, which require me to sync them, or worse - ask customer to manually replace AI key in two places. In the ASP.NET Core (and regular ASP.NET and just AI SDK) I without problem could change AI key using appsettings.json. Would be good to have this in the Blazor as well.

Since Blazor use index.html for serving application, and at the same time there no way to pass command line parameters when I embed Blazor in ASP.NET Core website (no parameters here app.UseBlazor<BlazorApp1.Program>();). It may be not about AI itself, but rather ability to pass configuration from the application hosting Blazor.

kant2002 avatar Aug 24 '18 06:08 kant2002

Hi, I just created a Google Analytics extension for Blazor. I think it could be relevant to this ticket. https://github.com/isc30/blazor-analytics

This library can be extended for multiple analytics providers easily (+add TrackingService for complex operations)

isc30 avatar Apr 18 '19 21:04 isc30

Hi, I just created a Google Analytics extension for Blazor. I think it could be relevant to this ticket. https://github.com/isc30/blazor-analytics

This library can be extended for multiple analytics providers easily (+add TrackingService for complex operations)

I hope you don't mind but I have used your library for inspiration to implement as you suggest. https://github.com/robdavey555/Blazor.ApplicationInsights

robdavey555 avatar Apr 24 '20 17:04 robdavey555

Is there any update on this?

I would prefer to use dotnet rather than js to send telemetry events, as this would allow for easily consuming existing logging code in a wasm app.

martinfletcher-w2 avatar Jul 01 '20 12:07 martinfletcher-w2

Hi all,

I also would prefer registering AI instance into IoC container on the program.cs, like HttpClient, and then inject telemetry client each .razor pages. Otherwise, we can't track C# exceptions in a proper way.

Many Thanks

mehmettahameral avatar Jul 11 '20 16:07 mehmettahameral

I just released https://github.com/IvanJosipovic/BlazorApplicationInsights It hooks all logging to App Insights and supports App Insights Apis like Track Event etc.

IvanJosipovic avatar Jul 17 '20 01:07 IvanJosipovic

@kant2002

In the ASP.NET Core (and regular ASP.NET and just AI SDK) I without problem could change AI key using appsettings.json. Would be good to have this in the Blazor as well.

Check out https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/configuration?view=aspnetcore-5.0#app-settings-configuration

Specifically this section (no direct link available) image

Since different environments typically have different configurations (i.e. Instrumentation Key), your deployment process should be responsible for putting the correct file (i.e. $"{environment}.json") in the deployed application. Then in your Startup class use builder.HostEnvironment.Environment to interpolate the filename if you need it in your Blazor app.

You can also load this file in index.html and set it with the AI JS SDK.

This should enable the functionality you require.

ElanHasson avatar Jun 06 '21 02:06 ElanHasson

Might be related to #30972

Liero avatar Jun 11 '21 06:06 Liero

@danroth27 Is there an ETA for this? This issue has been languishing for over 4 years now; almost two years after @SteveSandersonMS has labelled it as a major severity. We had expected this to be ready with .net 6 release. The implication is that it is creating strong headwinds against us convincing folks #BlazorWASM has critical mass and is production ready.

indcoder avatar Jan 25 '22 23:01 indcoder

@danroth27 Is there an ETA for this? This issue has been languishing for over 4 years now; almost two years after @SteveSandersonMS has labelled it as a major severity. We had expected this to be ready with .net 6 release. The implication is that it is creating strong headwinds against us convincing folks #BlazorWASM has critical mass and is production ready.

You can use the javascript appinsights sdk -> same with google analytics.

In my production app we use the following packages https://github.com/IvanJosipovic/BlazorApplicationInsights https://github.com/isc30/blazor-analytics

both are working very well without much work to setup

CoryKoehler avatar Jan 26 '22 00:01 CoryKoehler

@CoryKoehler We are aware of the two packages [they have cropped up earlier in this thread years back ]. But the recent log4j scare has completely changed the landscape; especially in the enterprise sector. Mind you, they are official AppInsights plugins for react and angular; we are demanding parity for BlazorWASM and we solicit your support in this regard.

indcoder avatar Jan 26 '22 00:01 indcoder

Hello, I am coming from - https://github.com/microsoft/ApplicationInsights-dotnet/issues/2143 that has referenced this issue. Also alternative - https://feedback.azure.com/d365community/idea/4f959530-1425-ec11-b6e6-000d3a4f09d0

Please inform us about plan and status for supporting Application insights in .NET 6 SDK via dotnet new blazorwasm

Thank you

hkusulja avatar Jan 26 '22 14:01 hkusulja

For folks considering jumping from react to blazor, please add native blazor wasm support for Azure AI

ss-proc avatar Jul 27 '22 06:07 ss-proc

I can confirm that this is causing headwinds for the same reasons @indcoder pointed out. Enterprise sentiment has shifted negatively towards third-party logging providers and having native support for Azure AI is definitely crucial. A similar discussion can be found at https://github.com/microsoft/ApplicationInsights-dotnet/issues/2143 @danroth27 is native Azure AI support something that the Blazor Team would even consider doing or is the SDK Team solely responsible for that? Their current status is 'this is not being actively worked on by anyone in the SDK team' - so hopefully not a ping-pong problem.

Postlagerkarte avatar Sep 21 '22 20:09 Postlagerkarte

After 4 years I still haven't been able to associate logs with username or current url in Blazor Server. How this cannot be prioritized is beyond my understanding

Liero avatar Sep 23 '22 06:09 Liero

@Liero I think that this should be resolved under Application Insights team and their SDK which should support Blazor WASM here is feature request - https://github.com/microsoft/ApplicationInsights-dotnet/issues/2143

hkusulja avatar Sep 23 '22 07:09 hkusulja