Multiple WebHosts could run in the same process.
This scenario is possible with any ASP.NET Core app and when using the Shared Process hosting model in ServiceFabric
In this case AppInsights services are added to each service provider, however, singletons that track requests and dependencies are static and process-wide - they are not aware of WebHost boundaries.
So the requests and dependencies are tracked by multiple DiagnostiSource subscribers - one per web host.
Repro Steps
Ignored functional test in AspNetCore2.0 app will be added shortly
using (var server1 = new InProcessServer(assemblyName, this.output))
using (var server2 = new InProcessServer(assemblyName, this.output))
{
this.ExecuteRequest(server1.BaseHost + requestPath);
var telemetry1 = server1.Listener.ReceiveItems(TestListenerTimeoutInMs);
this.ExecuteRequest(server2.BaseHost + requestPath);
var telemetry2 = server2.Listener.ReceiveItems(TestListenerTimeoutInMs);
Assert.Single(telemetry1.Where(t => t is TelemetryItem<RequestData>));
Assert.Single(telemetry1.Where(IsServiceDependencyCall));
Assert.DoesNotContain(telemetry1, t => t is TelemetryItem<ExceptionData>);
var request1 = telemetry1.Single(t => t is TelemetryItem<RequestData>);
Assert.Equal("200", ((TelemetryItem<RequestData>)request1).data.baseData.responseCode);
// Fails here, we track everything twice
// it did not happen with the first host because second one has not been really started yet
Assert.Single(telemetry2.Where(t => t is TelemetryItem<RequestData>));
Assert.Single(telemetry2.Where(IsServiceDependencyCall));
Assert.DoesNotContain(telemetry2, t => t is TelemetryItem<ExceptionData>);
var request2 = telemetry2.Single(t => t is TelemetryItem<RequestData>);
Assert.Equal("200", ((TelemetryItem<RequestData>)request2).data.baseData.responseCode);
}
Actual Behavior
each webhost tracks requests and depedencies of all running web hosts
Expected Behavior
We should not re-create diagnostic listeners if there is an active one.
This blocks scenario with web hosts from having different configurations: imagine a different set of ikeys or telmetryinitializers/processors. I'm not sure it's feasible to support this scenario (even if feasible, it's much harder to implement), in this case, there could a listener per webhost, but the listener must only track its own webhost telemetry.
Multiple WebHosts could run in the same process.
This scenario is possible with any ASP.NET Core app and when using the Shared Process hosting model in ServiceFabric
In this case AppInsights services are added to each service provider, however, singletons that track requests and dependencies are static and process-wide - they are not aware of WebHost boundaries.
So the requests and dependencies are tracked by multiple DiagnostiSource subscribers - one per web host.
Repro Steps
Ignored functional test in AspNetCore2.0 app will be added shortly
Actual Behavior
each webhost tracks requests and depedencies of all running web hosts
Expected Behavior
We should not re-create diagnostic listeners if there is an active one.
This blocks scenario with web hosts from having different configurations: imagine a different set of ikeys or telmetryinitializers/processors. I'm not sure it's feasible to support this scenario (even if feasible, it's much harder to implement), in this case, there could a listener per webhost, but the listener must only track its own webhost telemetry.