Giter Club home page Giter Club logo

Comments (12)

cijothomas avatar cijothomas commented on May 24, 2024

@ghosttie Where do you see application insights turned on by default? Its is not turned on, unless you add it yourself.
Depending on how you onboarded to application insights, the same can be reversed - but the most easy option is to remove application insights from packagereference.

from applicationinsights-aspnetcore.

ghosttie avatar ghosttie commented on May 24, 2024

I never chose it, when I created the project it was already there

I don't want to remove it completely in case we want it later, I just want to be able to turn it off when I don't need it

from applicationinsights-aspnetcore.

cijothomas avatar cijothomas commented on May 24, 2024

Please share the screenshots on how you created a new project. I am not aware of application insights being installed automatically for a .net core 2.2 project.

You can comment out/remove the services.AddApplicationInsightsTelemetry()/builder.UseApplicationInsights() when you don't need application insights.

from applicationinsights-aspnetcore.

ghosttie avatar ghosttie commented on May 24, 2024

Sorry, I guess I was misleading - it's 2.2 now but it was originally 1.0 that's been upgraded through every version, so maybe it was installed by default in the past but isn't anymore.

I tried putting the call to IWebHostBuilder.UseApplicationInsights in an #if !DEBUG but I got a

invalidoperationexception: No service for type 'Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet' has been registered.

so I figured it must be more complicated...

from applicationinsights-aspnetcore.

cijothomas avatar cijothomas commented on May 24, 2024

The javascriptsnippet is a known issue, fixed in 2.8.0-beta2.
If you are using older version, do the following temp workaround:

Add services.AddWebEncoders(); in ConfigureServices() method of your Startup.cs class, before services.AddApplicationInsightsTelemetry();

from applicationinsights-aspnetcore.

ghosttie avatar ghosttie commented on May 24, 2024

I've since upgraded to ASP.NET Core 3.0 and I'm using Microsoft.ApplicationInsights.AspNetCore 2.8.0

In Startup.cs ConfigureServices I have

#if !DEBUG
	services.AddApplicationInsightsTelemetry();
#endif

but when I run it in Debug mode (or just comment it out entirely) I still get

System.InvalidOperationException: No service for type 'Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet' has been registered.
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator.<>c__DisplayClass8_0.<CreateActivateInfo>b__1(ViewContext context)
   at Microsoft.Extensions.Internal.PropertyActivator`1.Activate(Object instance, TContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator.Activate(Object page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorPageActivator.Activate(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderViewStartsAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I don't understand why it's doing anything at all if I don't call AddApplicationInsightsTelemetry...

from applicationinsights-aspnetcore.

cijothomas avatar cijothomas commented on May 24, 2024

@ghosttie You still have appliction insights in razor pages. If you didn't intent to use application insights, remove it from razor pages as well.

from applicationinsights-aspnetcore.

ghosttie avatar ghosttie commented on May 24, 2024

I also have a compile time time check around this in _ViewImports.cshtml

#if !DEBUG
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
#endif

and one in _Layout.cshtml

#if !DEBUG
@Html.Raw(JavaScriptSnippet.FullScript)
#endif

is that what you mean? Or somewhere else?

from applicationinsights-aspnetcore.

cijothomas avatar cijothomas commented on May 24, 2024

All usage of Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet.

The error indicates Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet is being requested (and failing as not registered). So remove all references to it.

from applicationinsights-aspnetcore.

ghosttie avatar ghosttie commented on May 24, 2024

Ah, apparently compiler directives don't work in CSHTML.

Thank you for your help

from applicationinsights-aspnetcore.

ghosttie avatar ghosttie commented on May 24, 2024

OK I'm left with my original problem - I want to be able to turn off Application Insights when in Debug mode but I can't do it.

Because compiler directives don't work in CSHTML I can't turn it off that way, and if I wrap the JavaScriptSnippet line in an @if it seems to get processed when the Razor page is compiled regardless whether the code would get called or not

Is there not a property in Application Insights to turn off collection?

I found references to TelemetryConfiguration.Active.DisableTelemetry = true but when I tried to use it I got

Warning CS0618 'TelemetryConfiguration.Active' is obsolete: 'We do not recommend using TelemetryConfiguration.Active on .NET Core. See microsoft/ApplicationInsights-dotnet#1152 for more details'

I read through that bug but it didn't seem to help with my goal.

Reading through the documentation I tried this to turn of all collection:

#if DEBUG
	services.ConfigureTelemetryModule<EventCounterCollectionModule>((module, o) => {
		module.Counters.Clear();
	});
#endif

but it's still logging a bunch of Application Insights Telemetry lines

from applicationinsights-aspnetcore.

cijothomas avatar cijothomas commented on May 24, 2024

Not sure which doc you are following.

Here's official doc:
https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core#disable-telemetry-dynamically

from applicationinsights-aspnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.