OTLP Exporter collects zero metrics on .NET MAUI Android AOT- System.Diagnostics.Metrics registration fails #6884
-
System.Diagnostics.Metrics completely fails under .NET MAUI Android AOTProblem SummaryI'm experiencing complete failure of Environment
Configurationservices.AddOpenTelemetry() .ConfigureResource(resource => resource .AddService("MobileApp", serviceVersion: "1.0.0") .AddAttributes(new Dictionary<string, object> { { "device.platform", "android" }, { "device.os", DeviceInfo.Platform.ToString() }, { "device.model", DeviceInfo.Model } })) .WithMetrics(metrics => metrics .AddMeter("Mobile") .AddView("photo.capture.time", new ExplicitBucketHistogramConfiguration { Boundaries = new double[] { 100, 200, 300, 500, 1000, 2000, 5000, 10000 } }) .AddOtlpExporter(options => { options.Endpoint = new Uri("https://my-backend.com/metrics"); options.Protocol = OtlpExportProtocol.HttpProtobuf; })); // Create meters and instruments var meter = new Meter("Mobile", "1.0.0"); var appLaunchCounter = meter.CreateCounter<long>("app.launch.total", "1", "Total app launches"); var photoCaptureTime = meter.CreateHistogram<double>("photo.capture.time", "ms", "Photo capture time"); // Record metrics appLaunchCounter.Add(1); photoCaptureTime.Record(1234.5);Behavior ComparisonDebug Build (works perfectly)Diagnostic output: Release Build with AOT (complete failure)Diagnostic output: Root Cause AnalysisI've traced this to the BCL level - when To confirm this is not an OpenTelemetry issue, I created a simple test exporter: public class ConsoleTestMetricExporter : BaseExporter<Metric> { public override ExportResult Export(in Batch<Metric> batch) { var count = 0; foreach (var metric in batch) { count++; Console.WriteLine($"Metric: {metric.Name}, Value: {metric}"); } Console.WriteLine($"[CONSOLE-EXPORTER] Batch size: {count}"); if (count == 0) { Console.WriteLine("[CONSOLE-EXPORTER] ⚠️ EMPTY BATCH"); } return ExportResult.Success; } }The exporter is called correctly, but the batch is always empty in AOT builds. What I've Tried
None of these affect the core issue: meters don't register in Questions
Related Issues
Additional ContextI can provide full diagnostic logs, sample project, or any other information that would be helpful. The failure is 100% reproducible - Debug builds always work, Release+AOT builds always fail with empty metric batches. Thank you for any guidance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Yes, if you're confident the root cause is there.
Not that I'm aware of - the .NET OpenTelemetry SDK builds on top of the .NET APIs (
I would hold off on that until you've filed a bug with dotnet/runtime - if it's a easily fixable bug that can be backported to servicing branches, then you may only need to wait ~2 months for a patch that fixes it. FYI we have zero CI/test coverage for MAUI scenarios (see #5831). We do however have test coverage for native AoT. |
Beta Was this translation helpful? Give feedback.
I've opened a ticket in the dotnet repo and it turned out that there is a parameter which disables metrics in release configuration for Android/iOS:
https://learn.microsoft.com/en-us/dotnet/ios/building-apps/build-properties#metricssupport
So
<MetricsSupport>true</MetricsSupport>solves the problem.