Sitelet https://github.com/microsoft/ApplicationInsights-dotnet/issues/2194
Skip to content

HttpCoreDiagnosticSourceListener errors when events are raised from a different library #2194

Description

  • ApplicationInsight version: 2.17 (Latest)
  • .NET 5

Describe the bug

Grpc.Net.Client raises events that HttpCoreDiagnosticSourceListener listens to. The problem is that TypedFetchProperty assumes that the type passed here will always be the same. Grpc.Net.Client has a copy of the types passed to the listener.

var typedPropertyFetcher = typeof(TypedFetchProperty<,>);
var instantiatedTypedPropertyFetcher = typedPropertyFetcher.GetTypeInfo().MakeGenericType(
propertyInfo.DeclaringType, propertyInfo.PropertyType);
return (PropertyFetch)Activator.CreateInstance(instantiatedTypedPropertyFetcher, propertyInfo);

If System.Net.Http raises the events with one type, and Grpc.Net.Client raises the events with a different type, then TypedFetchProperty throws an error.

AI (Internal): [Microsoft-ApplicationInsights-Extensibility-DependencyCollector] HttpCoreDiagnosticSourceListener OnNext failed to call event handler. Error details 'System.InvalidCastException: [A]ActivityStartData cannot be cast to [B]ActivityStartData. Type A originates from 'Grpc.Net.ClientFactory, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad' in the context 'Default' at location '/app/Grpc.Net.ClientFactory.dll'.
Type B originates from 'System.Net.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location '/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.4/System.Net.Http.dll'.
   at Microsoft.ApplicationInsights.Common.PropertyFetcher.PropertyFetch.TypedFetchProperty`2.Fetch(Object obj)
   at Microsoft.ApplicationInsights.DependencyCollector.Implementation.HttpCoreDiagnosticSourceListener.OnNext(KeyValuePair`2 evnt)'

To Reproduce

With AI configured, make a web request with HttpClient, and make a gRPC request with Grpc.Net.Client.

Whichever library makes the second request will fail because TypedFetchProperty has been created against the other libraries copy of the event objects.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions