Sitelet https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/621
Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Request and dependency telemetry is tracked by each Webhost in the app #621

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions