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: add more debug signals #1743

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/__tests__/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ describe('posthog core', () => {
$is_identified: false,
$process_person_profile: false,
$recording_status: 'buffering',
$sdk_debug_replay_internal_buffer_length: 0,
$sdk_debug_replay_internal_buffer_size: 0,
$sdk_debug_retry_queue_size: 0,
})
})

Expand All @@ -467,6 +470,9 @@ describe('posthog core', () => {
$is_identified: false,
$process_person_profile: false,
$recording_status: 'buffering',
$sdk_debug_replay_internal_buffer_length: 0,
$sdk_debug_replay_internal_buffer_size: 0,
$sdk_debug_retry_queue_size: 0,
})
})

Expand Down Expand Up @@ -597,6 +603,40 @@ describe('posthog core', () => {
expect(pageleaveProperties.$pageview_id).toEqual('pageview-id-2')
expect(pageleaveProperties.$prev_pageview_id).toEqual('pageview-id-2')
})

it('includes pageview id from previous pageview', () => {
const pageview1Properties = posthog._calculate_event_properties(
'$pageview',
{},
new Date(),
'pageview-id-1'
)
expect(pageview1Properties.$pageview_id).toEqual('pageview-id-1')

const event1Properties = posthog._calculate_event_properties('custom event', {}, new Date(), 'event-id-1')
expect(event1Properties.$pageview_id).toEqual('pageview-id-1')

const pageview2Properties = posthog._calculate_event_properties(
'$pageview',
{},
new Date(),
'pageview-id-2'
)
expect(pageview2Properties.$pageview_id).toEqual('pageview-id-2')
expect(pageview2Properties.$prev_pageview_id).toEqual('pageview-id-1')

const event2Properties = posthog._calculate_event_properties('custom event', {}, new Date(), 'event-id-2')
expect(event2Properties.$pageview_id).toEqual('pageview-id-2')

const pageleaveProperties = posthog._calculate_event_properties(
'$pageleave',
{},
new Date(),
'pageleave-id'
)
expect(pageleaveProperties.$pageview_id).toEqual('pageview-id-2')
expect(pageleaveProperties.$prev_pageview_id).toEqual('pageview-id-2')
})
})

describe('_handle_unload()', () => {
Expand Down
11 changes: 9 additions & 2 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,15 @@ export class PostHog {
properties['$window_id'] = windowId
}

if (this.sessionRecording) {
properties['$recording_status'] = this.sessionRecording.status
try {
if (this.sessionRecording) {
properties['$recording_status'] = this.sessionRecording.status
properties['$sdk_debug_replay_internal_buffer_length'] = this.sessionRecording['buffer'].data.length
properties['$sdk_debug_replay_internal_buffer_size'] = this.sessionRecording['buffer'].size
}
properties['$sdk_debug_retry_queue_size'] = this._retryQueue?.['queue']?.length
Comment on lines +995 to +998
Copy link
Member Author

Choose a reason for hiding this comment

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

this should give us a view on how much data replay is currently holding
and whether the SDK retry queue is high

hopefully giving signal that e.g. network requests to send data are failing in replay
when smaller event data might be succeeding

} catch (e: any) {
properties['$sdk_debug_error_capturing_properties'] = String(e)
}

if (this.requestRouter.region === RequestRouterRegion.CUSTOM) {
Expand Down
Loading