Skip to content

Browser Profiling #792

Closed
Closed

Description

@timfish

Problem Statement

Newer versions of Chrome support the BrowserProfilingIntegration which captures CPU profiles.

Solution Brainstorm

Initial testing shows this does not work out-of-the-box.

Activity

  1. self-assigned this
    on Dec 1, 2023
  2. AbhiPrasad commented on Dec 1, 2023

    @AbhiPrasad
    Contributor
  3. JonasBa commented on Dec 1, 2023

    @JonasBa

    @timfish can you explain a bit more about what breaks?

  4. JonasBa commented on Dec 1, 2023

    @JonasBa

    Or wait, do you mean newer versions of Electron right?

  5. timfish commented on Dec 1, 2023

    @timfish
    CollaboratorAuthor

    Just need to publish an SDK release and then I'll upload my demo app which is easier to debug.

    So far the log looks like this:

    [App] [Renderer] Sentry Logger [log]: [Tracing] starting undefined transaction - Long work
    [App] [Renderer] Sentry Logger [log]: [Profiling] started profiling transaction: Long work
    [App] [Renderer] Sentry Logger [log]: [Tracing] Starting '< unknown op >' span on transaction 'Long work' (b49c1529ba22dcba).
    /// snip extra
    [App] [Renderer] Sentry Logger [log]: [Tracing] Finishing '< unknown op >' span on transaction 'Long work' (b49c1529ba22dcba).
    [App] [Renderer] Sentry Logger [log]: [Profiling] stopped profiling of transaction: Long work
    [App] [Renderer] Sentry Logger [log]: [Tracing] Finishing undefined transaction: Long work.
    envelope
    

    My best guess so far is that the profile context is not being added to the event as it's not hitting any of the debug logging when it should attempt to add the profile envelope.

  6. JonasBa commented on Dec 1, 2023

    @JonasBa

    Oh I see. It does seem like the profiler is correctly started, it just never gets attached to the envelope 🤔 Let me know when you publish your example app and I'll take a look

  7. timfish commented on Dec 4, 2023

    @timfish
    CollaboratorAuthor

    Sorry for the delay. Here is the demo repo:
    https://github.com/timfish/sentry-electron-renderer-profiling-test

    yarn && yarn start to see the output.

    It's worth noting that in the case of this basic app, and in many Electron apps, Node integration is enabled in the renderer processes which gives you full Node mixed into the browser context! This is not the recommended way to use Electron now, especially if you're loading remote content, but for many apps this is less of a concern. Historically this has caused issues with libraries that do any kind of Node detection but I don't think this is the case here.

  8. timfish commented on Dec 11, 2023

    @timfish
    CollaboratorAuthor

    There is nothing wrong with profiling, the issue is how we route envelopes through the apps main process!

  9. timfish commented on Dec 11, 2023

    @timfish
    CollaboratorAuthor

    No, that's all working in the renderer/browser process.

    The issue is that we intercept all events and transactions and capture them through the main/node process so they have the full content. At this point, the profiles are being stripped off:

    function handleEnvelope(options: ElectronMainOptionsInternal, env: Uint8Array | string, contents?: WebContents): void {
    const envelope = parseEnvelope(env, new TextEncoder(), new TextDecoder());
    const eventAndAttachments = eventFromEnvelope(envelope);
    if (eventAndAttachments) {
    const [event, attachments] = eventAndAttachments;
    captureEventFromRenderer(options, event, attachments, contents);
    } else {
    const normalizedEnvelope = normalizeUrlsInReplayEnvelope(envelope, app.getAppPath());
    // Pass other types of envelope straight to the transport
    void getCurrentHub().getClient()?.getTransport()?.send(normalizedEnvelope);
    }
    }

    We want to maintain passing through the main process event pipeline so events from both processes have the same context. However, there's no way to pass the profiles (or envelope items other than attachment) through. Replays work since they are a completely separate envelope which can be directly forwarded.

    Possible solutions:

    • In the JavaScript repo, add something to EventHint that allows passing profiles or other envelope items through with captured events
    • When we receive an event in the main process with a profile
      • Remove and cache the profile
      • Re-add the profile context
      • Re-add the profile envelope when the event comes back through the main process event pipeline
    • Send the profiles in a separate envelope?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions