-
Notifications
You must be signed in to change notification settings - Fork 824
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(traceparent): setting parent span from server #477
feat(traceparent): setting parent span from server #477
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, should add documentation somewhere that this is something you cna do, similar to the link census docs.
Codecov Report
@@ Coverage Diff @@
## master #477 +/- ##
==========================================
+ Coverage 92.5% 92.66% +0.16%
==========================================
Files 136 137 +1
Lines 6511 6627 +116
Branches 593 587 -6
==========================================
+ Hits 6023 6141 +118
+ Misses 488 486 -2
|
@bg451 updated readme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice!!
@@ -76,12 +84,17 @@ export class DocumentLoad extends BasePlugin<unknown> { | |||
* Collects information about performance and creates appropriate spans | |||
*/ | |||
private _collectPerformance() { | |||
const windowWithTrace: WindowWithTrace = (window as unknown) as WindowWithTrace; | |||
const serverContext = | |||
parseTraceParent(windowWithTrace.traceparent || '') || undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that parseTraceParent
already will return null
if it fails to parse, would this still work without the || undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the undefined
must be there as the SpanOptions.parent
is optional and cannot be null so the typescript is complaining about it.
parent?: Span | SpanContext; |
I'm sure it's much too late to bring something like this up but just for my own edification, why did you choose to embed the trace parent in a script tag with a variable as opposed to a meta tag like |
It is never too late to improve things :). |
If it isn't too late to change, I prefer the meta option. In addition to being outside of script execution, it is also more reliable and simplifies server-side implementation as HTML is much easier to parse/modify without unexpected side effects than JS is. |
@dyladan you might have a look again, I changed the |
Good idea about the I think in the future it could potentially also allow it to be set via the Server Timing header, which is the only header that the JS client can read directly from the initial page load. That would allow something like a load balancer to inject it without changing the HTML. But that's a future improvement and should be optional! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Thanks for making the meta
tag change.
@@ -25,7 +25,17 @@ const VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i; | |||
const INVALID_ID_REGEX = /^0+$/i; | |||
const VERSION = '00'; | |||
|
|||
function parse(traceParent: string): SpanContext | null { | |||
/** | |||
* Parses information from [traceParent] window property and converts it into {@link SpanContext} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Parses information from [traceParent] window property and converts it into {@link SpanContext} | |
* Parses information from the [traceparent] span tag and converts it into {@link SpanContext} |
Additionally, the trace context working group is going to be working on a trace context response header for this use specifically |
Which problem is this PR solving?
Short description of the changes
It adds functionality of reading the server span using the trace context. It will allow to share context between server and client.