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

React Native Session Replays missing network requests #276

Closed
jrusso1020 opened this issue Sep 30, 2024 · 6 comments · Fixed by PostHog/posthog-ios#203
Closed

React Native Session Replays missing network requests #276

jrusso1020 opened this issue Sep 30, 2024 · 6 comments · Fixed by PostHog/posthog-ios#203
Labels
bug Something isn't working Session Replay

Comments

@jrusso1020
Copy link

jrusso1020 commented Sep 30, 2024

Bug Description

Bug description

When enabling react native session replays, we are noticing that only network requests from third party SDKs are being recorded. For example, requests to revenue cat or sentry which come from their own react native packages.

Network requests to our own backend are not being recorded, throughout the entire session. We use fetch for requests in our react native application.

here's a link to our screen recording for help debugging

Please describe.
If this affects the front-end, screenshots would be of great help.

If you are on PostHog Cloud it would be really valuable if you can share any links where the problem occurs. This speeds up our ability to troubleshoot tremendously.

How to reproduce

  1. Enabled session replays on latest posthog react native version (version below)
  2. Checked the session replays in posthog cloud

Additional context

Fetch

We initialize our API client to use fetch like so

this.fetch = (...args: any[]) => window.fetch(...args);

And then make requests like so, similar for 'get' requests as well

the Content-Type will either be application/json or text/plain(used for sending base64 encoded protocol buffers)

response = await this.fetch(url, {
        method: 'post',
        body: body,
        headers: {
          'Content-Type': contentType,
          authorization: `Bearer ${this.accessToken}`,
          ...this.extraHeaders,
        },
      });

And example fetch request

{
  "method": "post",
  "body": "[REDACTED]",
  "headers": {
    "Content-Type": "application/json",
    "authorization": "Bearer [REDACTED]",
    "appId": "[REDACTED]",
    "appVersion": "2.12.0 2024/09/19"
  }
}

Posthog Initailization

We enable the posthog client separately and then pass this into the posthogProvider

export function initPostHog(config: EHAppConfig) {
  if (posthogInstance) {
    return posthogInstance;
  }

  if (!config.posthog.enabled || !config.posthog.apiKey) {
    return null;
  }

  posthogInstance = new PostHog(config.posthog.apiKey, {
    host: 'https://us.i.posthog.com',
    disableGeoip: true,
    // Comment out the line below to enable PostHog in dev
    disabled: __DEV__ || !config.posthog.enabled, // Disable in dev or if not enabled in config
    enableSessionReplay: true,
  });

  return posthogInstance;
}
<PostHogProvider client={posthog} autocapture>
...

Package versions

We don't technically use expo to build our app but including it as well

  • posthog-react-native@3.3.1
  • react-native@0.72.17
  • expo@48.0.21

Testing on iOS 18 (built and running on an actual device, not a simulator)

Debug info

- [x] PostHog Cloud, Debug information:
Session: https://us.posthog.com/project/sTMFPsFhdP1Ssg/replay/01924347-1cab-7922-be47-db03acae31e6?t=4771
Admin: http://go/adminOrgUS/01910e4f-b970-0000-fa38-08ea1e2e4866 (project ID 82677)
Sentry: http://go/sentryUS/82677
@jrusso1020 jrusso1020 added the bug Something isn't working label Sep 30, 2024
@marandaneto
Copy link
Member

Hello @jrusso1020 checking this out now.

@marandaneto
Copy link
Member

The reason is that RN uses the URLSession.shared.dataTask(with: X) instead of the methods using the method with completionHandler, so the instrumentation (swizzling) isn't picking it up correctly.
Libraries that would use the URLSession.shared.dataTask(with: X, { completionHandler } would be captured correctly, but if libraries would also use the URLSession.shared.dataTask(with: X) it'd not work either.
Checking how to fix this.

@marandaneto marandaneto transferred this issue from PostHog/posthog Oct 1, 2024
@jrusso1020
Copy link
Author

Thanks for the quick update and work here @marandaneto ! will stay up to date and happy to try out any fix you have

@marandaneto
Copy link
Member

I've opened this issue for later refactoring PostHog/posthog-ios#204
https://github.com/PostHog/posthog-ios/releases/tag/3.12.6 should be a quick fix for now.
The RN session plugin uses the latest posthog-ios version, so if you update your Pods, you can test this (be sure its using the 3.12.6 version).

@jrusso1020
Copy link
Author

@marandaneto just tested it out with a local build and looks like it's working now for us thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Session Replay
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants