Skip to content
This repository was archived by the owner on Mar 19, 2022. It is now read-only.

Conversation

@wdittmer
Copy link

When using a sample rate of 1%, I still saw traces from the nodejs application. After digging through it , it turns out that the sampled value is propagated as a string with either '0' or '1'. Further on in the trace of zipkin.js when the recordAnnotation is done it is checked with: if (!sampled) return; A string is always truthy, so it will always sample.
This pull request transforms the incoming string into a boolean.

The sampled value should be a boolean, not a string. Currently the result is that the trace is always sampled.
if (!(ctxSampled in ['0', '1'])) {
ctxSampled = '0';
}
let ctxSampledAsString = grpcMetadataFromIncomingCtx.get('x-b3-sampled')[0];

Choose a reason for hiding this comment

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

cool. while unlikely, the header could be not present (that's why the Option type is used)

Copy link
Author

Choose a reason for hiding this comment

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

The grpcMetadataFromIncomingCtx is a grpc.Metadata type.
If the header is not present it returns an empty array []; Taking the zeroth value will then be an undefined.
An undefined is not equal to either '1' or 'true' and thus result to false.
So, this should be fine, right?

@codefromthecrypt
Copy link

codefromthecrypt commented Mar 19, 2018 via email

Updated the code to use None when the sampled flag does not exist instead of default to False
Prepare for creating our own package with fix
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.

3 participants