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

Support trace information in logs #26

Merged
merged 2 commits into from
Nov 8, 2019
Merged

Support trace information in logs #26

merged 2 commits into from
Nov 8, 2019

Conversation

caskolkm
Copy link

@caskolkm caskolkm commented Nov 8, 2019

Hi Guys, I added functionality to support trace information in the logs.

See: https://cloud.google.com/logging/docs/agent/configuration#special-fields

@JeanMertz
Copy link
Contributor

JeanMertz commented Nov 8, 2019

Thank you for your contribution @caskolkm!

Regarding the string format TRACE_ID/SPAN_ID;o=TRACE_TRUE, is this a standard trace format definition? I couldn't find anything relevant other than this Google Cloud page talking about adding trace information using headers.

In that case, it makes sense to use such a format, as it adheres to best practices on how to format a header, and a header can only be a single string.

In the case of this library though, unless there is a compelling reason to stick to the current format, I think it would be best if we moved away from the regex implementation, and used a typed function signature for improved performance (no regex parsing) and correctness (the function becomes infallible).

So instead of this:

func TraceContext(traceContext string, projectName string) []zap.Field

We'd use this:

func TraceContext(trace string, spanID string, sampled bool, projectName string) []zap.Field

Given your example, we'd get:

// before
TraceContext("105445aa7843bc8bf206b120001000/0;o=1", "my-project-name")

// after
TraceContext("105445aa7843bc8bf206b120001000", "0", true, "my-project-name")

WDYT?

@caskolkm
Copy link
Author

caskolkm commented Nov 8, 2019

@JeanMertz i thought it was a standard trace format, but i can agree on your suggestion.

@caskolkm
Copy link
Author

caskolkm commented Nov 8, 2019

@JeanMertz changed the implementation, take a look :)

@JeanMertz
Copy link
Contributor

@caskolkm looks great, thanks! I tested it locally (I should really add CI integration to this repository) and it works as expected 👍. I'll cut a new release with this change included.

@JeanMertz JeanMertz merged commit 6a3c767 into blendle:master Nov 8, 2019
@caskolkm caskolkm deleted the trace-fields branch November 8, 2019 09:11
@caskolkm
Copy link
Author

caskolkm commented Nov 8, 2019

@JeanMertz you are fast! thnx!

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

Successfully merging this pull request may close these issues.

2 participants