-
Notifications
You must be signed in to change notification settings - Fork 123
Make using of TelemetryConfiguration.Active singleton optional #227
Comments
We had it optional but putting it in the API was sub optimal so we removed it again. |
same app domain. You can run multiple apps in a single process. tests runs asynchronously and re-use shared configuration. So there may be random failures when telemetry item sent by one test is received in StubChannel by another test. |
Just to be clear, the process and the app domain are separate and different. The process can be shared, such as shared hosting in IIS, but each app is in a separate app domain (or even more than one). App domains do not share static variables with other apps, even in the same process, because that would make isolation impossible in IIS. |
This code will run two applications in a single process in a single domain: this.hostingEngine = CreateBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://localhost:8080")
.UseKestrel()
.UseStartup(assemblyName)
.UseEnvironment("Production")
.Build();
this.hostingEngine = CreateBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://localhost:8081")
.UseKestrel()
.UseStartup(assemblyName)
.UseEnvironment("Production")
.Build(); This is an extreme case, but asp.net core is designed for this use. So we should allow telemetry to be adjusted for this use |
Okay, I understand the edge case in question, someone writes one app that creates multiple self-host endpoints and wants each endpoint to report to a different iKey. |
This edge case could easily happen in a Service Fabric application. For example if you had different named instances of the same stateless ASP.NET Core service type, they could all end up in the same process (and more importantly in the same app domain). Another reason for this is infra code that is shared between ASP.NET Core and non-ASP.NET Core services. That code has to know now whether ASP.NET Core AI is active, so as to avoid adding initializers, modules, and processors that will be added by ASP.NET Core AI (if it doesn't, they will end up twice in the configuration, which in most/all cases would be undesirable). IMO when |
@ohadschn I agree those scenarios increases the priority of this work. Having nested configuration settings is a good idea. However there should be a way to gain a full control on the configuration for specific app. Thank you! We will be discussing the best options for configuration story improvements with aspnet team. Meanwhile if it's blocking your scenario - feel free to send PR to fix it by passing a flag to |
#622 I do not think a configuration flag is an option as in shared process scenario app breaks throwing before sending HTTP request or the whole AI pipeline just becomes noop after TelemteryConfiguration.Active.TelemetryChannel is disposed. |
So what is the recommendation if one is forced to use We are building an Azure Cloud Service with a Worker Role where one must use the According to comments in the #622 PR it should be fine to first configure via I'd prefer an alternative to using the static |
@EnCey there is no requirement to use Active on worker roles. As long as you are using AspNetCore you can set instrumentation key via appsettings.json, environment variable or in code by supplying it to In non-AspNetCore environments or telemetry reported before the host is built, you can create and setup TelemteryConfiguration manually in the code. It could be We discourage anyone from using static singletons except cases where there is no dependency injection available - ASP.NET Classic applications or pure Console apps, but it's your choice what to use. Could you please tell me more about the scenario and concern you have? |
I'd like to create a I'd be happy to stop using the In short: we don't have "just" AspNetCore. AspNetCore specific Perhaps this makes more sense: what is the recommended way to configure AI for both AspNetCore and other components? Should we use |
Is there an ETA on this? It's breaking out Integration tests as per Microsoft/ApplicationInsights-dotnet#613. |
#613 and #621 are fixed. #613 with AppInsights AspnetCore 2.3.0 and #621 with 2.6.0-beta3 (not stable yet). AppInsights AspNetCore SDK creates TelemetryConfiguration per host since 2.3.0 and only sets up Active once per process lifetime. I would not expect any issues with integration tests at the moment related to this issue if you run 2.3.0 or higher. If you do, please create another issue and provide the details. @EnCey If you need a custom configuration, you may create a new configuration and pass it over to other parts of service using DI or any other way you want. If you want to affect how auto-collectors report telemetry, you may tweak TelemetryConfiguration created by AppInsights for AspNetCore - you can find examples in the wiki. None of this affects dependency collection (unless you configure DependencyTrackingTelemetryModule differently). I think this issue could be closed now since Active singleton is no longer used by AppInsights for AspNetCore. |
@lmolkova thanks for getting back on this. The fundamental problem that I see is that there is an We have a separate config for our AspNetCore project that is used by the worker role and use DI here. The thing is, we have other projects that are independent from AspNetCore. They have their own entry points so no config can "flow" via execution contexts (e.g. Redis pub/sub). As a result, no AspNetCore config can work there. I realize that all of this is a Cloud Service issue and not an AspNetCore one; I just wished there would have been a way to pass a |
we need to make use of TC.Active singleton optional so you can host multiple apps in the same process. Also it will make unit tests better
The text was updated successfully, but these errors were encountered: