-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: Pick up sentry-trace in JS <meta/> tag #2703
Conversation
let parentSpanId; | ||
let sampled; | ||
|
||
const header = Tracing._getMeta('sentry-trace'); |
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.
So I guess now if someone sets this in an SPA, all transactions would use this meta header right?
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.
Correct. For me this is opt-in behavior enough, this can't happen by accident so guarding this behind an option in the integration doesn't make a lot of sense to me.
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.
@@ -42,13 +43,15 @@ export function tracingHandler(): ( | |||
if (span) { | |||
traceId = span.traceId; | |||
parentSpanId = span.parentSpanId; | |||
sampled = span.sampled; |
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 is a bug fix right? We should remember for the changelog then that there are two changes in this PR. a feat
for the meta tag, and a fix
for sampling from trace parent in node.
private static _getMeta(metaName: string): string | null { | ||
const metas = document.getElementsByTagName('meta'); | ||
|
||
// tslint:disable-next-line: prefer-for-of | ||
for (let i = 0; i < metas.length; i++) { | ||
if (metas[i].getAttribute('name') === metaName) { | ||
return metas[i].getAttribute('content'); | ||
} | ||
} | ||
|
||
return null; | ||
} |
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.
private static _getMeta(metaName: string): string | null { | |
const metas = document.getElementsByTagName('meta'); | |
// tslint:disable-next-line: prefer-for-of | |
for (let i = 0; i < metas.length; i++) { | |
if (metas[i].getAttribute('name') === metaName) { | |
return metas[i].getAttribute('content'); | |
} | |
} | |
return null; | |
} | |
private static _getMeta(metaName: string): string | undefined { | |
return (document.querySelector(`meta[name=${metaName}]`) || {}).content; | |
} |
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 has typescript errors, I will go with
const el = document.querySelector(`meta[name=${metaName}]`);
return el ? el.getAttribute('content') : null;
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.
Ah, silly empty object typing 🎳
parentSpanId = span.parentSpanId; | ||
sampled = span.sampled; | ||
} | ||
Tracing._log( |
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 log will be incorrect if span
is falsy. Should be moved inside span
or corrected logically.
Add functionality to
Tracing
integration to pick up<meta name="sentry-trace" />
to continue a trace in the frontend.The reason why it's a
<meta/>
tag is that a<script/>
tag setting something on the window would block rendering.Right now, only Laravel can provide this meta tag with this PR
getsentry/sentry-laravel#358
This is for cases where the Trace is not started from the frontend but from the backend.
It can be also useful for other webframeworks that are not SPA and instead still render templates from backend -> frontend.