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

W3C context propagation hex encodes in capital letters causing failure to read the identifiers #985

Closed
pnerg opened this issue Apr 7, 2021 · 1 comment

Comments

@pnerg
Copy link
Contributor

pnerg commented Apr 7, 2021

Issue

When propagating using W3C it hex encodes the identifiers like this:

 def idToHex(identifier: Identifier, length: Int): String = {
      val leftPad = (string: String) => "0" * (length - string.length) + string
      leftPad(identifier.bytes.map("%02X" format _).mkString)
    }

SpanPropagation.scala#L105

"%02X"causes the generated hex to be in capital letters.
According to the W3C specification the identifiers shall be in lowercase.
"HEXDIGLC = DIGIT / "a" / "b" / "c" / "d" / "e" / "f" ; lowercase hex character"

Effect

This breaks when the request is received on the other end as Kamon fails to parse the identifier due to being uppercase
E.g.

  val identityProvider = Identifier.Scheme.Double

  val s = "2f2b727a4a0dcfd8c0bed5f6209f2694"

  println(identityProvider.traceIdFactory.from(s.toLowerCase).isEmpty)
  println(identityProvider.traceIdFactory.from(s.toLowerCase).string)

  println(identityProvider.traceIdFactory.from(s.toUpperCase).isEmpty)
  println(identityProvider.traceIdFactory.from(s.toUpperCase).string)

yields

false
2f2b727a4a0dcfd8c0bed5f6209f2694
true

Solution

Change to leftPad(identifier.bytes.map("%02x" format _).mkString)
Note the 'x' to dictate lower caps.

SimunKaracic added a commit that referenced this issue Apr 9, 2021
hexencode identifiers in lower char for w3c propagation (#985)
@SimunKaracic
Copy link
Contributor

Fixed in 2.1.16!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants