getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.9k stars 1.56k forks source link

remix @sentry/profiling-node #11992

Closed jasonloeve closed 2 months ago

jasonloeve commented 4 months ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/remix

SDK Version

7.114.0

Framework Version

^18.2.0

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

  1. Follow the docs at https://docs.sentry.io/platforms/javascript/guides/remix/profiling/#prerequisites to setup profiling in a new remix application (Hydrogen).
  2. Run npm dev / build etc (Node v20.12.1, npm v10.5.0)

Expected Result

The application to build out

Actual Result

Receiving the following errors

`✘ [ERROR] Could not resolve "os"

node_modules/@sentry/profiling-node/lib/index.js:3:19:
  3 │ const os = require('os');
    ╵                    ~~~~

The package "os" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

✘ [ERROR] Could not resolve "path"

node_modules/@sentry/profiling-node/lib/index.js:4:21:
  4 │ const path = require('path');
    ╵                      ~~~~~~

The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

✘ [ERROR] Could not resolve "worker_threads"

node_modules/@sentry/profiling-node/lib/index.js:8:31:
  8 │ const worker_threads = require('worker_threads');
    ╵                                ~~~~~~~~~~~~~~~~

The package "worker_threads" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

✘ [ERROR] Could not resolve "child_process"

node_modules/@sentry/profiling-node/node_modules/detect-libc/lib/detect-libc.js:6:29:
  6 │ const childProcess = require('child_process');
    ╵                              ~~~~~~~~~~~~~~~

The package "child_process" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

✘ [ERROR] Could not resolve "fs"

node_modules/@sentry/profiling-node/node_modules/detect-libc/lib/filesystem.js:6:19:
  6 │ const fs = require('fs');
    ╵                    ~~~~

The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error. `

mydea commented 4 months ago

Can you share your init code, as well as in which file you put it? This sounds like you are loading nodeProfilingIntegration in entry.client.js or something along these lines!

jasonloeve commented 4 months ago

Hey @mydea ,

So Im working with Shopify Hydrogen (Remix)

entry.client.tsx

import * as Sentry from '@sentry/remix';
import {RemixBrowser, useLocation, useMatches} from '@remix-run/react';
import {startTransition, StrictMode, useEffect} from 'react';
import {hydrateRoot} from 'react-dom/client';

Sentry.init({
  dsn: 'https://xxxxxxxxxxxxx@xxxxxxxxxxxxxxx.ingest.us.sentry.io/xxxxxxxxxxxxxxx',
  tracesSampleRate: 1.0,
  profilesSampleRate: 1.0,
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1,

  integrations: [
    Sentry.browserTracingIntegration({
      useEffect,
      useLocation,
      useMatches,
    }),
    Sentry.replayIntegration(),
    Sentry.browserProfilingIntegration(),
  ],
});

startTransition(() => {
  hydrateRoot(
    document,
    <StrictMode>
      <RemixBrowser />
    </StrictMode>,
  );
});

entry.server.tsx

import * as Sentry from '@sentry/remix';
import {nodeProfilingIntegration} from '@sentry/profiling-node';
import type {EntryContext} from '@shopify/remix-oxygen';
import {RemixServer} from '@remix-run/react';
import isbot from 'isbot';
import {renderToReadableStream} from 'react-dom/server';
import {createContentSecurityPolicy} from '@shopify/hydrogen';

export function handleError(error, {request}) {
  Sentry.captureRemixServerException(error, 'remix.server', request);
}

Sentry.init({
  dsn: 'https://xxxxxxxxxxxxx@xxxxxxxxxxxxxxx.ingest.us.sentry.io/xxxxxxxxxxxxxxx',
  // debug: true,
  tracesSampleRate: 1.0,
  profilesSampleRate: 1,
  integrations: [nodeProfilingIntegration()],
});

.......................
lforst commented 4 months ago

@jasonloeve I lack a bit of knowledge on hydrogen but I think it does generally not run on Node.js but on a worker runtime instead (at least when looking at this https://github.com/Shopify/hydrogen/discussions/1535). It running on a worker runtime means that most of the Node.js API is not available. As of now, our SDK is not cut out for this. Is this only a problem when using the nodeProfilingIntegration() or do you get similar errors after removing it?

getsantry[bot] commented 3 months ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀