Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Add support for jaeger style uber-trace-id propagation #80

Closed
wants to merge 6 commits into from

Conversation

nvx
Copy link
Contributor

@nvx nvx commented May 6, 2020

Extending on the header_type config option, I've added support for jaeger-style uber-trace-id propagation. This implements #22.

I'm not overly familiar with unit testing in Lua however so I haven't made unit tests for the new functionality, but it has been tested manually and seems to work as intended including inter-op with downstream http services using the golang Jaeger library.

As an aside, I noticed setting header_type to eg w3c doesn't prevent the generation of b3 headers to the downstream service if no headers were found in the incoming request. It doesn't stop the configured header_type from being generated as well so not nothing breaks, but did seem a little odd?

@seh
Copy link

seh commented Jul 7, 2020

I noticed setting header_type to eg w3c doesn't prevent the generation of b3 headers to the downstream service if no headers were found in the incoming request. It doesn't stop the configured header_type from being generated as well so not nothing breaks, but did seem a little odd?

See the discussion starting here: #67 (comment).

@nvx
Copy link
Contributor Author

nvx commented Jul 8, 2020

Cheers for the heads up.

I also just noticed there was a merge conflict due to changes in master that I've just resolved now too. Any ETA on getting this merged @Tieske / @kikito. Happy to do more work on this if anything else is needed.

Co-authored-by: Yoan Blanc <yoan@dosimple.ch>
@CLAassistant
Copy link

CLAassistant commented Nov 23, 2020

CLA assistant check
All committers have signed the CLA.

@nvx
Copy link
Contributor Author

nvx commented Nov 23, 2020

I've accepted those two changes you suggested @greut, resolved the merge conflict with master, and signed the CLA (I assume the CLA is new as I don't remember it flagging up previously).

@Tieske
Copy link
Member

Tieske commented Nov 23, 2020

there still seem to be conflicts, but more importantly it seems to miss tests?

@nvx
Copy link
Contributor Author

nvx commented Nov 23, 2020

GitHub says there are no conflicts with the base branch?

As for the tests, I mentioned in the original post of the PR that I'm not familiar with unit testing in Lua. If there's a quick guide you can point me to for how to run the test suite I'd be more than happy to write up some tests for the new functionality.

@Tieske
Copy link
Member

Tieske commented Nov 23, 2020

try this:

# install Pongo
git clone https://github.com/kong/kong-pongo
cd kong-pongo
make install
# adjust PATH if you have to here
cd ..

# clone plugin
git clone https://github.com/kong/kong-plugin-zipkin
cd kong-plugin-zipkin

# run tests
pongo run

Additional info in the README.md.

@nvx
Copy link
Contributor Author

nvx commented Nov 24, 2020

Unit tests added and a couple of issues fixed.

As an aside, I noticed a couple of issues with parse_w3c_trace_context_headers (which I based the jaeger parse function on) while implementing unit tests for the jaeger headers functionality as they caused my unit tests to fail (the W3C tests pass coincidentally due to other factors).

The first issue is that it returns 4 items on error, but only 3 when no error is returned.

return nil, nil, nil, should_sample

vs
return trace_id, parent_id, should_sample

I suspect returning just nil 3 times and not also returning should_sample is the correct behaviour as that triggers the should sample logic. This is effectively the current behaviour anyway as the 4th item returned isn't referenced anywhere.
if should_sample == nil then
should_sample = math_random() < conf.sample_ratio
end

If returning should_sample rather than nil (which would be false in most cases) is considered the right option instead, I can adjust the Jaeger parser to match that as well.

The same function also doesn't return in one of the error cases, but is then caught by the version check just afterwards. I suspect this is just a case of a missing return line:

if version == nil or trace_id == nil or parent_id == nil or trace_flags == nil then
warn("invalid W3C traceparent header; ignoring.")
end
-- Only support version 00 of the W3C Trace Context spec.
if version ~= "00" then
warn("invalid W3C Trace Context version; ignoring.")
return nil, nil, nil, should_sample
end

Both are pretty trivial to fix, but I didn't want to clutter this PR with those changes too.

@Tieske
Copy link
Member

Tieske commented Nov 26, 2020

@kikito mind having a look, since you did most of the maintenance on this repo iirc?

@kikito kikito self-assigned this Jan 26, 2021
kikito added a commit that referenced this pull request Jan 27, 2021
The function was returning an extra value (should_sample) in some cases, which was never used. It has been removed.

It now also early-exits when it finds a problem in the w3c header.

Thanks to @nvx for pointing this out!

Related: #80
@kikito
Copy link
Member

kikito commented Feb 3, 2021

Hello, thank you for sending this PR and apologies for the time it took us to merge it.

I merged this on another pr (#101) after rebasing over master.

I noticed a couple of issues with parse_w3c_trace_context_headers

Thanks for this. I have done the relevant changes in #100

@kikito kikito closed this Feb 3, 2021
@nvx nvx deleted the feature/jaeger-propagation branch February 7, 2021 23:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants