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(nuxt): Add server config to root folder #13583

Merged
merged 8 commits into from
Sep 9, 2024
Merged

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Sep 4, 2024

This is a draft PR as this approach leads to an error as hook.mjs is not included in the node_modules. This has been fixed upstream but was not yet released for nuxt.

Makes it possible to include a sentry.server.config.ts file in the root folder alongside sentry.client.config.ts. Currently, it has to be added in the public folder which is not 100% ideal.

@s1gr1d s1gr1d mentioned this pull request Sep 4, 2024
@s1gr1d s1gr1d added the Package: nuxt Issues related to the Sentry Nuxt SDK label Sep 4, 2024
Copy link
Contributor

github-actions bot commented Sep 4, 2024

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 22.52 KB - -
@sentry/browser - with treeshaking flags 21.3 KB - -
@sentry/browser (incl. Tracing) 34.78 KB - -
@sentry/browser (incl. Tracing, Replay) 71.23 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.67 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 75.57 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 88.3 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 90.14 KB - -
@sentry/browser (incl. metrics) 26.83 KB - -
@sentry/browser (incl. Feedback) 39.6 KB - -
@sentry/browser (incl. sendFeedback) 27.19 KB - -
@sentry/browser (incl. FeedbackAsync) 31.9 KB - -
@sentry/react 25.28 KB - -
@sentry/react (incl. Tracing) 37.74 KB - -
@sentry/vue 26.67 KB - -
@sentry/vue (incl. Tracing) 36.61 KB - -
@sentry/svelte 22.65 KB - -
CDN Bundle 23.77 KB - -
CDN Bundle (incl. Tracing) 36.49 KB - -
CDN Bundle (incl. Tracing, Replay) 70.91 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 76.22 KB - -
CDN Bundle - uncompressed 69.63 KB - -
CDN Bundle (incl. Tracing) - uncompressed 108.21 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 219.87 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.07 KB - -
@sentry/nextjs (client) 37.51 KB - -
@sentry/sveltekit (client) 35.35 KB - -
@sentry/node 126.36 KB +1.11% +1.38 KB 🔺
@sentry/node - without tracing 98.84 KB +3.5% +3.34 KB 🔺
@sentry/aws-serverless 109.1 KB +1.48% +1.58 KB 🔺

View base workflow run

@nandi95
Copy link

nandi95 commented Sep 6, 2024

This indeed would be helpful as I have a project which a merge of a laravel a nuxt project. Nuxt project is in the folder nuxt and I have the srcDir in the nuxt config set. This module should respect that and the rootDir configuration of nuxt.

? path.join(cwd, 'public', `instrument.${type}.${e}`)

This indeed

@s1gr1d s1gr1d marked this pull request as ready for review September 6, 2024 14:12
@s1gr1d
Copy link
Member Author

s1gr1d commented Sep 6, 2024

@nandi95 If I understand you correctly, you are defining a curstom rootDir in the nuxt config?

@s1gr1d s1gr1d requested a review from Lms24 September 6, 2024 14:14
@nandi95
Copy link

nandi95 commented Sep 6, 2024

I only meant to say that I define a srcDir so it's not the default expected nuxt directory structure.
And remind that there's also a rootDir option.
This will especially be importent when nuxt 4 comes out and has a different folder structure.

if (moduleOptions.debug) {
// eslint-disable-next-line no-console
console.log(
'[Sentry] Using your `sentry.server.config` file for the server-side Sentry configuration. In case you have a `public/instrument.server` file, it will be ignored.',
Copy link
Member

Choose a reason for hiding this comment

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

(...) it will be ignored

This reads a bit confusing, which of the two files are being ignored?

I think we could check here for the existence of the file and log explicitly if that file is getting ignored, wdyt?

Also, we are ignoring the public file here but users will still potentially --import it. This log makes it sound like it's completely ignored.

Copy link
Member

@Lms24 Lms24 Sep 9, 2024

Choose a reason for hiding this comment

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

I think this log should be split up.

1st part (public): can we log a warning if we detect the file in public instead of the first part of this message? Otherwise, I don't think we need to bother users with it, right?

To the second part: Can we instead print the exact import command? Something like

"Make sure to add --import ./.output/sentry.server.config.mjs to your NODE_OPTIONS env variable"

if (moduleOptions.debug) {
// eslint-disable-next-line no-console
console.log(
'[Sentry] Successfully added the content of the `sentry.server.config` file as `instrument-sentry.mjs` to the `.output/server` directory',
Copy link
Member

Choose a reason for hiding this comment

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

l: Maybe we can use destination here?

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Nice work! Other than the console log, this looks good to me!

We can follow up with the e2e tests after this is merged, given we hit some road blocks there

Comment on lines 49 to 65
it('should return the server file with .ts extension if it exists', () => {
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => {
return !(filePath instanceof URL) && filePath.includes('sentry.server.config.ts');
});

const result = findDefaultSdkInitFile('server');
expect(result).toBe('sentry.server.config.ts');
});

it('should return the client file with .mjs extension if it exists', () => {
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => {
return !(filePath instanceof URL) && filePath.includes('sentry.client.config.mjs');
});

const result = findDefaultSdkInitFile('client');
expect(result).toBe('sentry.client.config.mjs');
});
Copy link
Member

Choose a reason for hiding this comment

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

l: For some test extra credit (feel free to disregard) - we could use an it.each to test against all file types we search for.

@s1gr1d s1gr1d merged commit 45156d2 into develop Sep 9, 2024
102 checks passed
@s1gr1d s1gr1d deleted the sig/server-config-nuxt branch September 9, 2024 10:18
@wanderowski
Copy link

Hello! Thank you for the work you have done!

Could you please clarify, should we somehow modify the command for running the project on server in package.json? I see that now we can put sentry.server.config.ts in the root folder, but did not find any instructions on how to modify starting command. Previously, it was required to paste this:

{
  "scripts": {
    "preview": "NODE_OPTIONS='--import ./public/instrument.server.mjs' nuxt preview",
    "start": "node --import .output/public/instrument.server.mjs .output/server/index.mjs"
  }
}

If i put my config file in the root folder and deleted instrument.server.mjs from public folder, should I modify these commands as well?

@s1gr1d
Copy link
Member Author

s1gr1d commented Sep 10, 2024

@wanderowski This PR is not released yet and more elaborate docs on this are still coming for the official docs page.

The file can be added like this:

"start": "node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs",

As it only affects the server, it can only be added to the start script. The preview script attempts to load data from the .nuxt folder as well and this would not work. It worked with the public folder as this folder is the same during development and in production.

However, it could be that your environment variables from the .env file are not yet loaded. You can explicitly include them with --env-file=.env (like described here).

@wanderowski
Copy link

@s1gr1d Thanks!

alexandresoro pushed a commit to alexandresoro/ouca that referenced this pull request Sep 12, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@sentry/node](https://github.com/getsentry/sentry-javascript/tree/master/packages/node) ([source](https://github.com/getsentry/sentry-javascript)) | dependencies | minor | [`8.26.0` -> `8.30.0`](https://renovatebot.com/diffs/npm/@sentry%2fnode/8.26.0/8.30.0) |
| [@sentry/react](https://github.com/getsentry/sentry-javascript/tree/master/packages/react) ([source](https://github.com/getsentry/sentry-javascript)) | dependencies | minor | [`8.26.0` -> `8.30.0`](https://renovatebot.com/diffs/npm/@sentry%2freact/8.26.0/8.30.0) |

---

### Release Notes

<details>
<summary>getsentry/sentry-javascript (@&#8203;sentry/node)</summary>

### [`v8.30.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8300)

[Compare Source](getsentry/sentry-javascript@8.29.0...8.30.0)

##### Important Changes

-   *feat(node): Add `kafkajs` integration ([#&#8203;13528](getsentry/sentry-javascript#13528

This release adds a new integration that instruments `kafkajs` library with spans and traces. This integration is
automatically enabled by default, but can be included with the `Sentry.kafkaIntegration()` import.

```js
Sentry.init({
  integrations: [Sentry.kafkaIntegration()],
});
```

##### Other Changes

-   feat(core): Allow adding measurements without global client ([#&#8203;13612](getsentry/sentry-javascript#13612))
-   feat(deps): Bump [@&#8203;opentelemetry/instrumentation-undici](https://github.com/opentelemetry/instrumentation-undici) from 0.5.0 to 0.6.0 ([#&#8203;13622](getsentry/sentry-javascript#13622))
-   feat(deps): Bump [@&#8203;sentry/cli](https://github.com/sentry/cli) from 2.33.0 to 2.35.0 ([#&#8203;13624](getsentry/sentry-javascript#13624))
-   feat(node): Use `@opentelemetry/instrumentation-undici` for fetch tracing ([#&#8203;13485](getsentry/sentry-javascript#13485))
-   feat(nuxt): Add server config to root folder ([#&#8203;13583](getsentry/sentry-javascript#13583))
-   feat(otel): Upgrade [@&#8203;opentelemetry/semantic-conventions](https://github.com/opentelemetry/semantic-conventions) to 1.26.0 ([#&#8203;13631](getsentry/sentry-javascript#13631))
-   fix(browser): check supportedEntryTypes before caling the function ([#&#8203;13541](getsentry/sentry-javascript#13541))
-   fix(browser): Ensure Standalone CLS span timestamps are correct ([#&#8203;13649](getsentry/sentry-javascript#13649))
-   fix(nextjs): Widen removal of 404 transactions ([#&#8203;13628](getsentry/sentry-javascript#13628))
-   fix(node): Remove ambiguity and race conditions when matching local variables to exceptions ([#&#8203;13501](getsentry/sentry-javascript#13501))
-   fix(node): Update OpenTelemetry instrumentation package for solidstart and opentelemetry ([#&#8203;13640](getsentry/sentry-javascript#13640))
-   fix(node): Update OpenTelemetry instrumentation package for solidstart and opentelemetry ([#&#8203;13642](getsentry/sentry-javascript#13642))
-   fix(vue): Ensure Vue `trackComponents` list matches components with or without `<>` ([#&#8203;13543](getsentry/sentry-javascript#13543))
-   ref(profiling): Conditionally shim cjs globals ([#&#8203;13267](getsentry/sentry-javascript#13267))

Work in this release was contributed by [@&#8203;Zen-cronic](https://github.com/Zen-cronic) and [@&#8203;odanado](https://github.com/odanado). Thank you for your contributions!

### [`v8.29.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8290)

[Compare Source](getsentry/sentry-javascript@8.28.0...8.29.0)

##### Important Changes

-   **Beta releases of official Solid and SolidStart Sentry SDKs**

This release marks the beta releases of the `@sentry/solid` and `@sentry/solidstart` Sentry SDKs. For details on how to
use them, check out the
[Sentry Solid SDK README](https://github.com/getsentry/sentry-javascript/tree/develop/packages/solid) and the
[Sentry SolidStart SDK README](https://github.com/getsentry/sentry-javascript/tree/develop/packages/solidstart)
respectively. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have
any feedback or concerns.

-   **feat(node): Option to only wrap instrumented modules ([#&#8203;13139](getsentry/sentry-javascript#13139

Adds the SDK option to only wrap ES modules with `import-in-the-middle` that specifically need to be instrumented.

```javascript
import * as Sentry from '@&#8203;sentry/node';

Sentry.init({
  dsn: '__PUBLIC_DSN__',
  registerEsmLoaderHooks: { onlyIncludeInstrumentedModules: true },
});
```

-   **feat(node): Update OpenTelemetry packages to instrumentation v0.53.0 ([#&#8203;13587](getsentry/sentry-javascript#13587

All internal OpenTelemetry instrumentation was updated to their latest version. This adds support for Mongoose v7 and v8
and fixes various bugs related to ESM mode.

##### Other Changes

-   feat(nextjs): Emit warning when using turbopack ([#&#8203;13566](getsentry/sentry-javascript#13566))
-   feat(nextjs): Future-proof Next.js config options overriding ([#&#8203;13586](getsentry/sentry-javascript#13586))
-   feat(node): Add `generic-pool` integration ([#&#8203;13465](getsentry/sentry-javascript#13465))
-   feat(nuxt): Upload sourcemaps generated by Nitro ([#&#8203;13382](getsentry/sentry-javascript#13382))
-   feat(solidstart): Add `browserTracingIntegration` by default ([#&#8203;13561](getsentry/sentry-javascript#13561))
-   feat(solidstart): Add `sentrySolidStartVite` plugin to simplify source maps upload ([#&#8203;13493](getsentry/sentry-javascript#13493))
-   feat(vue): Only start UI spans if parent is available ([#&#8203;13568](getsentry/sentry-javascript#13568))
-   fix(cloudflare): Guard `context.waitUntil` call in request handler ([#&#8203;13549](getsentry/sentry-javascript#13549))
-   fix(gatsby): Fix assets path for sourcemaps upload ([#&#8203;13592](getsentry/sentry-javascript#13592))
-   fix(nextjs): Use posix paths for sourcemap uploads ([#&#8203;13603](getsentry/sentry-javascript#13603))
-   fix(node-fetch): Use stringified origin url ([#&#8203;13581](getsentry/sentry-javascript#13581))
-   fix(node): Replace dashes in `generic-pool` span origins with underscores ([#&#8203;13579](getsentry/sentry-javascript#13579))
-   fix(replay): Fix types in WebVitalData ([#&#8203;13573](getsentry/sentry-javascript#13573))
-   fix(replay): Improve replay web vital types ([#&#8203;13602](getsentry/sentry-javascript#13602))
-   fix(utils): Keep logger on carrier ([#&#8203;13570](getsentry/sentry-javascript#13570))

Work in this release was contributed by [@&#8203;Zen-cronic](https://github.com/Zen-cronic). Thank you for your contribution!

### [`v8.28.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8280)

[Compare Source](getsentry/sentry-javascript@8.27.0...8.28.0)

##### Important Changes

-   **Beta release of official NestJS SDK**

This release contains the beta version of `@sentry/nestjs`! For details on how to use it, check out the
[README](https://github.com/getsentry/sentry-javascript/blob/master/packages/nestjs/README.md). Any feedback/bug reports
are greatly appreciated, please reach out on GitHub.

-   **fix(browser): Remove faulty LCP, FCP and FP normalization logic ([#&#8203;13502](getsentry/sentry-javascript#13502

This release fixes a bug in the `@sentry/browser` package and all SDKs depending on this package (e.g. `@sentry/react`
or `@sentry/nextjs`) that caused the SDK to send incorrect web vital values for the LCP, FCP and FP vitals. The SDK
previously incorrectly processed the original values as they were reported from the browser. When updating your SDK to
this version, you might experience an increase in LCP, FCP and FP values, which potentially leads to a decrease in your
performance score in the Web Vitals Insights module in Sentry. This is because the previously reported values were
smaller than the actually measured values. We apologize for the inconvenience!

##### Other Changes

-   feat(nestjs): Add `SentryGlobalGraphQLFilter` ([#&#8203;13545](getsentry/sentry-javascript#13545))
-   feat(nestjs): Automatic instrumentation of nestjs interceptors after route execution ([#&#8203;13264](getsentry/sentry-javascript#13264))
-   feat(nextjs): Add `bundleSizeOptimizations` to build options ([#&#8203;13323](getsentry/sentry-javascript#13323))
-   feat(nextjs): Stabilize `captureRequestError` ([#&#8203;13550](getsentry/sentry-javascript#13550))
-   feat(nuxt): Wrap config in nuxt context ([#&#8203;13457](getsentry/sentry-javascript#13457))
-   feat(profiling): Expose profiler as top level primitive ([#&#8203;13512](getsentry/sentry-javascript#13512))
-   feat(replay): Add layout shift to CLS replay data ([#&#8203;13386](getsentry/sentry-javascript#13386))
-   feat(replay): Upgrade rrweb packages to 2.26.0 ([#&#8203;13483](getsentry/sentry-javascript#13483))
-   fix(cdn): Do not mangle \_metadata ([#&#8203;13426](getsentry/sentry-javascript#13426))
-   fix(cdn): Fix SDK source for CDN bundles ([#&#8203;13475](getsentry/sentry-javascript#13475))
-   fix(nestjs): Check arguments before instrumenting with `@Injectable` ([#&#8203;13544](getsentry/sentry-javascript#13544))
-   fix(nestjs): Ensure exception and host are correctly passed on when using [@&#8203;WithSentry](https://github.com/WithSentry) ([#&#8203;13564](getsentry/sentry-javascript#13564))
-   fix(node): Suppress tracing for transport request execution rather than transport creation ([#&#8203;13491](getsentry/sentry-javascript#13491))
-   fix(replay): Consider more things as DOM mutations for dead clicks ([#&#8203;13518](getsentry/sentry-javascript#13518))
-   fix(vue): Correctly obtain component name ([#&#8203;13484](getsentry/sentry-javascript#13484))

Work in this release was contributed by [@&#8203;leopoldkristjansson](https://github.com/leopoldkristjansson), [@&#8203;mhuggins](https://github.com/mhuggins) and [@&#8203;filips123](https://github.com/filips123). Thank you for your
contributions!

### [`v8.27.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8270)

[Compare Source](getsentry/sentry-javascript@8.26.0...8.27.0)

##### Important Changes

-   **fix(nestjs): Exception filters in main app module are not being executed ([#&#8203;13278](getsentry/sentry-javascript#13278

    With this release nestjs error monitoring is no longer automatically set up after adding the `SentryModule` to your
    application, which led to issues in certain scenarios. You will now have to either add the `SentryGlobalFilter` to
    your main module providers or decorate the `catch()` method in your existing global exception filters with the newly
    released `@WithSentry()` decorator. See the [docs](https://docs.sentry.io/platforms/javascript/guides/nestjs/) for
    more details.

##### Other Changes

-   feat: Add options for passing nonces to feedback integration ([#&#8203;13347](getsentry/sentry-javascript#13347))
-   feat: Add support for SENTRY_SPOTLIGHT env var in Node ([#&#8203;13325](getsentry/sentry-javascript#13325))
-   feat(deps): bump [@&#8203;prisma/instrumentation](https://github.com/prisma/instrumentation) from 5.17.0 to 5.18.0 ([#&#8203;13327](getsentry/sentry-javascript#13327))
-   feat(feedback): Improve error message for 403 errors ([#&#8203;13441](getsentry/sentry-javascript#13441))
-   fix(deno): Don't rely on `Deno.permissions.querySync` ([#&#8203;13378](getsentry/sentry-javascript#13378))
-   fix(replay): Ensure we publish replay CDN bundles ([#&#8203;13437](getsentry/sentry-javascript#13437))

Work in this release was contributed by [@&#8203;charpeni](https://github.com/charpeni). Thank you for your contribution!

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC41NS4zIiwidXBkYXRlZEluVmVyIjoiMzguNzMuNyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19-->

Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/61
Reviewed-by: Alexandre Soro <[email protected]>
Co-authored-by: renovate <[email protected]>
Co-committed-by: renovate <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants