Skip to content

Commit 1fbffab

Browse files
committed
make dedicated package
1 parent fc05c52 commit 1fbffab

26 files changed

+583
-23
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ jobs:
369369
${{ github.workspace }}/packages/browser/build/bundles/**
370370
${{ github.workspace }}/packages/integrations/build/bundles/**
371371
${{ github.workspace }}/packages/replay/build/bundles/**
372+
${{ github.workspace }}/packages/replay-canvas/build/bundles/**
372373
${{ github.workspace }}/packages/**/*.tgz
373374
${{ github.workspace }}/packages/serverless/build/aws/dist-serverless/*.zip
374375

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"packages/remix",
7070
"packages/replay",
7171
"packages/replay-worker",
72+
"packages/replay-canvas",
7273
"packages/serverless",
7374
"packages/svelte",
7475
"packages/sveltekit",

packages/browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@sentry-internal/integration-shims": "7.88.0",
35+
"@sentry-internal/replay-canvas": "7.88.0",
3536
"@types/md5": "2.1.33",
3637
"btoa": "^1.2.1",
3738
"chai": "^4.1.2",

packages/browser/rollup.npm.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@ export default makeNPMConfigVariants(
44
makeBaseNPMConfig({
55
// packages with bundles have a different build directory structure
66
hasBundles: true,
7+
packageSpecificConfig: {
8+
output: {
9+
// set exports to 'named' or 'auto' so that rollup doesn't warn
10+
exports: 'named',
11+
// set preserveModules to false because for Replay we actually want
12+
// to bundle everything into one file.
13+
preserveModules: false,
14+
},
15+
},
716
}),
817
);

packages/browser/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const INTEGRATIONS = {
2020

2121
export { INTEGRATIONS as Integrations };
2222

23-
export { Replay, ReplayCanvas } from '@sentry/replay';
23+
export { Replay } from '@sentry/replay';
24+
export { ReplayCanvas } from '@sentry-internal/replay-canvas';
2425
export type {
2526
ReplayEventType,
2627
ReplayEventWithTime,

packages/deno/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"index.d.ts"
1818
],
1919
"dependencies": {
20-
"@sentry/browser": "7.88.0",
2120
"@sentry/core": "7.88.0",
2221
"@sentry/types": "7.88.0",
2322
"@sentry/utils": "7.88.0"
@@ -37,7 +36,7 @@
3736
"build:types:bundle": "rollup -c rollup.types.config.js",
3837
"build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build",
3938
"circularDepCheck": "madge --circular src/index.ts",
40-
"clean": "rimraf build build-types build-test coverage",
39+
"clean": "rimraf build build-types build-test coverage sentry-deno-*.tgz",
4140
"prefix": "yarn deno-types",
4241
"fix": "eslint . --format stylish --fix",
4342
"prelint": "yarn deno-types",

packages/deno/src/debug-build.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare const __DEBUG_BUILD__: boolean;
2+
3+
/**
4+
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
5+
*
6+
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
7+
*/
8+
export const DEBUG_BUILD = __DEBUG_BUILD__;
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
import { addBreadcrumb, getClient } from '@sentry/core';
2+
import type { Event as SentryEvent, HandlerDataConsole, HandlerDataFetch, Integration } from '@sentry/types';
3+
import type { FetchBreadcrumbData, FetchBreadcrumbHint } from '@sentry/types/build/types/breadcrumb';
4+
import {
5+
addConsoleInstrumentationHandler,
6+
addFetchInstrumentationHandler,
7+
getEventDescription,
8+
safeJoin,
9+
severityLevelFromString,
10+
} from '@sentry/utils';
11+
12+
interface BreadcrumbsOptions {
13+
console: boolean;
14+
fetch: boolean;
15+
sentry: boolean;
16+
}
17+
18+
/** maxStringLength gets capped to prevent 100 breadcrumbs exceeding 1MB event payload size */
19+
const MAX_ALLOWED_STRING_LENGTH = 1024;
20+
21+
/**
22+
* Default Breadcrumbs instrumentations
23+
* TODO: Deprecated - with v6, this will be renamed to `Instrument`
24+
*/
25+
export class Breadcrumbs implements Integration {
26+
/**
27+
* @inheritDoc
28+
*/
29+
public static id: string = 'Breadcrumbs';
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public name: string;
35+
36+
/**
37+
* Options of the breadcrumbs integration.
38+
*/
39+
// This field is public, because we use it in the browser client to check if the `sentry` option is enabled.
40+
public readonly options: Readonly<BreadcrumbsOptions>;
41+
42+
/**
43+
* @inheritDoc
44+
*/
45+
public constructor(options?: Partial<BreadcrumbsOptions>) {
46+
this.name = Breadcrumbs.id;
47+
this.options = {
48+
console: true,
49+
fetch: true,
50+
sentry: true,
51+
...options,
52+
};
53+
}
54+
55+
/**
56+
* Instrument browser built-ins w/ breadcrumb capturing
57+
* - Console API
58+
* - Fetch API
59+
*/
60+
public setupOnce(): void {
61+
if (this.options.console) {
62+
addConsoleInstrumentationHandler(_consoleBreadcrumb);
63+
}
64+
if (this.options.fetch) {
65+
addFetchInstrumentationHandler(_fetchBreadcrumb);
66+
}
67+
if (this.options.sentry) {
68+
const client = getClient();
69+
client && client.on && client.on('beforeSendEvent', addSentryBreadcrumb);
70+
}
71+
}
72+
}
73+
74+
/**
75+
* Adds a breadcrumb for Sentry events or transactions if this option is enabled.
76+
*/
77+
function addSentryBreadcrumb(event: SentryEvent): void {
78+
addBreadcrumb(
79+
{
80+
category: `sentry.${event.type === 'transaction' ? 'transaction' : 'event'}`,
81+
event_id: event.event_id,
82+
level: event.level,
83+
message: getEventDescription(event),
84+
},
85+
{
86+
event,
87+
},
88+
);
89+
}
90+
91+
/**
92+
* Creates breadcrumbs from console API calls
93+
*/
94+
function _consoleBreadcrumb(handlerData: HandlerDataConsole): void {
95+
const breadcrumb = {
96+
category: 'console',
97+
data: {
98+
arguments: handlerData.args,
99+
logger: 'console',
100+
},
101+
level: severityLevelFromString(handlerData.level),
102+
message: safeJoin(handlerData.args, ' '),
103+
};
104+
105+
if (handlerData.level === 'assert') {
106+
if (handlerData.args[0] === false) {
107+
breadcrumb.message = `Assertion failed: ${safeJoin(handlerData.args.slice(1), ' ') || 'console.assert'}`;
108+
breadcrumb.data.arguments = handlerData.args.slice(1);
109+
} else {
110+
// Don't capture a breadcrumb for passed assertions
111+
return;
112+
}
113+
}
114+
115+
addBreadcrumb(breadcrumb, {
116+
input: handlerData.args,
117+
level: handlerData.level,
118+
});
119+
}
120+
121+
/**
122+
* Creates breadcrumbs from fetch API calls
123+
*/
124+
function _fetchBreadcrumb(handlerData: HandlerDataFetch): void {
125+
const { startTimestamp, endTimestamp } = handlerData;
126+
127+
// We only capture complete fetch requests
128+
if (!endTimestamp) {
129+
return;
130+
}
131+
132+
if (handlerData.fetchData.url.match(/sentry_key/) && handlerData.fetchData.method === 'POST') {
133+
// We will not create breadcrumbs for fetch requests that contain `sentry_key` (internal sentry requests)
134+
return;
135+
}
136+
137+
if (handlerData.error) {
138+
const data: FetchBreadcrumbData = handlerData.fetchData;
139+
const hint: FetchBreadcrumbHint = {
140+
data: handlerData.error,
141+
input: handlerData.args,
142+
startTimestamp,
143+
endTimestamp,
144+
};
145+
146+
addBreadcrumb(
147+
{
148+
category: 'fetch',
149+
data,
150+
level: 'error',
151+
type: 'http',
152+
},
153+
hint,
154+
);
155+
} else {
156+
const response = handlerData.response as Response | undefined;
157+
const data: FetchBreadcrumbData = {
158+
...handlerData.fetchData,
159+
status_code: response && response.status,
160+
};
161+
const hint: FetchBreadcrumbHint = {
162+
input: handlerData.args,
163+
response,
164+
startTimestamp,
165+
endTimestamp,
166+
};
167+
addBreadcrumb(
168+
{
169+
category: 'fetch',
170+
data,
171+
type: 'http',
172+
},
173+
hint,
174+
);
175+
}
176+
}

0 commit comments

Comments
 (0)