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

Experimental tracing module (1/3): implement trace ids generation and propagation #2853

Merged
merged 19 commits into from
Jan 26, 2023

Conversation

oleiade
Copy link
Member

@oleiade oleiade commented Jan 13, 2023

About

To keep Pull Requests as small as possible and reduce the review burden, this PR is the first in a chain of 3 implementing the decided API design for the experimental tracing module.

This first PR exposes the k6/experimental/tracing module to k6 scripts but does not include any public APIs. Instead, it implements the trace id generation and propagation logic according to the W3C trace contexts specification.

The code introduced in this PR will be used in further PRs by the Client implementation to produce a trace id to attach to a given request and emit as part of the output's data points metadata, as well as producing the trace context headers in the supported formats (W3C, B3, and Jaeger).

Much of this PR's code and logic is essentially inherited and refactored from the xk6-distributed-tracing project.

Looking forward to your review 🙇🏻

References

Next: #2854

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,
thanks for it 🙇 I left a few comments.

js/modules/k6/experimental/tracing/trace_id.go Outdated Show resolved Hide resolved
js/modules/k6/experimental/tracing/trace_id.go Outdated Show resolved Hide resolved
js/modules/k6/experimental/tracing/trace_id.go Outdated Show resolved Hide resolved
js/modules/k6/experimental/tracing/trace_id.go Outdated Show resolved Hide resolved
@oleiade oleiade force-pushed the experimental/tracing-module-propagators branch from d0ef025 to 1b4a7a9 Compare January 16, 2023 14:57
@codecov-commenter
Copy link

codecov-commenter commented Jan 16, 2023

Codecov Report

Merging #2853 (0da38e2) into master (41472d1) will decrease coverage by 0.17%.
The diff coverage is 75.35%.

❗ Current head 0da38e2 differs from pull request most recent head dbff8f9. Consider uploading reports for the commit dbff8f9 to get more accurate results

@@            Coverage Diff             @@
##           master    #2853      +/-   ##
==========================================
- Coverage   76.87%   76.70%   -0.17%     
==========================================
  Files         217      224       +7     
  Lines       16619    16843     +224     
==========================================
+ Hits        12776    12920     +144     
- Misses       3039     3091      +52     
- Partials      804      832      +28     
Flag Coverage Δ
ubuntu 76.70% <75.35%> (-0.09%) ⬇️
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/v1/status_routes.go 58.33% <ø> (+25.68%) ⬆️
js/timeout_error.go 52.94% <0.00%> (-3.31%) ⬇️
lib/execution.go 89.90% <ø> (-2.76%) ⬇️
lib/testutils/mockoutput/mockoutput.go 41.66% <ø> (-4.49%) ⬇️
js/modules/k6/experimental/tracing/client.go 61.11% <61.11%> (ø)
js/modules/k6/experimental/tracing/options.go 63.63% <63.63%> (ø)
output/manager.go 79.16% <70.00%> (+4.16%) ⬆️
execution/abort.go 70.37% <70.37%> (ø)
errext/abort_reason.go 75.00% <75.00%> (ø)
js/modules/k6/experimental/tracing/module.go 75.55% <75.55%> (ø)
... and 28 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@oleiade oleiade force-pushed the experimental/tracing-module-propagators branch 3 times, most recently from 9df375a to beeacb4 Compare January 16, 2023 15:44
codebien
codebien previously approved these changes Jan 16, 2023
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should merge to master directly here, should we merge to a long-lived intermediate branch for aggregating the entire feature?

@oleiade
Copy link
Member Author

oleiade commented Jan 16, 2023

I considered it indeed, especially as there are two other PRs have to be merged if this first sequence makes it on time for release. I'll create one preemptively, and if other reviewers agree, I would rebase the current PR train on it 👍🏻

mstoykov
mstoykov previously approved these changes Jan 18, 2023
Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

I am glad we have smaller PRs.

In general it seems to me like 90% of this PR can be not under the js package. This likely will be useful in the future so that other js modules or parts of the system can use the tracing code.

This though likely should be done in a separate PR(s) as I don't want to add more things to be discussed for this PR chain.

Also I would've likely not introduced and registered the module in this PR but done it later.

Given that it seems like we agree to merge the other 2 PRs in this one and then merge this one - this is really not a problem that needs to be fixed. But is something I would like to note.

@oleiade oleiade dismissed stale reviews from mstoykov and codebien via 8b5b35c January 19, 2023 14:05
@oleiade oleiade force-pushed the experimental/tracing-module-propagators branch from beeacb4 to 8b5b35c Compare January 19, 2023 14:05
@oleiade
Copy link
Member Author

oleiade commented Jan 19, 2023

Thanks a lot for your input @mstoykov; much appreciated. After giving it some thought, I agree with you; a lot of the code here could live in another, more reusable place in the repository.

I took note and will try it in a future PR during our cooldown phase.

I'm unsure where a valid alternative place for that code would be. Did you have something in mind? 💭 Maybe js/common somewhere in lib, or we create a new tracing or identifiers module somewhere?

@oleiade oleiade requested review from codebien and mstoykov January 19, 2023 14:25
@oleiade
Copy link
Member Author

oleiade commented Jan 19, 2023

Heads-up @codebien and @mstoykov I've addressed the comments made so far, and also replaced the trace id's UnixTimestampNano with a time.Time as discussed in the second PR #2854 🙇🏻

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code LGTM

mstoykov
mstoykov previously approved these changes Jan 20, 2023
Although we do not expose any of user-facing logic at this point, we
register the "k6/experimental/tracing" module in k6 to prepare for
further implementation of public APIs
@oleiade oleiade force-pushed the experimental/tracing-module-propagators branch from 6e1c51b to 3889364 Compare January 23, 2023 15:03
This commit defines a Client type which exposes an API similar to the
HTTP module, and allows users to perform HTTP requests embedding a
trace-context, and attaching their trace_id as an output metadata to
their HTTP-related samples.

It uses the HTTP module's request function under the hood, and wraps it
with some "hook" logic to ensure the expected headers are present, and
that the expected output metadata are emitted.

The tracing client exposes an option-set allowing to use the three
available propagation format. Other options such as sampling, and
baggage are present for forward-compatibility, but will be implemented
at a later point in time.
This commit exposes the Client constructor publicly as part of the
k6/experimental/tracing module. From this point forward users will be
able to instantiate the Client, and perform instrumented HTTP requests
using it.

This commit also adds a bunch of integration tests covering the expected
behavior of the module's API.
@oleiade oleiade requested review from codebien and mstoykov January 26, 2023 14:12
samples/experimental/tracing-client.js Outdated Show resolved Hide resolved
@oleiade oleiade requested a review from codebien January 26, 2023 15:00
@codebien
Copy link
Contributor

@oleiade can we get #2855 (comment) before merging this PR?

@oleiade
Copy link
Member Author

oleiade commented Jan 26, 2023

@codebien considering it was brought up as a non-blocking request, I was planning to implement it in the PR implementing sampling (as I will have to modify the tests in the process anyways). If that's okay with you, I'd prefer to merge as is now 🙇🏻

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@oleiade oleiade merged commit daa866a into master Jan 26, 2023
@oleiade oleiade deleted the experimental/tracing-module-propagators branch January 26, 2023 15:38
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.

4 participants