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

Fix B3 sampling API to support missing values #1640

Merged
merged 1 commit into from
Jul 21, 2021

Conversation

tkountis
Copy link
Contributor

Motivation:

B3 sampling handling was supposed to support both present and not values.
However, in practise it only supported present values, and treated non existing as sampling=off.

Modifications:

Support Boolean values for handling sampling which now allows for not present values in the carrier,
and the local sampler can make the final decision on whether to enable sampling for the local span or not.

The change unfortunately broke API because of the type change, thus we took advantage of that and cleaned up
some problematic relationships between classes which results in a cleaner more consistent API, which also
follows closer the spec.

Result:

Correct sampling & cleaner API

Link: #1512

@tkountis tkountis added the breaking-change PR with breaking changes, removed APIs or other binary incompatibilities. label Jun 25, 2021
@tkountis tkountis self-assigned this Jun 25, 2021
@tkountis tkountis requested review from Scottmitch and idelpivnitskiy and removed request for Scottmitch June 25, 2021 15:22
@Scottmitch
Copy link
Member

@eddie4941 - FYI. PTAL.

*
* @return low 64 bits of the trace ID
*/
default long traceId() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are these used in the wild, should I offer an alternative accessor through context

Copy link
Member

Choose a reason for hiding this comment

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

lets stick with single access point on the API for now, and we can add utility methods if necessary.

Copy link
Member

@Scottmitch Scottmitch left a comment

Choose a reason for hiding this comment

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

few comments then lgtm

if (parentSpanIdHex != null) {
carrier.set(PARENT_SPAN_ID, parentSpanIdHex);
}
carrier.set(SAMPLED, state.isSampled() ? "1" : "0");
carrier.set(SAMPLED, context.isSampled() ? "1" : "0");
Copy link
Member

Choose a reason for hiding this comment

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

context.isSampled() may be null, add null protection?

public void inject(InMemoryTraceState state, SingleLineValue carrier) {
carrier.set(format(state.traceIdHex(), state.spanIdHex(), state.parentSpanIdHex(), state.isSampled()));
public void inject(final InMemorySpanContext context, final SingleLineValue carrier) {
carrier.set(format(context.toTraceId(), context.toSpanId(), context.parentSpanId(), context.isSampled()));
Copy link
Member

Choose a reason for hiding this comment

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

context.isSampled() maybe null. check other usages of isSampled() to avoid NPE.

*
* @return low 64 bits of the trace ID
*/
default long traceId() {
Copy link
Member

Choose a reason for hiding this comment

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

lets stick with single access point on the API for now, and we can add utility methods if necessary.

*
* @return parent span ID in hex
*/
default String nonnullParentSpanIdHex() {
Copy link
Member

Choose a reason for hiding this comment

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

since the "hex" variation of parentSpanIdHex longer exist and this method name doesn't really make sense any more. Also the impl uses some internal types (NO_PARENT_ID) ... lets move this method to an internal utility class for now.

*/
protected abstract InMemorySpanContext newSpanContext(InMemoryTraceState state);
protected abstract InMemorySpanContext newSpanContext(String traceId, String spanId, String parentSpanId,
Copy link
Member

Choose a reason for hiding this comment

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

this method is no longer called in this class, make it private to DefaultInMemoryTracer?

*/
class DefaultInMemorySpanContext implements InMemorySpanContext {
public class DefaultInMemorySpanContext implements InMemorySpanContext {
Copy link
Member

Choose a reason for hiding this comment

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

can we make this class final for now (more restrictive access pattern to minimize our API surface)?

Motivation:

B3 sampling handling was supposed to support both present and not values.
However, in practise it only supported present values, and treated non existing as sampling=off.

Modifications:

Support Boolean values for handling sampling which now allows for not present values in the carrier,
and the local sampler can make the final decision on whether to enable sampling for the local span or not.
The change unfortunately broke API because of the type change, thus we took advantage of that and cleaned up
some problematic relationships between classes which results in a cleaner more consistent API, which also
follows closer the spec.

Result:

Correct sampling & cleaner API
@tkountis tkountis merged commit c4699d2 into apple:main Jul 21, 2021
@tkountis tkountis deleted the api/opentracing branch July 21, 2021 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change PR with breaking changes, removed APIs or other binary incompatibilities.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants