-
-
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: Sessions Health Tracking #2973
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.
Looking good. I appreciate the jsdoc strings and clear code that most of the time speaks for itself.
First pass of feedback since I see things are already changing :)
size-limit report
|
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.
💯
Second pass. Up to you, I'd start with less attributes on Session unless we can clarify their usage.
What I care most is how we set the sent_at
on the envelope header, that has to change.
const session = scope.getSession(); | ||
if (session) { | ||
session.close(); | ||
if (client && client.captureSession) { |
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.
Can there be a custom client that doesn't implement captureSession
?!
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.
Sure, why not? It's an optional method.
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.
How optional? Aren't all clients based off BaseClient
? The BaseClient
abstract class implements captureSession
.
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.
Our own yes, but not if you are implementing a custom one. We rely on Client
interface, not BaseClient
abstract class.
public release?: string; | ||
public sid: string = uuid4(); | ||
public did?: string; | ||
public timestamp: number = Date.now(); |
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 docs are a bit ambiguous. I'd omit the parts of session we don't need for now.
In particular, the timestamp
should be the time when "session change event came in". In Python it is set to datetime.utcnow()
in Session.update
, otherwise it is None
.
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.
It's other way around. It's utcnow()
if user doesn't provide it explicitly :) (it's the only if
that omits not
😅)
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 if
is what I linked above, and it in in the Session.update
method (Python). Here (JS) we're looking at the timestamp
at construction time, in Python it starts as None
.
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.
It doesn't, as python's __init__
is calling update
which will set it immediately to utcnow()
try { | ||
const po = new PerformanceObserver((entryList, po) => { | ||
entryList.getEntries().forEach(entry => { | ||
if (entry.name === 'first-contentful-paint' && entry.startTime < firstHiddenTime) { |
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.
if (entry.name === 'first-contentful-paint' && entry.startTime < firstHiddenTime) { | |
if (entry.name === 'first-contentful-paint' && entry.startTime < firstHiddenTime && !fcpResolved) { |
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.
Should guarantee that the if condition is run at most once.
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.
Observer is disconnected after the first call, so I'm not sure how it'd be ever called twice?
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.
🌟
Step 1:
Step 2: PROFIT
For now, the initial page load session is tracked using
First-Contentful-Paint
in conjunction withload
event. If Performance API is not available,FCP
will be skipped and resolved instantly, and onlyload
event will be awaited on.This is a good first step that we can iterate over if necessary.