Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

hex span id serialization, more test cases #169

Closed
wants to merge 2 commits into from
Closed

hex span id serialization, more test cases #169

wants to merge 2 commits into from

Conversation

mhindery
Copy link

@mhindery mhindery commented Jul 7, 2019

What version of OpenCensus are you using?

  • opencensus-python [0.6.0]
  • opencensus-go 0.22.0; stackdriver-exporter 0.10.0

What version of Go are you using?

go version go1.11.5 darwin/amd64

What did you do?

The span ID is a 64-bit id (confusing sidenote, the specs here claim it to be 8 bit). Both the Python (16-char hex encoded string) and Go (8-byte array) implementation generate this correctly.

However, there is an incompatibility in the propagation of traces. What the Python code does with the GoogleCloudFormatPropagator is put the span_id (which is a string type with hexadecimal chars) as string in the header. Then the header is something like

X-Cloud-Trace-Context: 129b452d2ef458f798c10811e2c28cf6/14a650d3b8b5ddde;o=1

Now the propagation code in Go expects an integer, as what the stackdriver exporter tries to do is parse that hexadecimal string as an integer with

sid, err := strconv.ParseUint(spanstr, 10, 64)

This throws an error, leading the trace propagation to fail and traces being separated between services. Similarly, when creating a header for propagation in Go, it does put it in there as an integer number instead of the hexadecimal representation:

sid := binary.BigEndian.Uint64(sc.SpanID[:])
header := fmt.Sprintf("%s/%d;o=%d", hex.EncodeToString(sc.TraceID[:]), sid, int64(sc.TraceOptions))

As a fix, I changed the (de)serialization to use hexadecimal representations. I also added some tests for different valid and invalid cases.

As a related but important note, which I'll raise in the Python repo as well: there's a difference in behaviour in parsing the headers. Python uses a regex which only matches exactly 16 characters as span id. The Go code doesn't use that regex (or any other), but works with splitting on separators and happily accepts a span id which is shorter than 16 characters. It will also propagate that shorter span ID further. The result is that the trace propagation fails between services in the different langauges. Should this behaviour be equalized between langauges?

Review by @rakyll and/or @Ramonza ?

@rghetia
Copy link
Contributor

rghetia commented Jul 16, 2019

@mhindery according this doc spanId should be decimal.
For first span it should be 0. example copied from the doc

curl "http://www.example.com" --header "X-Cloud-Trace-Context:
  105445aa7843bc8bf206b120001000/0;o=1"

@mhindery
Copy link
Author

Allright, then I'll push to change this over in the python repo. This one can be closed then I suppose?

@rghetia
Copy link
Contributor

rghetia commented Jul 16, 2019

Allright, then I'll push to change this over in the python repo. This one can be closed then I suppose?

yes.

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

Successfully merging this pull request may close these issues.

4 participants