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

Support for Xamarin.Android #3101

Closed
Falco20019 opened this issue Mar 29, 2022 · 9 comments
Closed

Support for Xamarin.Android #3101

Falco20019 opened this issue Mar 29, 2022 · 9 comments
Labels
enhancement New feature or request

Comments

@Falco20019
Copy link

Falco20019 commented Mar 29, 2022

Feature Request

When using Xamarin.Android with OpenTelemetry.Exporter.OpenTelemetryProtocol, you are limited in what Grpc.Net.Client can do due to what's explained here: https://docs.microsoft.com/en-us/aspnet/core/grpc/supported-platforms?view=aspnetcore-6.0#net-grpc-client-requirements

Grpc.Core on the other side still works fine with Android.

What do you want to happen instead? What is the expected behavior?

OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj can add another TargetFramework for monoandroid80 which is compatible to all netstandard2.0 dependencies (see https://dotnet.microsoft.com/en-us/platform/dotnet-standard). The projects SDK just needs to be changed from Microsoft.NET.Sdk to MSBuild.Sdk.Extras/3.0.44 to be able to build the new csproj format for Android until .net7 is released later this year.

Which alternative solutions or features have you considered?

I tried different options to use netstandard2.0 instead without success. Due to NuGet resolving dependencies on a nearest-win strategy, it will always use the netstandard2.1 route and therefore try to use Grpc.Net.Client which does not work well on Android.

Alternatively to allow using Grpc.Net.Client.Web we would need to be able to control the GrpcChannelOptions which is currently not possible with this library.

Additional Context

For now, I wanted to implement the workaround described here: https://docs.microsoft.com/en-us/aspnet/core/grpc/netstandard?view=aspnetcore-6.0 which if failing due to the inability to configure the GrpcChannelOptions.

This would at least allow me do use the library as is, but will still include and use Grpc.Net.Client although my application is currently using Grpc already everywhere else.

I know that Grpc.Core is close to the end of it's life, but there is currently no good support from Microsoft/Google on Grpc.Net.Client for Android. There are some pending open issues, but it's mainly due to Android not being able to use HTTP/2 fully. So the Xamarin.Android (and also Xamarin.iOS) team has to do some more work. This is sadly also true for the upcoming net7.0-android stuff.

@Falco20019 Falco20019 added the enhancement New feature or request label Mar 29, 2022
@Falco20019
Copy link
Author

Falco20019 commented Mar 29, 2022

I will try to use the OtlpExportProtocol.HttpProtobuf for now to circumvent the issue. But this leads to some other issues here, since I also wanted to have a way to store the traces into a local file (for Android). In the past with OpenTracing, I just piped the data to a local gRPC server through the Jaeger client and wrote the data away.

With the current OtlpTraceExporter I sadly have no option to just attach my own IExportClient directly, since it would need to make a huge amount of the API public. It would be great, if we could at least make the pre-processed OtlpCollector.ExportTraceServiceRequest accessible in some way. With that, I would not even need gRPC at all.

Right now, all routes are blocked (gRPC service workaround due to neither being able to use old gRPC or using Grpc.Net.Client.Web and direct usage since everything is internal only).

@kwkgaya
Copy link

kwkgaya commented Apr 4, 2022

We have done a spike on trying open telemetry dotnet on xamarin.
There are several other issues as well

  • Self log uses System.Diagnostics.Tracing.EventSource which is not supported on xamarin
  • Reflection.Emit is used for tracing support
  • Linking issues when building Xamarin.iOS application

@Falco20019
Copy link
Author

Thanks for the info. That's a downer, seems that we need to stick with Jaeger then.

@Falco20019
Copy link
Author

Do we already know if this is supported by .NET MAUI or net6-android? Or is this running into the same issues as mentioned above?

@kwkgaya
Copy link

kwkgaya commented Jun 8, 2022

I'm not sure about that. But I guess it is the same result, because the runtime is essentially the same.

@Falco20019
Copy link
Author

Falco20019 commented Jun 30, 2022

I did some quick tests and it looks promising. Also found a blog post (https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-5/) that since .NET 6 Preview 5 the mentioned classes had been added. But we are still out of look for using OTEL since we are still stuck with Grpc.Core due to Microsoft still not bringing ASP.NET runtime to Android.

If

would allow to configure GrpcChannelOptions and pass it to GrpcChannel.ForAddress, we would be able to pass it the new GrpcWebHandler(new HttpClientHandler()) necessary on Android.

I will also do some more tests to ensure, this is still necessary.

@Falco20019
Copy link
Author

OK, did some more tests with creating the server with Grpc.Core (since we are stuck) and connecting with GrpcChannel. Everything works fine now on .NET 6 without the need to use the GrpcWebHandler. OTEL should therefore be really now usable with .NET 6 🎉

I will close this, as we do not need Xamarin.Android support anymore and since it seems to work with .NET 6 Android.

@cijothomas
Copy link
Member

We have done a spike on trying open telemetry dotnet on xamarin. There are several other issues as well

  • Self log uses System.Diagnostics.Tracing.EventSource which is not supported on xamarin
  • Reflection.Emit is used for tracing support
  • Linking issues when building Xamarin.iOS application

The above are unresolved, right?

@Falco20019
Copy link
Author

Falco20019 commented Jul 1, 2022

EventSource and Emit seem to work on .NET 6 Android. According to the blog post, they were added in Preview 5. Not sure if it's also true for iOS. Also don't know about the linking issues for iOS since I don't use iOS in my tests. Especially https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-5/#diagnostics-eventpipe-diagnosticsserver-monovm should be an interesting read.

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

No branches or pull requests

3 participants