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

feat: support child spans with tail latencies #913

Merged
merged 4 commits into from Feb 6, 2019

Conversation

kjin
Copy link
Contributor

@kjin kjin commented Nov 10, 2018

Fixes #794

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 10, 2018
@kjin kjin changed the title [wip] refactor: support child spans with tail latencies [wip] feat: support child spans with tail latencies Nov 10, 2018
@kjin kjin changed the title [wip] feat: support child spans with tail latencies feat: support child spans with tail latencies Dec 12, 2018
@kjin kjin requested a review from a team January 24, 2019 19:39
@JustinBeckwith
Copy link
Contributor

👋 @googleapis/node-team @kjin can someone take a look at this one?

src/span-data.ts Outdated
// A function that replaces the ChildSpanData#endSpan prototype method on
// a child span instance.
private static overrideChildEndSpanHandler = function(
this: ChildSpanData, timestamp?: Date) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use an identifier other than this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a type annotation only, it'll be erased on compilation.

src/span-data.ts Outdated
if (!child.span.endTime) {
// Child hasn't ended yet.
// Override the endSpan function to make it re-publish only itself.
child.endSpan = RootSpanData.overrideChildEndSpanHandler;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there another way to do this instead of monkey patching? Could you have a test in the endSpan function? It is best to avoid monkey patching functions unless absolutely necessary. A reader will have to know that the endSpan method is part of the dynamic state rather than just the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a commit that changes the way this is being done, LMK what you think.

Copy link
Contributor

@ofrobots ofrobots left a comment

Choose a reason for hiding this comment

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

So much better. Let a few more comments.

/**
* Clears the buffer, returning its original contents.
*/
flush(): Trace[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name doesn't match the implementation.

child.shouldSelfPublish = true;
}
});
this.children = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

We need a comment on why we are setting the children array to empty. My guess is that the reason is that we don't want to keep the children array to stay alive because of the unterminated spans (since they continue to keep a reference to trace).

Alternatively, you could remove the reference from span to the trace, and remove this line and the needed comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's really more just that the this.children served its one-time purpose, so its value no longer holds any real meaning. I don't think there is significant memory impact either way, though there is the miniscule added benefit that in unforeseen circumstances where the root span is being retained in memory for whatever reason, that is has a slightly smaller footprint.

@@ -63,18 +63,20 @@ function mockNoMetadata() {
};
}

function createDummyTrace(): Trace {
let traceIdHighWater = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: complete the name to traceIdHighWatermark

@kjin kjin merged commit d1de959 into googleapis:master Feb 6, 2019
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.

None yet

4 participants