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

Refactor span ID and trace ID using newtype pattern #73

Merged

Conversation

Monkeyanator
Copy link
Contributor

Addresses #11.

This change wraps usages of span ID (u64) and trace ID (u128) in single-field tuple structs in
order to enforce intention when passing around values of these types (i.e. the newtype pattern). Discussion on the advantages and disadvantages of this pattern can be found here.

Also adds the "SpanId::invalid()" and "TraceId::invalid()" convenience methods for creating zero-valued instances of both types.

@Monkeyanator Monkeyanator requested a review from a team March 3, 2020 23:55
Wraps usages of span ID (u64) and trace ID (u128) in single-field tuple structs in
order to enforce intention when passing around values of these types.
Adds the "SpanId::invalid()" and "TraceId::invalid()" methods for
conveniently creating zero-valued instances of both types.
@Monkeyanator Monkeyanator force-pushed the newtype-migration-spanid-traceid branch from be3e3d8 to 8b58457 Compare March 4, 2020 01:14
Copy link
Member

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! just a few style tweaks requested.

src/api/trace/span_context.rs Outdated Show resolved Hide resolved
src/api/propagation/binary_propagator.rs Outdated Show resolved Hide resolved
src/api/propagation/noop.rs Outdated Show resolved Hide resolved
src/api/trace/span_context.rs Outdated Show resolved Hide resolved
@MikeGoldsmith
Copy link
Member

Looks good - thanks for the contributions. I don't have any more to add than what @jtescher has already said.

@Monkeyanator Monkeyanator force-pushed the newtype-migration-spanid-traceid branch 2 times, most recently from 4df1714 to d8d2e92 Compare March 5, 2020 19:34
Copy link
Member

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Yeah that looks better! just last few comments 🎉

opentelemetry-jaeger/src/lib.rs Outdated Show resolved Hide resolved
src/api/propagation/binary_propagator.rs Outdated Show resolved Hide resolved
Adds the from_u64 and to_u64 methods to SpanId and the from_u128 and
to_u128 methods to TraceId. Facilitates straightforward conversion
between the wrapper structs and their wrapped uint types.
@Monkeyanator Monkeyanator force-pushed the newtype-migration-spanid-traceid branch from d8d2e92 to d5107d5 Compare March 6, 2020 16:45
Copy link
Member

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Great thanks!

@jtescher jtescher merged commit b31b674 into open-telemetry:master Mar 6, 2020
@Monkeyanator Monkeyanator deleted the newtype-migration-spanid-traceid branch March 7, 2020 00:07
cijothomas added a commit to cijothomas/opentelemetry-rust that referenced this pull request Sep 7, 2024
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.

3 participants