From 4e36915c202bea39e3644e10f72fb1402d8af893 Mon Sep 17 00:00:00 2001 From: a-h-mzd Date: Tue, 5 Nov 2024 14:40:25 +0100 Subject: [PATCH 1/2] fix max int generation on web to use `-1 >> 0` --- .../lib/src/tracing/tracing_headers.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart b/packages/datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart index 80c33b59..6b39ed5b 100644 --- a/packages/datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart +++ b/packages/datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart @@ -145,6 +145,8 @@ class TracingId { TracingId.spanId() : value = _generateSpanId(); + static const _maxInt = kIsWeb ? -1 >> 0 : 1 << 32; + /// Generate a 128-bit Trace Id. /// /// The trace is generated within the range: @@ -152,8 +154,8 @@ class TracingId { static BigInt _generateTraceId() { final time = (DateTime.now().millisecondsSinceEpoch ~/ 1000); - final highBits = BigInt.from(_traceRandom.nextInt(1 << 32)); - final lowBits = BigInt.from(_traceRandom.nextInt(1 << 32)); + final highBits = BigInt.from(_traceRandom.nextInt(_maxInt)); + final lowBits = BigInt.from(_traceRandom.nextInt(_maxInt)); var traceId = BigInt.from(time) << 96; traceId += (highBits << 32); @@ -168,7 +170,7 @@ class TracingId { // we assume it needs to be a positive signed 64-bit int, so only // use 63-bits. final highBits = _traceRandom.nextInt(1 << 31); - final lowBits = BigInt.from(_traceRandom.nextInt(1 << 32)); + final lowBits = BigInt.from(_traceRandom.nextInt(_maxInt)); var spanId = BigInt.from(highBits) << 32; spanId += lowBits; From 7c0fd59f63403a803c95e45cbd8f59c113a2f36d Mon Sep 17 00:00:00 2001 From: a-h-mzd Date: Tue, 5 Nov 2024 14:51:23 +0100 Subject: [PATCH 2/2] fix max int calculation on web to ensure same result is generate on both web and native --- .../datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart b/packages/datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart index 6b39ed5b..2068cb34 100644 --- a/packages/datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart +++ b/packages/datadog_flutter_plugin/lib/src/tracing/tracing_headers.dart @@ -145,7 +145,7 @@ class TracingId { TracingId.spanId() : value = _generateSpanId(); - static const _maxInt = kIsWeb ? -1 >> 0 : 1 << 32; + static const _maxInt = kIsWeb ? (-1 >> 0) + 1 : 1 << 32; /// Generate a 128-bit Trace Id. ///