Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

feat: support child spans with tail latencies#913

Merged
kjin merged 4 commits intogoogleapis:masterfrom
kjin:child-span-tails
Feb 6, 2019
Merged

feat: support child spans with tail latencies#913
kjin merged 4 commits intogoogleapis:masterfrom
kjin:child-span-tails

Conversation

@kjin
Copy link
Copy Markdown
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 force-pushed the child-span-tails branch from 9f1b448 to ecc1eda Compare January 22, 2019 17:37
@kjin kjin requested a review from a team January 24, 2019 19:39
@JustinBeckwith
Copy link
Copy Markdown
Contributor

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

Comment thread 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
Copy Markdown
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
Copy Markdown
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.

Comment thread 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
Copy Markdown
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
Copy Markdown
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.

@kjin kjin force-pushed the child-span-tails branch from afa0642 to ef32ae3 Compare January 28, 2019 18:38
Copy link
Copy Markdown
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.

Comment thread src/trace-writer.ts Outdated
/**
* Clears the buffer, returning its original contents.
*/
flush(): Trace[] {
Copy link
Copy Markdown
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.

Comment thread src/span-data.ts
child.shouldSelfPublish = true;
}
});
this.children = [];
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread test/test-trace-writer.ts Outdated
}

function createDummyTrace(): Trace {
let traceIdHighWater = 0;
Copy link
Copy Markdown
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 force-pushed the child-span-tails branch from aa16adb to fab9f66 Compare February 4, 2019 19:39
@kjin kjin merged commit d1de959 into googleapis:master Feb 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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