Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly parse unsigned integer trace id #1305

Merged
merged 7 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ class DataDogSpanPropagationSpec extends AnyWordSpec with Matchers with OptionVa
}
}


"SpanPropagation.DataDog.decodeUnsignedLongToHex" should {
"decode unsigned long to expected hex value " in {
val expectedHex1 = "0";
val actualHex1 = SpanPropagation.DataDog.decodeUnsignedLongToHex("0");
expectedHex1 shouldBe actualHex1;

val expectedHex2 = "ff";
val actualHex2 = SpanPropagation.DataDog.decodeUnsignedLongToHex("255");
expectedHex2 shouldBe actualHex2;

val expectedHex3 = "c5863f7d672b65bf";
val actualHex3 = SpanPropagation.DataDog.decodeUnsignedLongToHex("14233133480185390527");
expectedHex3 shouldBe actualHex3;

val expectedHex4 = "ffffffffffffffff";
val actualHex4 = SpanPropagation.DataDog.decodeUnsignedLongToHex("18446744073709551615");
expectedHex4 shouldBe actualHex4;

}
}

def unsignedLongString(id: String): String = BigInt(id, 16).toString

def headerReaderFromMap(map: Map[String, String]): HttpPropagation.HeaderReader = new HttpPropagation.HeaderReader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -450,7 +451,7 @@ object W3CTraceContext {
* https://docs.datadoghq.com/tracing/guide/send_traces_to_agent_by_api/
*/
def decodeUnsignedLongToHex(id: String): String =
urlDecode(id).toLong.toHexString
JLong.parseUnsignedLong(urlDecode(id), 10).toHexString
}

class DataDog extends Propagation.EntryReader[HeaderReader] with Propagation.EntryWriter[HeaderWriter] {
Expand Down