withContext<T> method

Future<T> withContext<T>(
  1. String transactionId,
  2. Map<String, dynamic> attributes,
  3. Future<T> operation()
)

Run code with a specific transaction context

Implementation

Future<T> withContext<T>(
  String transactionId,
  Map<String, dynamic> attributes,
  Future<T> Function() operation,
) async {
  final context = TransactionContext(
    transactionId: transactionId,
    attributes: attributes,
  );

  pushContext(context);
  try {
    return await operation();
  } finally {
    popContext();
  }
}