Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JamesNK opened this issue Mar 26, 2021 · 3 comments
Labels

Comments

@JamesNK
Copy link
Member

JamesNK commented Mar 26, 2021

  • 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.

@metoule
Copy link

metoule commented Jul 9, 2021

I'm seeing this exact exception when deploying an Azure Function with the dotnet-isolated runtime. When can we expect a new version of the AppInsights package that contains the fix?

@jrgcubano
Copy link

same here @metoule

@metoule
Copy link

metoule commented Jul 15, 2021

Actually I found that version 2.18.0-beta1 and up contain the fix! If you can't / don't want to use a beta version, the 2.18 milestone says to expect the 2.18 release on July 30th.

I currently use version 2.18-beta3 from Nuget (I had to select the "Include prerelease" checkbox in the Visual Studio Nuget UI), and it's working great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants