Comments (12)
@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.
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.
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.
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.
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.
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.
@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.
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.
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.
Ah, apparently compiler directives don't work in CSHTML.
Thank you for your help
from applicationinsights-aspnetcore.
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.
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)
- Instrumentationkey read from appsettings.json even if it is not in Configuration.Providers HOT 1
- System.InvalidCastException exception with .NET Core 3.0 HOT 1
- Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.4.0 HOT 5
- AspNetCore: This repo is in the process of being migrated
- Timestamp for Event Telemetry in Application Insights Azure Portal get overridden by ingestion time HOT 3
- Initializing TelemetryConfiguration twice can result into DiagnosticListeners to pump events into wrong pipeline HOT 2
- Regression issue: appId is never set in response headers HOT 2
- 2.7.1 and 2.8.0-beta1 throws NullReferenceException when used together with AspNetCore 3.0 preview8 HOT 6
- How to disable SQL logging for Azure Functions? HOT 1
- Can I delete Application Insights from project file properties and Connected Services folder? HOT 2
- Question: Is it possible to emit CustomEvent from the ILogger? (by using EventId) HOT 1
- Proposal: Skip version to be in sync with BaseSDK HOT 2
- Direct Use of TelemetryClient best practices? HOT 1
- System.ObjectDisposedException when trying to read request.Body HOT 2
- Conflicts Between Versions Using Asp.Net Core 3.0 HOT 2
- Provide disable/enable flag in ApplicationInsightsServiceOptions for each TelemetryModule present in default list.
- null/Empty ikey from AIServiceOptions is overriding ikey from appsettings.json
- Microsoft.ApplicationInsights.WorkerService - Log4NetAppender Issue HOT 1
- Correct correlation for Microsoft.Azure.Storage.DataMovement HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from applicationinsights-aspnetcore.