Repository: flutter
Issue: Proposal to collect DebugCreator details for release builds
Labels: c: new feature,framework,c: proposal,a: error message,a: release,P3,team-framework,triaged-framework

Because of performance considerations, it does not collect DebugCreator information on release mode, such as:
```dart
  try {
    element.rebuild();
  } catch (e, stack) {
    _debugReportException(
      ErrorDescription('while rebuilding dirty elements'),
      e,
      stack,
      informationCollector: () => <DiagnosticsNode>[
        if (kDebugMode)
          DiagnosticsDebugCreator(DebugCreator(element)),
      ],
    );
  }
```

However, there are some online error without more useful information, which makes it difficult to troubleshoot where causes the error, such as the below case, we don't know anymore other details except a framework stack trace.
```dart
Null check operator used on a null value
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞════════════════════════
The following _CastError was thrown building Widget:
Null check operator used on a null value
When the exception was thrown, this was the stack:
#0      ContainerRenderObjectMixin._insertIntoChildList (package:flutter/src/rendering/object.dart:3211)
#1      ContainerRenderObjectMixin.insert (package:flutter/src/rendering/object.dart:3243)
#2      MultiChildRenderObjectElement.insertRenderObjectChild (package:flutter/src/widgets/framework.dart:6065)
#3      RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:5674)
#4      RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5365)
#5      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5986)
#6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3546)
#7      Element.updateChild (package:flutter/src/widgets/framework.dart:3311)
#8      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4525)
#9      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4672)
#10     Element.rebuild (package:flutter/src/widgets/framework.dart:4194)
#11     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4479)
#12     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4663)
#13     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4474)
#14     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3546)
#15     Element.updateChild (package:flutter/src/widgets/framework.dart:3311)
#16     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4525)
#17     Element.rebuild (package:flutter/src/widgets/framework.dart:4194)
#18     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4479)
#19     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4474)
#20     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3546)
#21     Element.updateChild (package:flutter/src/widgets/framework.dart:3311)
#22     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4525)
#23     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4672)
#24     Element.rebuild (package:flutter/src/widgets/framework.dart:4194)
#25     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4479)
#26     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4663)
#27     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4474)
#28     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3546)
#29     Element.updateChild (package:flutter/src/widgets/framework.dart:3311)
#30     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4525)
#31     Element.rebuild (package:flutter/src/widgets/framework.dart:4194)
#32     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4479)
#33     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4474)
#34     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3546)
#35     Element.updateChild (package:flutter/src/widgets/framework.dart:3311)
#36     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4525)
#37     Element.rebuild (package:flutter/src/widgets/framework.dart:4194)
#38     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4479)
#39     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4474)
#40     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3546)
#41     Element.updateChild (package:flutter/src/widgets/framework.dart:3311)
#42     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4525)
#43     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4672)
#44     Element.rebuild (package:flutter/src/widgets/framework.dart:4194)
#45     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4479)
#46     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4663)
#47     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4474)
#48     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3546)
#49     Element.updateChild (package:flutter/src/widgets/framework.dart:3311)
#50     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5572)
#51     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6118)
#52     Element.updateChild (package:flutter/src/widgets/framework.dart:3298)
#53     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4525)
#54     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4672)
#55     Element.rebuild (package:flutter/src/widgets/framework.dart:4194)
#56     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2694)
#57     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:893)
#58     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:322)
#59     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1176)
#60     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1114)
#61     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1030)
#65     _invoke (dart:ui/hooks.dart:204)
#66     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:253)
#67     _drawFrame (dart:ui/hooks.dart:123)
(elided 3 frames from dart:async)
═════════════════════════════════════════════════════════════════
```

So, can we also collect DebugCreator information in release mode when error occurs in order to facilitate troubleshooting of such online problems?  

Considering that the DebugCreator information is only collected when errors are reported, the performance impact should not be significant. And we can also add a switch that the developer can turn on or off by themselves. Now, we also used this feature in our internal flutter framework sdk, could you have more advice about it? Thanks.
<img width="812" alt="Screen Shot 2022-04-26 at 8 27 48 PM" src="https://user-images.githubusercontent.com/4476512/165301201-61afa409-1110-430d-bad0-a541c5c0d3e4.png">

Related issue https://github.com/flutter/flutter/issues/102282.