From 86ad159082cb999f58e232dfd107fde94db92e5a Mon Sep 17 00:00:00 2001 From: Vivek Mahajan Date: Wed, 18 Oct 2023 17:28:27 +0200 Subject: [PATCH 1/6] Fix issue --- .../kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala b/core/kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala index 0133bc199..cba6fb06d 100644 --- a/core/kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala +++ b/core/kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala @@ -450,7 +450,7 @@ object W3CTraceContext { * https://docs.datadoghq.com/tracing/guide/send_traces_to_agent_by_api/ */ def decodeUnsignedLongToHex(id: String): String = - urlDecode(id).toLong.toHexString + Long.parseUnsignedLong(urlDecode(id), 10).toHexString } class DataDog extends Propagation.EntryReader[HeaderReader] with Propagation.EntryWriter[HeaderWriter] { From c9f360c1e1408b609f094ceaf703a31eec602504 Mon Sep 17 00:00:00 2001 From: Vivek Mahajan Date: Thu, 19 Oct 2023 10:34:26 +0200 Subject: [PATCH 2/6] import Long --- .../src/main/scala/kamon/trace/SpanPropagation.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala b/core/kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala index cba6fb06d..77034f739 100644 --- a/core/kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala +++ b/core/kamon-core/src/main/scala/kamon/trace/SpanPropagation.scala @@ -24,6 +24,7 @@ import kamon.context.HttpPropagation.{HeaderReader, HeaderWriter} import kamon.context.generated.binary.span.{Span => ColferSpan} import kamon.context.{Context, _} import kamon.trace.Trace.SamplingDecision +import java.lang.{Long => JLong} import scala.util.Try @@ -450,7 +451,7 @@ object W3CTraceContext { * https://docs.datadoghq.com/tracing/guide/send_traces_to_agent_by_api/ */ def decodeUnsignedLongToHex(id: String): String = - Long.parseUnsignedLong(urlDecode(id), 10).toHexString + JLong.parseUnsignedLong(urlDecode(id), 10).toHexString } class DataDog extends Propagation.EntryReader[HeaderReader] with Propagation.EntryWriter[HeaderWriter] { From 7b37b4bc2cc1871cda72c982955a9a18a9040dac Mon Sep 17 00:00:00 2001 From: Vivek Mahajan Date: Thu, 19 Oct 2023 10:48:51 +0200 Subject: [PATCH 3/6] Add tests --- .../trace/DataDogSpanPropagationSpec.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala b/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala index 8a22c1fd5..c5ad3749a 100644 --- a/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala +++ b/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala @@ -118,6 +118,23 @@ class DataDogSpanPropagationSpec extends AnyWordSpec with Matchers with OptionVa } } + + "Testing SpanPropagation.DataDog.decodeUnsignedLongToHex" should { + "works as expected " in { + String expectedHex1 = "0"; + String actualHex1 = dataDogPropagation.decodeUnsignedLongToHex("0"); + assertEquals(expectedHex1, actualHex1); + + String expectedHex2 = "ff"; + String actualHex2 = dataDogPropagation.decodeUnsignedLongToHex("255"); + assertEquals(expectedHex2, actualHex2); + + String expectedHex3 = "c5863f7d672b65bf"; + String actualHex3 = dataDogPropagation.decodeUnsignedLongToHex("14233133480185390527"); + assertEquals(expectedHex1, actualHex1); + } + } + def unsignedLongString(id: String): String = BigInt(id, 16).toString def headerReaderFromMap(map: Map[String, String]): HttpPropagation.HeaderReader = new HttpPropagation.HeaderReader { From a2e05a399380bd63757240b4a9fb683e367b4aa4 Mon Sep 17 00:00:00 2001 From: Vivek Mahajan Date: Thu, 19 Oct 2023 10:51:37 +0200 Subject: [PATCH 4/6] fix test name --- .../test/scala/kamon/trace/DataDogSpanPropagationSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala b/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala index c5ad3749a..814537a62 100644 --- a/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala +++ b/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala @@ -119,8 +119,8 @@ class DataDogSpanPropagationSpec extends AnyWordSpec with Matchers with OptionVa } - "Testing SpanPropagation.DataDog.decodeUnsignedLongToHex" should { - "works as expected " in { + "SpanPropagation.DataDog.decodeUnsignedLongToHex" should { + "decode unsigned long to expected hex value " in { String expectedHex1 = "0"; String actualHex1 = dataDogPropagation.decodeUnsignedLongToHex("0"); assertEquals(expectedHex1, actualHex1); From ca58124fb4551b1eb79381f3eb207196b885e0a9 Mon Sep 17 00:00:00 2001 From: Vivek Mahajan Date: Thu, 19 Oct 2023 13:00:28 +0200 Subject: [PATCH 5/6] checking upper bound --- .../test/scala/kamon/trace/DataDogSpanPropagationSpec.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala b/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala index 814537a62..389f41b4c 100644 --- a/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala +++ b/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala @@ -132,6 +132,11 @@ class DataDogSpanPropagationSpec extends AnyWordSpec with Matchers with OptionVa String expectedHex3 = "c5863f7d672b65bf"; String actualHex3 = dataDogPropagation.decodeUnsignedLongToHex("14233133480185390527"); assertEquals(expectedHex1, actualHex1); + + String expectedHex4 = "ffffffffffffffff"; + String actualHex4 = dataDogPropagation.decodeUnsignedLongToHex("18446744073709551615"); + assertEquals(expectedHex4, actualHex4); + } } From b6dffc601a1e59606d02725316fa47a5ca520c09 Mon Sep 17 00:00:00 2001 From: Vivek Mahajan Date: Thu, 19 Oct 2023 15:51:58 +0200 Subject: [PATCH 6/6] fix tests --- .../trace/DataDogSpanPropagationSpec.scala | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala b/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala index 389f41b4c..3cfb1682f 100644 --- a/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala +++ b/core/kamon-core-tests/src/test/scala/kamon/trace/DataDogSpanPropagationSpec.scala @@ -121,21 +121,21 @@ class DataDogSpanPropagationSpec extends AnyWordSpec with Matchers with OptionVa "SpanPropagation.DataDog.decodeUnsignedLongToHex" should { "decode unsigned long to expected hex value " in { - String expectedHex1 = "0"; - String actualHex1 = dataDogPropagation.decodeUnsignedLongToHex("0"); - assertEquals(expectedHex1, actualHex1); + val expectedHex1 = "0"; + val actualHex1 = SpanPropagation.DataDog.decodeUnsignedLongToHex("0"); + expectedHex1 shouldBe actualHex1; - String expectedHex2 = "ff"; - String actualHex2 = dataDogPropagation.decodeUnsignedLongToHex("255"); - assertEquals(expectedHex2, actualHex2); + val expectedHex2 = "ff"; + val actualHex2 = SpanPropagation.DataDog.decodeUnsignedLongToHex("255"); + expectedHex2 shouldBe actualHex2; - String expectedHex3 = "c5863f7d672b65bf"; - String actualHex3 = dataDogPropagation.decodeUnsignedLongToHex("14233133480185390527"); - assertEquals(expectedHex1, actualHex1); + val expectedHex3 = "c5863f7d672b65bf"; + val actualHex3 = SpanPropagation.DataDog.decodeUnsignedLongToHex("14233133480185390527"); + expectedHex3 shouldBe actualHex3; - String expectedHex4 = "ffffffffffffffff"; - String actualHex4 = dataDogPropagation.decodeUnsignedLongToHex("18446744073709551615"); - assertEquals(expectedHex4, actualHex4); + val expectedHex4 = "ffffffffffffffff"; + val actualHex4 = SpanPropagation.DataDog.decodeUnsignedLongToHex("18446744073709551615"); + expectedHex4 shouldBe actualHex4; } }