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

change how tracing query comments are handled #6463

Merged
merged 1 commit into from
Jul 23, 2020

Conversation

systay
Copy link
Collaborator

@systay systay commented Jul 22, 2020

When sending the trace information over the mysql protocol, we need to be able to encode a string-string map into a string that can be put into a query as a comment. The current way of doing it is broken, since it is not protecting the map serialisation from clashing with SQL.

This PR changes the approach to use first JSON as a way of encoding the map, and then base64 encoding to make sure that the json doesn't clash with any SQL syntax rules.

On the client side, one would need to pick up the current tracing information from openTracing, encode it as JSON, base64 encode the json-string, and stick this into the comment. Example:

openTracingData := map[string]string{
	"uber-trace-id":"123:456:789:1",
	"other data":   "something else",
}

jsonBytes, _ := json.Marshal(openTracingData)
encodedComment := base64.StdEncoding.EncodeToString(jsonBytes)

originalQuery := "select 42"

fullQuery := fmt.Sprintf("/*VT_SPAN_CONTEXT=%s*/ %s", encodedComment, originalQuery)

fmt.Println(fullQuery)

Result:

/*VT_SPAN_CONTEXT=eyJvdGhlciBkYXRhIjoic29tZXRoaW5nIGVsc2UiLCJ1YmVyLXRyYWNlLWlkIjoiMTIzOjQ1Njo3ODk6MSJ9*/ select 42

This PR replaces #6387

Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay merged commit f9f2ef8 into vitessio:master Jul 23, 2020
@deepthi deepthi added this to the v7.0 milestone Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants