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

Incorrect parsing of a single b3 header #189

Closed
nosan opened this issue Mar 15, 2021 · 0 comments
Closed

Incorrect parsing of a single b3 header #189

nosan opened this issue Mar 15, 2021 · 0 comments

Comments

@nosan
Copy link
Contributor

nosan commented Mar 15, 2021

Hi, I've been trying to parse a single b3 header and found that it has been parsed incorrectly. Please take a look at the following test:

func TestParseSingleHeader(t *testing.T) {
	//https://github.com/openzipkin/b3-propagation#single-header
	m := make(b3.Map)
	//b3={TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
	m[b3.Context] = "80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"
	spanContext, _ := m.Extract()
	assertEqual(t, spanContext.TraceID.String(), "80f198ee56343ba864fe8b2a57d3eff7", "traceId")
	assertEqual(t, spanContext.ID.String(), "e457b5a2e4d86bd1", "spanId")
	assertEqual(t, spanContext.ParentID.String(), "05e3ac9a4f6e3b90", "parentSpanId")
}

func assertEqual(t *testing.T, actual interface{}, expected interface{}, message string) {
	if actual == expected {
		return
	}
	t.Fatal(fmt.Sprintf("%s %v != %v", message, actual, expected))
}
=== RUN   TestParseSingleHeader
    main_test.go:24: traceId 80f198ee56343ba804fe8b2a57d3eff7 != 80f198ee56343ba864fe8b2a57d3eff7
--- FAIL: TestParseSingleHeader (0.00s)

The possible issue is here:

low, err := strconv.ParseUint(contextHeader[pos+1:pos+16], 16, 64)

It should be low, err := strconv.ParseUint(contextHeader[pos:pos+16], 16, 64)

Thanks in advance

@nosan nosan changed the title Failed to parse a single b3 header. Incorrect parsing of a single b3 header. Mar 15, 2021
@nosan nosan changed the title Incorrect parsing of a single b3 header. Incorrect parsing of a single b3 header Mar 16, 2021
@nosan nosan closed this as completed Mar 20, 2021
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

1 participant