diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66b282202f5e..4b3125c09eb1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -817,13 +817,20 @@ jobs: uses: ./.github/actions/restore-cache env: DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check tarball cache - uses: actions/cache@v3 + - name: NX cache + uses: actions/cache/restore@v3 with: - path: ${{ github.workspace }}/packages/*/*.tgz - key: ${{ env.BUILD_CACHE_TARBALL_KEY }} + path: .nxcache + key: nx-Linux-${{ github.ref }}-${{ env.HEAD_COMMIT }} + # On develop branch, we want to _store_ the cache (so it can be used by other branches), but never _restore_ from it + restore-keys: ${{ env.NX_CACHE_RESTORE_KEYS }} - name: Build tarballs run: yarn build:tarball + - name: Stores tarballs in cache + uses: actions/cache/save@v3 + with: + path: ${{ github.workspace }}/packages/*/*.tgz + key: ${{ env.BUILD_CACHE_TARBALL_KEY }} job_e2e_tests: name: E2E ${{ matrix.label || matrix.test-application }} Test @@ -877,6 +884,12 @@ jobs: - test-application: 'standard-frontend-react' build-command: 'test:build-ts3.8' label: 'standard-frontend-react (TS 3.8)' + - test-application: 'create-next-app' + build-command: 'test:build-13' + label: 'create-next-app (next@13)' + - test-application: 'nextjs-app-dir' + build-command: 'test:build-13' + label: 'nextjs-app-dir (next@13)' steps: - name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }}) diff --git a/.gitignore b/.gitignore index d6eee47e4eed..777b23658572 100644 --- a/.gitignore +++ b/.gitignore @@ -21,8 +21,6 @@ jest/transformers/*.js # node tarballs packages/*/sentry-*.tgz .nxcache -# The Deno types are downloaded before building -packages/deno/lib.deno.d.ts # logs yarn-error.log diff --git a/CHANGELOG.md b/CHANGELOG.md index efae6874fd65..cb1d998f360a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,52 @@ - "You miss 100 percent of the chances you don't take. β€” Wayne Gretzky" β€” Michael Scott +## 7.76.0 + +### Important Changes + +- **feat(core): Add cron monitor wrapper helper (#9395)** + +This release adds `Sentry.withMonitor()`, a wrapping function that wraps a callback with a cron monitor that will automatically report completions and failures: + +```ts +import * as Sentry from '@sentry/node'; + +// withMonitor() will send checkin when callback is started/finished +// works with async and sync callbacks. +const result = Sentry.withMonitor( + 'dailyEmail', + () => { + // withCheckIn return value is same return value here + return sendEmail(); + }, + // Optional upsert options + { + schedule: { + type: 'crontab', + value: '0 * * * *', + }, + // πŸ‡¨πŸ‡¦πŸ«‘ + timezone: 'Canada/Eastern', + }, +); +``` + +### Other Changes + +- chore(angular-ivy): Allow Angular 17 in peer dependencies (#9386) +- feat(nextjs): Instrument SSR page components (#9346) +- feat(nextjs): Trace errors in page component SSR (#9388) +- fix(nextjs): Instrument route handlers with `jsx` and `tsx` file extensions (#9362) +- fix(nextjs): Trace with performance disabled (#9389) +- fix(replay): Ensure `replay_id` is not added to DSC if session expired (#9359) +- fix(replay): Remove unused parts of pako from build (#9369) +- fix(serverless): Don't mark all errors as unhandled (#9368) +- fix(tracing-internal): Fix case when middleware contain array of routes with special chars as @ (#9375) +- meta(nextjs): Bump peer deps for Next.js 14 (#9390) + +Work in this release contributed by @LubomirIgonda1. Thank you for your contribution! + ## 7.75.1 - feat(browser): Allow collecting of pageload profiles (#9317) diff --git a/packages/angular-ivy/README.md b/packages/angular-ivy/README.md index 9546888170e6..f487ffa22707 100644 --- a/packages/angular-ivy/README.md +++ b/packages/angular-ivy/README.md @@ -16,7 +16,7 @@ ## Angular Version Compatibility -This SDK officially supports Angular 12 to 16 with Angular's new rendering engine, Ivy. +This SDK officially supports Angular 12 to 17 with Angular's new rendering engine, Ivy. If you're using Angular 10, 11 or a newer Angular version with View Engine instead of Ivy, please use [`@sentry/angular`](https://github.com/getsentry/sentry-javascript/blob/develop/packages/angular/README.md). diff --git a/packages/angular-ivy/package.json b/packages/angular-ivy/package.json index d7ec11952994..7bc79f4bf234 100644 --- a/packages/angular-ivy/package.json +++ b/packages/angular-ivy/package.json @@ -15,9 +15,9 @@ "access": "public" }, "peerDependencies": { - "@angular/common": ">= 12.x <= 16.x", - "@angular/core": ">= 12.x <= 16.x", - "@angular/router": ">= 12.x <= 16.x", + "@angular/common": ">= 12.x <= 17.x", + "@angular/core": ">= 12.x <= 17.x", + "@angular/router": ">= 12.x <= 17.x", "rxjs": "^6.5.5 || ^7.x" }, "dependencies": { diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index 7a28bf907d48..2d174277b0af 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -13,6 +13,7 @@ export { captureEvent, captureMessage, captureCheckIn, + withMonitor, configureScope, createTransport, extractTraceparentData, diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index c8428ab8e106..1f10a0d265e8 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -55,6 +55,7 @@ export { trace, withScope, captureCheckIn, + withMonitor, setMeasurement, getActiveSpan, startSpan, diff --git a/packages/core/src/exports.ts b/packages/core/src/exports.ts index 1a143a2efd4e..6569bc4e4c25 100644 --- a/packages/core/src/exports.ts +++ b/packages/core/src/exports.ts @@ -7,6 +7,7 @@ import type { EventHint, Extra, Extras, + FinishedCheckIn, MonitorConfig, Primitive, Severity, @@ -14,7 +15,7 @@ import type { TransactionContext, User, } from '@sentry/types'; -import { logger, uuid4 } from '@sentry/utils'; +import { isThenable, logger, timestampInSeconds, uuid4 } from '@sentry/utils'; import type { Hub } from './hub'; import { getCurrentHub } from './hub'; @@ -210,6 +211,49 @@ export function captureCheckIn(checkIn: CheckIn, upsertMonitorConfig?: MonitorCo return uuid4(); } +/** + * Wraps a callback with a cron monitor check in. The check in will be sent to Sentry when the callback finishes. + * + * @param monitorSlug The distinct slug of the monitor. + * @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want + * to create a monitor automatically when sending a check in. + */ +export function withMonitor( + monitorSlug: CheckIn['monitorSlug'], + callback: () => T, + upsertMonitorConfig?: MonitorConfig, +): T { + const checkInId = captureCheckIn({ monitorSlug, status: 'in_progress' }, upsertMonitorConfig); + const now = timestampInSeconds(); + + function finishCheckIn(status: FinishedCheckIn['status']): void { + captureCheckIn({ monitorSlug, status, checkInId, duration: timestampInSeconds() - now }); + } + + let maybePromiseResult: T; + try { + maybePromiseResult = callback(); + } catch (e) { + finishCheckIn('error'); + throw e; + } + + if (isThenable(maybePromiseResult)) { + Promise.resolve(maybePromiseResult).then( + () => { + finishCheckIn('ok'); + }, + () => { + finishCheckIn('error'); + }, + ); + } else { + finishCheckIn('ok'); + } + + return maybePromiseResult; +} + /** * Call `flush()` on the current client, if there is one. See {@link Client.flush}. * diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index f14f5d4aaf2f..b80c83cdfdfa 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -7,6 +7,7 @@ export * from './tracing'; export { addBreadcrumb, captureCheckIn, + withMonitor, captureException, captureEvent, captureMessage, diff --git a/packages/deno/.gitignore b/packages/deno/.gitignore index 299ae4a5c2fd..d2de144a353c 100644 --- a/packages/deno/.gitignore +++ b/packages/deno/.gitignore @@ -1 +1,3 @@ build-types +build-test +lib.deno.d.ts diff --git a/packages/deno/package.json b/packages/deno/package.json index 54c9d174f018..24878690baad 100644 --- a/packages/deno/package.json +++ b/packages/deno/package.json @@ -48,7 +48,9 @@ "lint:eslint": "eslint . --format stylish", "lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"", "install:deno": "node ./scripts/install-deno.mjs", - "test": "run-s deno-types install:deno test:types test:unit", + "pretest": "run-s deno-types test:build", + "test": "run-s install:deno test:types test:unit", + "test:build": "tsc -p tsconfig.test.types.json && rollup -c rollup.test.config.js", "test:types": "deno check ./build/index.js", "test:unit": "deno test --allow-read --allow-run", "test:unit:update": "deno test --allow-read --allow-write --allow-run -- --update", diff --git a/packages/deno/rollup.test.config.js b/packages/deno/rollup.test.config.js new file mode 100644 index 000000000000..3947d0e94b16 --- /dev/null +++ b/packages/deno/rollup.test.config.js @@ -0,0 +1,42 @@ +// @ts-check +import dts from 'rollup-plugin-dts'; +import nodeResolve from '@rollup/plugin-node-resolve'; +import sucrase from '@rollup/plugin-sucrase'; +import { defineConfig } from 'rollup'; + +export default [ + defineConfig({ + input: ['test/build.ts'], + output: { + file: 'build-test/index.js', + sourcemap: true, + preserveModules: false, + strict: false, + freeze: false, + interop: 'auto', + format: 'esm', + banner: '/// ', + }, + plugins: [ + nodeResolve({ + extensions: ['.mjs', '.js', '.json', '.node', '.ts', '.tsx'], + }), + sucrase({ transforms: ['typescript'] }), + ], + }), + defineConfig({ + input: './build-test/build.d.ts', + output: [{ file: 'build-test/index.d.ts', format: 'es' }], + plugins: [ + dts({ respectExternal: true }), + // The bundled types contain a declaration for the __DEBUG_BUILD__ global + // This can result in errors about duplicate global declarations so we strip it out! + { + name: 'strip-global', + renderChunk(code) { + return { code: code.replace(/declare global \{\s*const __DEBUG_BUILD__: boolean;\s*\}/g, '') }; + }, + }, + ], + }), +]; diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index 6a92adea2513..52e881528866 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -53,6 +53,7 @@ export { trace, withScope, captureCheckIn, + withMonitor, setMeasurement, getActiveSpan, startSpan, diff --git a/packages/deno/test/__snapshots__/mod.test.ts.snap b/packages/deno/test/__snapshots__/mod.test.ts.snap index 2cdb246a8e8b..501508e1a268 100644 --- a/packages/deno/test/__snapshots__/mod.test.ts.snap +++ b/packages/deno/test/__snapshots__/mod.test.ts.snap @@ -82,7 +82,7 @@ snapshot[`captureException 1`] = ` filename: "app:///test/mod.test.ts", function: "", in_app: true, - lineno: 42, + lineno: 46, post_context: [ "", " await delay(200);", @@ -90,7 +90,7 @@ snapshot[`captureException 1`] = ` "});", "", "Deno.test('captureMessage', async t => {", - " let ev: Event | undefined;", + " let ev: sentryTypes.Event | undefined;", ], pre_context: [ " ev = event;", @@ -108,7 +108,7 @@ snapshot[`captureException 1`] = ` filename: "app:///test/mod.test.ts", function: "something", in_app: true, - lineno: 39, + lineno: 43, post_context: [ " }", "", @@ -120,7 +120,7 @@ snapshot[`captureException 1`] = ` ], pre_context: [ "Deno.test('captureException', async t => {", - " let ev: Event | undefined;", + " let ev: sentryTypes.Event | undefined;", " const [hub] = getTestClient(event => {", " ev = event;", " });", diff --git a/packages/deno/test/build.ts b/packages/deno/test/build.ts new file mode 100644 index 000000000000..b593fed2f4dd --- /dev/null +++ b/packages/deno/test/build.ts @@ -0,0 +1,4 @@ +// We use this as the entry point to bundle Sentry dependencies that are used by the tests. +export * as sentryTypes from '@sentry/types'; +export * as sentryUtils from '@sentry/utils'; +export * as sentryCore from '@sentry/core'; diff --git a/packages/deno/test/mod.test.ts b/packages/deno/test/mod.test.ts index 7f57616816d5..f457033efe96 100644 --- a/packages/deno/test/mod.test.ts +++ b/packages/deno/test/mod.test.ts @@ -1,20 +1,24 @@ import { assertEquals } from 'https://deno.land/std@0.202.0/assert/assert_equals.ts'; import { assertSnapshot } from 'https://deno.land/std@0.202.0/testing/snapshot.ts'; -import { createStackParser, nodeStackLineParser } from '../../utils/build/esm/index.js'; +import type { sentryTypes } from '../build-test/index.js'; +import { sentryUtils } from '../build-test/index.js'; import { defaultIntegrations, DenoClient, Hub, Scope } from '../build/index.js'; import { getNormalizedEvent } from './normalize.ts'; import { makeTestTransport } from './transport.ts'; -function getTestClient(callback: (event?: Event) => void, integrations: any[] = []): [Hub, DenoClient] { +function getTestClient( + callback: (event?: sentryTypes.Event) => void, + integrations: sentryTypes.Integration[] = [], +): [Hub, DenoClient] { const client = new DenoClient({ dsn: 'https://233a45e5efe34c47a3536797ce15dafa@nothing.here/5650507', debug: true, integrations: [...defaultIntegrations, ...integrations], - stackParser: createStackParser(nodeStackLineParser()), + stackParser: sentryUtils.createStackParser(sentryUtils.nodeStackLineParser()), transport: makeTestTransport(envelope => { callback(getNormalizedEvent(envelope)); - }) as any, + }), }); const scope = new Scope(); @@ -30,7 +34,7 @@ function delay(time: number): Promise { } Deno.test('captureException', async t => { - let ev: Event | undefined; + let ev: sentryTypes.Event | undefined; const [hub] = getTestClient(event => { ev = event; }); @@ -46,7 +50,7 @@ Deno.test('captureException', async t => { }); Deno.test('captureMessage', async t => { - let ev: Event | undefined; + let ev: sentryTypes.Event | undefined; const [hub] = getTestClient(event => { ev = event; }); diff --git a/packages/deno/test/normalize.ts b/packages/deno/test/normalize.ts index 45f631116955..64295932e00d 100644 --- a/packages/deno/test/normalize.ts +++ b/packages/deno/test/normalize.ts @@ -1,20 +1,21 @@ /* eslint-disable complexity */ -import { forEachEnvelopeItem } from '../../utils/build/esm/index.js'; +import type { sentryTypes } from '../build-test/index.js'; +import { sentryUtils } from '../build-test/index.js'; -type EventOrSession = any; +type EventOrSession = sentryTypes.Event | sentryTypes.Transaction | sentryTypes.Session; -export function getNormalizedEvent(envelope: any): any | undefined { - let event: any | undefined; +export function getNormalizedEvent(envelope: sentryTypes.Envelope): sentryTypes.Event | undefined { + let event: sentryTypes.Event | undefined; - forEachEnvelopeItem(envelope, (item: any) => { + sentryUtils.forEachEnvelopeItem(envelope, item => { const [headers, body] = item; if (headers.type === 'event') { - event = body; + event = body as sentryTypes.Event; } }); - return normalize(event) as any | undefined; + return normalize(event) as sentryTypes.Event | undefined; } export function normalize(event: EventOrSession | undefined): EventOrSession | undefined { @@ -23,14 +24,14 @@ export function normalize(event: EventOrSession | undefined): EventOrSession | u } if (eventIsSession(event)) { - return normalizeSession(event); + return normalizeSession(event as sentryTypes.Session); } else { - return normalizeEvent(event); + return normalizeEvent(event as sentryTypes.Event); } } export function eventIsSession(data: EventOrSession): boolean { - return !!data?.sid; + return !!(data as sentryTypes.Session)?.sid; } /** @@ -39,7 +40,7 @@ export function eventIsSession(data: EventOrSession): boolean { * All properties that are timestamps, versions, ids or variables that may vary * by platform are replaced with placeholder strings */ -function normalizeSession(session: any): any { +function normalizeSession(session: sentryTypes.Session): sentryTypes.Session { if (session.sid) { session.sid = '{{id}}'; } @@ -65,7 +66,7 @@ function normalizeSession(session: any): any { * All properties that are timestamps, versions, ids or variables that may vary * by platform are replaced with placeholder strings */ -function normalizeEvent(event: any): any { +function normalizeEvent(event: sentryTypes.Event): sentryTypes.Event { if (event.sdk?.version) { event.sdk.version = '{{version}}'; } @@ -153,7 +154,7 @@ function normalizeEvent(event: any): any { if (event.exception?.values?.[0].stacktrace?.frames) { // Exlcude Deno frames since these may change between versions event.exception.values[0].stacktrace.frames = event.exception.values[0].stacktrace.frames.filter( - (frame: any) => !frame.filename?.includes('deno:'), + frame => !frame.filename?.includes('deno:'), ); } diff --git a/packages/deno/test/transport.ts b/packages/deno/test/transport.ts index 2eaeed6eeef6..47cb86622cb7 100644 --- a/packages/deno/test/transport.ts +++ b/packages/deno/test/transport.ts @@ -1,30 +1,25 @@ -import { createTransport } from 'npm:@sentry/core'; -import type { - BaseTransportOptions, - Envelope, - Transport, - TransportMakeRequestResponse, - TransportRequest, -} from 'npm:@sentry/types'; -import { parseEnvelope } from 'npm:@sentry/utils'; +import type { sentryTypes } from '../build-test/index.js'; +import { sentryCore, sentryUtils } from '../build-test/index.js'; -export interface TestTransportOptions extends BaseTransportOptions { - callback: (envelope: Envelope) => void; +export interface TestTransportOptions extends sentryTypes.BaseTransportOptions { + callback: (envelope: sentryTypes.Envelope) => void; } /** * Creates a Transport that uses the Fetch API to send events to Sentry. */ -export function makeTestTransport(callback: (envelope: Envelope) => void) { - return (options: BaseTransportOptions): Transport => { - async function doCallback(request: TransportRequest): Promise { - await callback(parseEnvelope(request.body, new TextEncoder(), new TextDecoder())); +export function makeTestTransport(callback: (envelope: sentryTypes.Envelope) => void) { + return (options: sentryTypes.BaseTransportOptions): sentryTypes.Transport => { + async function doCallback( + request: sentryTypes.TransportRequest, + ): Promise { + await callback(sentryUtils.parseEnvelope(request.body, new TextEncoder(), new TextDecoder())); return Promise.resolve({ statusCode: 200, }); } - return createTransport(options, doCallback); + return sentryCore.createTransport(options, doCallback); }; } diff --git a/packages/deno/tsconfig.test.types.json b/packages/deno/tsconfig.test.types.json new file mode 100644 index 000000000000..1cac4cb38a90 --- /dev/null +++ b/packages/deno/tsconfig.test.types.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "include": ["./lib.deno.d.ts", "test/build.ts"], + "compilerOptions": { + "declaration": true, + "declarationMap": false, + "emitDeclarationOnly": true, + "outDir": "build-test" + } +} diff --git a/packages/e2e-tests/test-applications/create-next-app/package.json b/packages/e2e-tests/test-applications/create-next-app/package.json index 58b89cb7dda7..c74dc5c414e1 100644 --- a/packages/e2e-tests/test-applications/create-next-app/package.json +++ b/packages/e2e-tests/test-applications/create-next-app/package.json @@ -8,6 +8,7 @@ "test:prod": "TEST_ENV=prod playwright test", "test:dev": "TEST_ENV=dev playwright test", "test:build": "pnpm install && npx playwright install && pnpm build", + "test:build-13": "pnpm install && pnpm add next@13.4.19 && npx playwright install && pnpm build", "test:assert": "pnpm test:prod && pnpm test:dev" }, "dependencies": { @@ -16,7 +17,7 @@ "@types/node": "18.11.17", "@types/react": "18.0.26", "@types/react-dom": "18.0.9", - "next": "13.0.7", + "next": "14.0.0", "react": "18.2.0", "react-dom": "18.2.0", "typescript": "4.9.5" diff --git a/packages/e2e-tests/test-applications/nextjs-app-dir/package.json b/packages/e2e-tests/test-applications/nextjs-app-dir/package.json index 461eabaf4dc2..ec3b43e528e0 100644 --- a/packages/e2e-tests/test-applications/nextjs-app-dir/package.json +++ b/packages/e2e-tests/test-applications/nextjs-app-dir/package.json @@ -11,6 +11,7 @@ "test:test-build": "pnpm ts-node --script-mode assert-build.ts", "test:build-canary": "pnpm install && pnpm add next@canary && npx playwright install && pnpm build", "test:build-latest": "pnpm install && pnpm add next@latest && npx playwright install && pnpm build", + "test:build-13": "pnpm install && pnpm add next@13.4.19 && npx playwright install && pnpm build", "test:assert": "pnpm test:test-build && pnpm test:prod && pnpm test:dev" }, "dependencies": { @@ -19,7 +20,7 @@ "@types/node": "18.11.17", "@types/react": "18.0.26", "@types/react-dom": "18.0.9", - "next": "13.4.19", + "next": "14.0.0", "react": "18.2.0", "react-dom": "18.2.0", "typescript": "4.9.5", diff --git a/packages/e2e-tests/test-applications/nextjs-app-dir/pages/pages-router/ssr-error-class.tsx b/packages/e2e-tests/test-applications/nextjs-app-dir/pages/pages-router/ssr-error-class.tsx new file mode 100644 index 000000000000..86ce68c1c034 --- /dev/null +++ b/packages/e2e-tests/test-applications/nextjs-app-dir/pages/pages-router/ssr-error-class.tsx @@ -0,0 +1,16 @@ +import React from 'react'; + +export default class Page extends React.Component { + render() { + throw new Error('Pages SSR Error Class'); + return
Hello world!
; + } +} + +export function getServerSideProps() { + return { + props: { + foo: 'bar', + }, + }; +} diff --git a/packages/e2e-tests/test-applications/nextjs-app-dir/pages/pages-router/ssr-error-fc.tsx b/packages/e2e-tests/test-applications/nextjs-app-dir/pages/pages-router/ssr-error-fc.tsx new file mode 100644 index 000000000000..6342caec47ca --- /dev/null +++ b/packages/e2e-tests/test-applications/nextjs-app-dir/pages/pages-router/ssr-error-fc.tsx @@ -0,0 +1,12 @@ +export default function Page() { + throw new Error('Pages SSR Error FC'); + return
Hello world!
; +} + +export function getServerSideProps() { + return { + props: { + foo: 'bar', + }, + }; +} diff --git a/packages/e2e-tests/test-applications/nextjs-app-dir/tests/pages-ssr-errors.test.ts b/packages/e2e-tests/test-applications/nextjs-app-dir/tests/pages-ssr-errors.test.ts new file mode 100644 index 000000000000..c861ecaafb25 --- /dev/null +++ b/packages/e2e-tests/test-applications/nextjs-app-dir/tests/pages-ssr-errors.test.ts @@ -0,0 +1,38 @@ +import { test, expect } from '@playwright/test'; +import { waitForError, waitForTransaction } from '../event-proxy-server'; + +test('Will capture error for SSR rendering error with a connected trace (Class Component)', async ({ page }) => { + const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => { + return errorEvent?.exception?.values?.[0]?.value === 'Pages SSR Error Class'; + }); + + const serverComponentTransaction = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { + return ( + transactionEvent?.transaction === '/pages-router/ssr-error-class' && + (await errorEventPromise).contexts?.trace?.trace_id === transactionEvent.contexts?.trace?.trace_id + ); + }); + + await page.goto('/pages-router/ssr-error-class'); + + expect(await errorEventPromise).toBeDefined(); + expect(await serverComponentTransaction).toBeDefined(); +}); + +test('Will capture error for SSR rendering error with a connected trace (Functional Component)', async ({ page }) => { + const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => { + return errorEvent?.exception?.values?.[0]?.value === 'Pages SSR Error FC'; + }); + + const serverComponentTransaction = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { + return ( + transactionEvent?.transaction === '/pages-router/ssr-error-fc' && + (await errorEventPromise).contexts?.trace?.trace_id === transactionEvent.contexts?.trace?.trace_id + ); + }); + + await page.goto('/pages-router/ssr-error-fc'); + + expect(await errorEventPromise).toBeDefined(); + expect(await serverComponentTransaction).toBeDefined(); +}); diff --git a/packages/feedback/README.md b/packages/feedback/README.md index 799cea6b59b8..9ae144057605 100644 --- a/packages/feedback/README.md +++ b/packages/feedback/README.md @@ -11,28 +11,33 @@ This SDK is **considered experimental and in an alpha state**. It may experience ## Pre-requisites -`@sentry/feedback` currently can only be used by browsers with [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM) support. +`@sentry-internal/feedback` currently can only be used by browsers with [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM) support. ## Installation -Feedback can be imported from `@sentry/browser`, or a respective SDK package like `@sentry/react` or `@sentry/vue`. -You don't need to install anything in order to use Feedback. The minimum version that includes Feedback is <>. +During the alpha phase, the feedback integration will need to be imported from `@sentry-internal/feedback`. This will be +changed for the general release. -For details on using Feedback when using Sentry via the CDN bundles, see [CDN bundle](#loading-feedback-as-a-cdn-bundle). +```shell +npm add @sentry-internal/feedback +``` ## Setup -To set up the integration, add the following to your Sentry initialization. Several options are supported and passable via the integration constructor. -See the [configuration section](#configuration) below for more details. +To set up the integration, add the following to your Sentry initialization. This will inject a feedback button to the bottom right corner of your application. Users can then click it to open up a feedback form where they can submit feedback. + +Several options are supported and passable via the integration constructor. See the [configuration section](#configuration) below for more details. ```javascript import * as Sentry from '@sentry/browser'; -// or e.g. import * as Sentry from '@sentry/react'; +// or from a framework specific SDK, e.g. +// import * as Sentry from '@sentry/react'; +import Feedback from '@sentry-internal/feedback'; Sentry.init({ dsn: '__DSN__', integrations: [ - new Sentry.Feedback({ + new Feedback({ // Additional SDK configuration goes in here, for example: // See below for all available options }) @@ -41,59 +46,159 @@ Sentry.init({ }); ``` -### Lazy loading Feedback +## Configuration + +### General Integration Configuration -Feedback will start automatically when you add the integration. -If you do not want to start Feedback immediately (e.g. if you want to lazy-load it), -you can also use `addIntegration` to load it later: +The following options can be configured as options to the integration, in `new Feedback({})`: -```js -import * as Sentry from "@sentry/react"; -import { BrowserClient } from "@sentry/browser"; +| key | type | default | description | +| --------- | ------- | ------- | ----------- | +| `autoInject` | `boolean` | `true` | Injects the Feedback widget into the application when the integration is added. This is useful to turn off if you bring your own button, or only want to show the widget on certain views. | +| `colorScheme` | `"system" \| "light" \| "dark"` | `"system"` | The color theme to use. `"system"` will follow your OS colorscheme. | -Sentry.init({ - // Do not load it initially - integrations: [] +### User/form Related Configuration +| key | type | default | description | +| --------- | ------- | ------- | ----------- | +| `showName` | `boolean` | `true` | Displays the name field on the feedback form, however will still capture the name (if available) from Sentry SDK context. | +| `showEmail` | `boolean` | `true` | Displays the email field on the feedback form, however will still capture the email (if available) from Sentry SDK context. | +| `isAnonymous` | `boolean` | `false` | Hides both name and email fields and does not use Sentry SDK's user context. | +| `useSentryUser` | `Record` | `{ email: 'email', name: 'username'}` | Map of the `email` and `name` fields to the corresponding Sentry SDK user fields that were called with `Sentry.setUser`. | + +By default the Feedback integration will attempt to fill in the name/email fields if you have set a user context via [`Sentry.setUser`](https://docs.sentry.io/platforms/javascript/enriching-events/identify-user/). By default it expects the email and name fields to be `email` and `username`. Below is an example configuration with non-default user fields. + +```javascript +Sentry.setUser({ + email: 'foo@example.com', + fullName: 'Jane Doe', }); -// Sometime later -const { Feedback } = await import('@sentry/browser'); -const client = Sentry.getCurrentHub().getClient(); -// Client can be undefined -client?.addIntegration(new Feedback()); +new Feedback({ + useSentryUser({ + email: 'email', + name: 'fullName', + }), +}) +``` + +### Text Customization +Most text that you see in the default Feedback widget can be customized. + +| key | default | description | +| --------- | ------- | ----------- | +| `buttonLabel` | `"Feedback"` | The label of the widget button. | +| `submitButtonLabel` | `"Send Feedback"` | The label of the submit button used in the feedback form dialog. | +| `cancelButtonLabel` | `"Cancel"` | The label of the cancel button used in the feedback form dialog. | +| `formTitle` | `"Send Feedback"` | The title at the top of the feedback form dialog. | +| `nameLabel` | `"Full Name"` | The label of the name input field. | +| `namePlaceholder` | `"Full Name"` | The placeholder for the name input field. | +| `emailLabel` | `"Email"` | The label of the email input field. || +| `emailPlaceholder` | `"Email"` | The placeholder for the email input field. | +| `messageLabel` | `"Description"` | The label for the feedback description input field. | +| `messagePlaceholder` | `"What's the issue? What did you expect?"` | The placeholder for the feedback description input field. | +| `successMessageText` | `"Thank you for your report!"` | The message to be displayed after a succesful feedback submission. | + +```javascript +new Feedback({ + buttonLabel: 'Bug Report', + submitButtonLabel: 'Send Report', + formTitle: 'Send Bug Report', +}); ``` -### Identifying Users +### Theme Customization +Colors can be customized via the Feedback constructor or by defining CSS variables on the widget button. If you use the default widget button, it will have an `id="sentry-feedback`, meaning you can use the `#sentry-feedback` selector to define CSS variables to override. -If you have only followed the above instructions to setup session feedbacks, you will only see IP addresses in Sentry's UI. In order to associate a user identity to a session feedback, use [`setUser`](https://docs.sentry.io/platforms/javascript/enriching-events/identify-user/). +| key | css variable | light | dark | description | +| --- | --- | --- | --- | --- | +| `background` | `--bg-color` | `#ffffff` | `#29232f` | Background color of the widget actor and dialog. | +| `backgroundHover` | `--bg-hover-color` | `#f6f6f7` | `#352f3b` | The background color of widget actor when in a hover state | +| `foreground` | `--fg-color` | `#2b2233` | `#ebe6ef` | The foreground color, e.g. text color | +| `error` | `--error-color` | `#df3338` | `#f55459` | Color used for error related components (e.g. text color when there was an error submitting feedback) | +| `success` | `--success-color` | `#268d75` | `#2da98c` | Color used for success-related components (e.g. text color when feedback is submitted successfully) | +| `border` | `--border` | `1.5px solid rgba(41, 35, 47, 0.13)` | `1.5px solid rgba(235, 230, 239, 0.15)` | The border style used for the widget actor and dialog | +| `boxShadow` | `--box-shadow` | `0px 4px 24px 0px rgba(43, 34, 51, 0.12)` | `0px 4px 24px 0px rgba(43, 34, 51, 0.12)` | The box shadow style used for the widget actor and dialog | +Here is an example of customizing only the background color for the light theme using the Feedback constructor configuration. ```javascript -import * as Sentry from "@sentry/browser"; +new Feedback({ + themeLight: { + background: "#cccccc", + }, +}) +``` + +Or the same example above but using the CSS variables method: -Sentry.setUser({ email: "jane.doe@example.com" }); +```css +#sentry-feedback { + --bg-color: #cccccc; +} ``` -## Loading Feedback as a CDN Bundle +### Additional UI Customization +Similar to theme customization above, these are additional CSS variables that can be overridden. Note these are not supported in the constructor. -As an alternative to the NPM package, you can use Feedback as a CDN bundle. -Please refer to the [Feedback installation guide](https://docs.sentry.io/platforms/javascript/session-feedback/#install) for CDN bundle instructions. +| Variable | Default | Description | +| --- | --- | --- | +| `--bottom` | `1rem` | By default the widget has a position of fixed, and is in the bottom right corner. | +| `--right` | `1rem` | By default the widget has a position of fixed, and is in the bottom right corner. | +| `--top` | `auto` | By default the widget has a position of fixed, and is in the bottom right corner. | +| `--left` | `auto` | By default the widget has a position of fixed, and is in the bottom right corner. | +| `--z-index` | `100000` | The z-index of the widget | +| `--font-family` | `"'Helvetica Neue', Arial, sans-serif"` | Default font-family to use| +| `--font-size` | `14px` | Font size | +### Event Callbacks +Sometimes it’s important to know when someone has started to interact with the feedback form, so you can add custom logging, or start/stop background timers on the page until the user is done. -## Configuration +Pass these callbacks when you initialize the Feedback integration: -### General Integration Configuration +```javascript +new Feedback({ + onActorClick: () => {}, + onDialogOpen: () => {}, + onDialogClose: () => {}, + onSubmitSuccess: () => {}, + onSubmitError: () => {}, +}); +``` -The following options can be configured as options to the integration, in `new Feedback({})`: +## Further Customization +There are two more methods in the integration that can help customization. -| key | type | default | description | -| --------- | ------- | ------- | ----------- | -| tbd | boolean | `true` | tbd | +### Bring Your Own Button +You can skip the default widget button and use your own button. Call `feedback.attachTo()` to have the SDK attach a click listener to your own button. You can additionally supply the same customization options that the constructor accepts (e.g. for text labels and colors). +```javascript +const feedback = new Feedback({ + // Disable injecting the default widget + autoInject: false, +}); + +feedback.attachTo(document.querySelector('#your-button'), { + formTitle: "Report a Bug!" +}); +``` -## Manually Sending Feedback Data +### Bring Your Own Widget -Connect your own feedback UI to Sentry's You can use `feedback.flush()` to immediately send all currently captured feedback data. -When Feedback is currently in buffering mode, this will send up to the last 60 seconds of feedback data, -and also continue sending afterwards, similar to when an error happens & is recorded. +You can also bring your own widget and UI and simply pass a feedback object to the `sendFeedback()` function. + +```html +
+ +