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

Change span ID to use random bytes #654

Merged
merged 12 commits into from
Jan 20, 2018

Conversation

draffensperger
Copy link
Contributor

@draffensperger draffensperger commented Jan 18, 2018

While running a test application that was composed of multiple Node.js apps, each with tracing enabled, we found that span IDs would conflict when the multiple apps were simultaneously started, because each started their span IDs at index 1. This switches to use secure randomness for span IDs to help ensure uniqueness even when multiple Node apps are started at the same time.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 18, 2018
src/span-data.ts Outdated
@@ -14,6 +14,7 @@
* limitations under the License.
*/

import {randomBytes} from 'crypto';

This comment was marked as spam.

This comment was marked as spam.

@kjin
Copy link
Contributor

kjin commented Jan 18, 2018

@draffensperger FYI: I opened a PR to update CONTRIBUTING.md (#655) to write about running unit tests locally. What was the problem you encountered with initializing test fixtures?

EDIT: For future readers -- the issue was that the last time npm run init-test-fixtures was run was before ea3b26e. To resolve this, delete any directories (but not the *.pem files) in test/plugins/fixtures

@draffensperger
Copy link
Contributor Author

Thanks for documenting that!

As for my specific issue, I was getting an error like this:

[ { Error: ENOENT: no such file or directory, mkdir '~/github/cloud-trace-nodejs/build/test/plugins/fixtures/google-cloud-datastore1/node_modules/grpc/node_modules/tar-pack/test/fixtures'
   errno: -2,
   code: 'ENOENT',
   syscall: 'mkdir',
   path: '~/github/cloud-trace-nodejs/build/test/plugins/fixtures/google-cloud-datastore1/node_modules/grpc/node_modules/tar-pack/test/fixtures' } ]

It turns out that I still had some untracked directories in test/plugins/fixture from when I had cloned a previous version of the repo. I deleted those directories, but kept the .pem files and then I was able to run the tests. I also needed to run ./bin/docker-trace.sh start to start a Docker container with the databases for the test.

@codecov
Copy link

codecov bot commented Jan 18, 2018

Codecov Report

Merging #654 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #654      +/-   ##
==========================================
+ Coverage   96.06%   96.08%   +0.01%     
==========================================
  Files          31       31              
  Lines        1627     1635       +8     
  Branches      293      295       +2     
==========================================
+ Hits         1563     1571       +8     
  Misses         64       64
Impacted Files Coverage Δ
root/project/build/src/span-data.js 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b811387...4f5c977. Read the comment docs.

@kjin kjin self-requested a review January 18, 2018 21:32
@@ -14,6 +14,7 @@
* limitations under the License.
*/

import * as crypto from 'crypto';

This comment was marked as spam.

This comment was marked as spam.

var receivedSpanId = receivedSpanIdAndOptions[0];
var receivedTraceOptions = receivedSpanIdAndOptions[1];
// Trace ID and trace options should be the same in sender and receiver.
assert.equal(receivedTraceId, sentTraceId);

This comment was marked as spam.

This comment was marked as spam.

src/span-data.ts Outdated
() => randomFillSync(spanIdBuffer) :
() => randomBytes(SPAN_ID_RANDOM_BYTES);
// This evaluates to a large whole number such that any fractional number
// between 0 and 1 multiplied by it will always give a whole number.

This comment was marked as spam.

This comment was marked as spam.

src/span-data.ts Outdated

function randomSpanId() {
// No rounding is needed because SPAN_ID_MAX is bigger than 1 / Number.EPSILON
return String(Math.random() * SPAN_ID_MAX);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

@kjin kjin 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'll merge this once CI passes

@kjin kjin merged commit a212d70 into googleapis:master Jan 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants