Skip to content

Commit 7c848bf

Browse files
authored
Merge branch 'develop' into patch-1
2 parents 85bcbcc + d4e94fe commit 7c848bf

File tree

184 files changed

+3011
-2293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+3011
-2293
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ jobs:
267267
run: yarn lint:lerna
268268
- name: Lint C++ files
269269
run: yarn lint:clang
270+
- name: Lint for ES compatibility
271+
run: yarn lint:es-compatibility
270272

271273
job_check_format:
272274
name: Check file formatting

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,50 @@
1212

1313
Work in this release was contributed by @aloisklink, @arturovt, @benjick and @maximepvrt. Thank you for your contributions!
1414

15+
- **feat(solidstart)!: Default to `--import` setup and add `autoInjectServerSentry` ([#14862](https://github.com/getsentry/sentry-javascript/pull/14862))**
16+
17+
To enable the SolidStart SDK, wrap your SolidStart Config with `withSentry`. The `sentrySolidStartVite` plugin is now automatically
18+
added by `withSentry` and you can pass the Sentry build-time options like this:
19+
20+
```js
21+
import { defineConfig } from '@solidjs/start/config';
22+
import { withSentry } from '@sentry/solidstart';
23+
24+
export default defineConfig(
25+
withSentry(
26+
{
27+
/* Your SolidStart config options... */
28+
},
29+
{
30+
// Options for setting up source maps
31+
org: process.env.SENTRY_ORG,
32+
project: process.env.SENTRY_PROJECT,
33+
authToken: process.env.SENTRY_AUTH_TOKEN,
34+
},
35+
),
36+
);
37+
```
38+
39+
With the `withSentry` wrapper, the Sentry server config should not be added to the `public` directory anymore.
40+
Add the Sentry server config in `src/instrument.server.ts`. Then, the server config will be placed inside the server build output as `instrument.server.mjs`.
41+
42+
Now, there are two options to set up the SDK:
43+
44+
1. **(recommended)** Provide an `--import` CLI flag to the start command like this (path depends on your server setup):
45+
`node --import ./.output/server/instrument.server.mjs .output/server/index.mjs`
46+
2. Add `autoInjectServerSentry: 'top-level-import'` and the Sentry config will be imported at the top of the server entry (comes with tracing limitations)
47+
```js
48+
withSentry(
49+
{
50+
/* Your SolidStart config options... */
51+
},
52+
{
53+
// Optional: Install Sentry with a top-level import
54+
autoInjectServerSentry: 'top-level-import',
55+
},
56+
);
57+
```
58+
1559
## 8.45.0
1660

1761
- feat(core): Add `handled` option to `captureConsoleIntegration` ([#14664](https://github.com/getsentry/sentry-javascript/pull/14664))

MIGRATION.md

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -870,53 +870,35 @@ or look at the TypeScript type definitions of `withSentryConfig`.
870870
871871
#### Updated the recommended way of calling `Sentry.init()`
872872
873-
With version 8 of the SDK we will no longer support the use of `sentry.server.config.ts` and `sentry.edge.config.ts`
874-
files. Instead, please initialize the Sentry Next.js SDK for the serverside in a
875-
[Next.js instrumentation hook](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation).
876-
**`sentry.client.config.ts|js` is still supported and encouraged for initializing the clientside SDK.**
873+
Version 8 of the Next.js SDK will require an additional `instrumentation.ts` file to execute the `sentry.server.config.js|ts` and `sentry.edge.config.js|ts` modules to initialize the SDK for the server-side.
874+
The `instrumentation.ts` file is a Next.js native API called [instrumentation hook](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation).
877875
878-
The following is an example of how to initialize the serverside SDK in a Next.js instrumentation hook:
876+
To start using the Next.js instrumentation hook, follow these steps:
879877
880-
1. First, enable the Next.js instrumentation hook by setting the `experimental.instrumentationHook` to `true` in your
881-
`next.config.js`.
882-
2. Next, create a `instrumentation.ts|js` file in the root directory of your project (or in the `src` folder if you have
883-
have one).
884-
3. Now, export a `register` function from the `instrumentation.ts|js` file and call `Sentry.init()` inside of it:
878+
1. First, enable the Next.js instrumentation hook by setting the [`experimental.instrumentationHook`](https://nextjs.org/docs/app/api-reference/next-config-js/instrumentationHook) to true in your `next.config.js`. (This step is no longer required with Next.js 15)
885879
886-
```ts
887-
import * as Sentry from '@sentry/nextjs';
888-
889-
export function register() {
890-
if (process.env.NEXT_RUNTIME === 'nodejs') {
891-
Sentry.init({
892-
dsn: 'YOUR_DSN',
893-
// Your Node.js Sentry configuration...
894-
});
895-
}
896-
897-
if (process.env.NEXT_RUNTIME === 'edge') {
898-
Sentry.init({
899-
dsn: 'YOUR_DSN',
900-
// Your Edge Runtime Sentry configuration...
901-
});
902-
}
880+
```JavaScript {filename:next.config.js} {2-4}
881+
module.exports = {
882+
experimental: {
883+
instrumentationHook: true, // Not required on Next.js 15+
884+
},
903885
}
904886
```
905887
906-
If you need to import a Node.js specific integration (like for example `@sentry/profiling-node`), you will have to
907-
import the package using a dynamic import to prevent Next.js from bundling Node.js APIs into bundles for other
908-
runtime environments (like the Browser or the Edge runtime). You can do so as follows:
888+
2. Next, create a `instrumentation.ts|js` file in the root directory of your project (or in the src folder if you have have one).
889+
890+
3. Now, export a register function from the `instrumentation.ts|js` file and import your `sentry.server.config.js|ts` and `sentry.edge.config.js|ts` modules:
909891
910-
```ts
892+
```JavaScript {filename:instrumentation.js}
911893
import * as Sentry from '@sentry/nextjs';
912894

913895
export async function register() {
914896
if (process.env.NEXT_RUNTIME === 'nodejs') {
915-
const { nodeProfilingIntegration } = await import('@sentry/profiling-node');
916-
Sentry.init({
917-
dsn: 'YOUR_DSN',
918-
integrations: [nodeProfilingIntegration()],
919-
});
897+
await import('./sentry.server.config');
898+
}
899+
900+
if (process.env.NEXT_RUNTIME === 'edge') {
901+
await import('./sentry.edge.config');
920902
}
921903
}
922904
```

dev-packages/browser-integration-tests/suites/integrations/captureConsole-attachStackTrace/init.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ window.Sentry = Sentry;
66
Sentry.init({
77
dsn: 'https://[email protected]/1337',
88
integrations: [captureConsoleIntegration()],
9-
autoSessionTracking: false,
109
attachStacktrace: true,
1110
});

dev-packages/browser-integration-tests/suites/integrations/captureConsole/init.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ window.Sentry = Sentry;
66
Sentry.init({
77
dsn: 'https://[email protected]/1337',
88
integrations: [captureConsoleIntegration()],
9-
autoSessionTracking: false,
109
});

dev-packages/browser-integration-tests/suites/sessions/update-session/test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { expect } from '@playwright/test';
22
import type { SessionContext } from '@sentry/core';
33

44
import { sentryTest } from '../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
5+
import { getFirstSentryEnvelopeRequest, waitForSession } from '../../../utils/helpers';
66

77
sentryTest('should update session when an error is thrown.', async ({ getLocalTestUrl, page }) => {
88
const url = await getLocalTestUrl({ testDir: __dirname });
9+
910
const pageloadSession = await getFirstSentryEnvelopeRequest<SessionContext>(page, url);
10-
const updatedSession = (
11-
await Promise.all([page.locator('#throw-error').click(), getFirstSentryEnvelopeRequest<SessionContext>(page)])
12-
)[1];
11+
12+
const updatedSessionPromise = waitForSession(page);
13+
await page.locator('#throw-error').click();
14+
const updatedSession = await updatedSessionPromise;
1315

1416
expect(pageloadSession).toBeDefined();
1517
expect(pageloadSession.init).toBe(true);
@@ -25,9 +27,10 @@ sentryTest('should update session when an exception is captured.', async ({ getL
2527
const url = await getLocalTestUrl({ testDir: __dirname });
2628

2729
const pageloadSession = await getFirstSentryEnvelopeRequest<SessionContext>(page, url);
28-
const updatedSession = (
29-
await Promise.all([page.locator('#capture-exception').click(), getFirstSentryEnvelopeRequest<SessionContext>(page)])
30-
)[1];
30+
31+
const updatedSessionPromise = waitForSession(page);
32+
await page.locator('#capture-exception').click();
33+
const updatedSession = await updatedSessionPromise;
3134

3235
expect(pageloadSession).toBeDefined();
3336
expect(pageloadSession.init).toBe(true);

dev-packages/browser-integration-tests/suites/sessions/v7-hub-start-session/init.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ window.Sentry = Sentry;
55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
77
release: '0.1',
8-
// intentionally disabling this, we want to leverage the deprecated hub API
9-
autoSessionTracking: false,
108
});
119

1210
// simulate old startSessionTracking behavior

dev-packages/browser-integration-tests/utils/helpers.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
Event,
88
EventEnvelope,
99
EventEnvelopeHeaders,
10+
SessionContext,
1011
TransactionEvent,
1112
} from '@sentry/core';
1213

@@ -157,7 +158,7 @@ export const countEnvelopes = async (
157158
* @param {{ path?: string; content?: string }} impl
158159
* @return {*} {Promise<void>}
159160
*/
160-
async function runScriptInSandbox(
161+
export async function runScriptInSandbox(
161162
page: Page,
162163
impl: {
163164
path?: string;
@@ -178,7 +179,7 @@ async function runScriptInSandbox(
178179
* @param {string} [url]
179180
* @return {*} {Promise<Array<Event>>}
180181
*/
181-
async function getSentryEvents(page: Page, url?: string): Promise<Array<Event>> {
182+
export async function getSentryEvents(page: Page, url?: string): Promise<Array<Event>> {
182183
if (url) {
183184
await page.goto(url);
184185
}
@@ -250,6 +251,25 @@ export function waitForTransactionRequest(
250251
});
251252
}
252253

254+
export async function waitForSession(page: Page): Promise<SessionContext> {
255+
const req = await page.waitForRequest(req => {
256+
const postData = req.postData();
257+
if (!postData) {
258+
return false;
259+
}
260+
261+
try {
262+
const event = envelopeRequestParser<SessionContext>(req);
263+
264+
return typeof event.init === 'boolean' && event.started !== undefined;
265+
} catch {
266+
return false;
267+
}
268+
});
269+
270+
return envelopeRequestParser<SessionContext>(req);
271+
}
272+
253273
/**
254274
* We can only test tracing tests in certain bundles/packages:
255275
* - NPM (ESM, CJS)
@@ -353,7 +373,7 @@ async function getMultipleRequests<T>(
353373
/**
354374
* Wait and get multiple envelope requests at the given URL, or the current page
355375
*/
356-
async function getMultipleSentryEnvelopeRequests<T>(
376+
export async function getMultipleSentryEnvelopeRequests<T>(
357377
page: Page,
358378
count: number,
359379
options?: {
@@ -374,7 +394,7 @@ async function getMultipleSentryEnvelopeRequests<T>(
374394
* @param {string} [url]
375395
* @return {*} {Promise<T>}
376396
*/
377-
async function getFirstSentryEnvelopeRequest<T>(
397+
export async function getFirstSentryEnvelopeRequest<T>(
378398
page: Page,
379399
url?: string,
380400
requestParser: (req: Request) => T = envelopeRequestParser as (req: Request) => T,
@@ -388,5 +408,3 @@ async function getFirstSentryEnvelopeRequest<T>(
388408

389409
return req;
390410
}
391-
392-
export { runScriptInSandbox, getMultipleSentryEnvelopeRequests, getFirstSentryEnvelopeRequest, getSentryEvents };
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { sentrySolidStartVite } from '@sentry/solidstart';
1+
import { withSentry } from '@sentry/solidstart';
22
import { defineConfig } from '@solidjs/start/config';
33

4-
export default defineConfig({
5-
ssr: false,
6-
vite: {
7-
plugins: [sentrySolidStartVite()],
8-
},
9-
});
4+
export default defineConfig(
5+
withSentry({
6+
ssr: false,
7+
middleware: './src/middleware.ts',
8+
}),
9+
);

dev-packages/e2e-tests/test-applications/solidstart-spa/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "0.0.0",
44
"scripts": {
55
"clean": "pnpx rimraf node_modules pnpm-lock.yaml .vinxi .output",
6-
"dev": "NODE_OPTIONS='--import ./src/instrument.server.mjs' vinxi dev",
7-
"build": "vinxi build && sh ./post_build.sh",
8-
"preview": "HOST=localhost PORT=3030 NODE_OPTIONS='--import ./src/instrument.server.mjs' vinxi start",
6+
"build": "vinxi build && sh post_build.sh",
7+
"preview": "HOST=localhost PORT=3030 vinxi start",
8+
"start:import": "HOST=localhost PORT=3030 node --import ./.output/server/instrument.server.mjs .output/server/index.mjs",
99
"test:prod": "TEST_ENV=production playwright test",
1010
"test:build": "pnpm install && pnpm build",
1111
"test:assert": "pnpm test:prod"

0 commit comments

Comments
 (0)