publishFlutterActionContext method

  1. @override
Future<void> publishFlutterActionContext(
  1. dynamic spanContext,
  2. Duration window
)
override

Publishes the current user-action span context to native along with an expiry (window from now), so native span creators can parent to it while the action window is open.

Implementation

@override
Future<void> publishFlutterActionContext(
  dynamic spanContext,
  Duration window,
) async {
  if (spanContext is! SpanContext || !spanContext.isValid) {
    return;
  }
  // Wall-clock expiry: Dart and native share the system clock, so an absolute
  // epoch-millis deadline lets native decide non-expiry without a round trip.
  final expiresAtMillis =
      DateTime.now().add(window).millisecondsSinceEpoch;
  await methodChannel.invokeMethod('updateFlutterActionContext', {
    ...spanContext.toJson(),
    'expiresAtMillis': expiresAtMillis,
  });
}