Skip to content

Commit 2f39e15

Browse files
committed
Merge branch 'develop' into update-master-with-develop
2 parents f5ad00b + 8ee1aa5 commit 2f39e15

File tree

131 files changed

+631
-366
lines changed

Some content is hidden

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

131 files changed

+631
-366
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Pro tip: If any of your breakpoints are in code run by multiple tests, and you r
6969

7070
## Debug Build Flags
7171

72-
Throughout the codebase, you will find the `__DEBUG_BUILD__` flag guarding various code sections. This flag serves two purposes:
72+
Throughout the codebase, you will find a `__DEBUG_BUILD__` constant. This flag serves two purposes:
7373

7474
1. It enables us to remove debug code from our minified CDN bundles during build, by replacing the flag with `false` before tree-shaking occurs.
7575
2. It enables users to remove Sentry debug code from their production bundles during their own build. When we build our npm packages, we replace the flag with `(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__)`. If the user does nothing, this evaluates to `true` and logging is included. But if the user runs their own replacement during build (again replacing the flag with `false`), the build will tree-shake the logging away, just as our bundle builds do.

packages/browser/src/client.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
} from '@sentry/types';
1414
import { createClientReportEnvelope, dsnToString, getSDKSource, logger } from '@sentry/utils';
1515

16+
import { DEBUG_BUILD } from './debug-build';
1617
import { eventFromException, eventFromMessage } from './eventbuilder';
1718
import { WINDOW } from './helpers';
1819
import type { BrowserTransportOptions } from './transports/types';
@@ -96,7 +97,7 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
9697
*/
9798
public captureUserFeedback(feedback: UserFeedback): void {
9899
if (!this._isEnabled()) {
99-
__DEBUG_BUILD__ && logger.warn('SDK not enabled, will not capture user feedback.');
100+
DEBUG_BUILD && logger.warn('SDK not enabled, will not capture user feedback.');
100101
return;
101102
}
102103

@@ -123,17 +124,17 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
123124
const outcomes = this._clearOutcomes();
124125

125126
if (outcomes.length === 0) {
126-
__DEBUG_BUILD__ && logger.log('No outcomes to send');
127+
DEBUG_BUILD && logger.log('No outcomes to send');
127128
return;
128129
}
129130

130131
// This is really the only place where we want to check for a DSN and only send outcomes then
131132
if (!this._dsn) {
132-
__DEBUG_BUILD__ && logger.log('No dsn provided, will not send outcomes');
133+
DEBUG_BUILD && logger.log('No dsn provided, will not send outcomes');
133134
return;
134135
}
135136

136-
__DEBUG_BUILD__ && logger.log('Sending outcomes:', outcomes);
137+
DEBUG_BUILD && logger.log('Sending outcomes:', outcomes);
137138

138139
const envelope = createClientReportEnvelope(outcomes, this._options.tunnel && dsnToString(this._dsn));
139140
void this._sendEnvelope(envelope);

packages/browser/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__;

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
severityLevelFromString,
3131
} from '@sentry/utils';
3232

33+
import { DEBUG_BUILD } from '../debug-build';
3334
import { getClient } from '../exports';
3435
import { WINDOW } from '../helpers';
3536

@@ -148,7 +149,7 @@ function _domBreadcrumb(dom: BreadcrumbsOptions['dom']): (handlerData: HandlerDa
148149
let maxStringLength =
149150
typeof dom === 'object' && typeof dom.maxStringLength === 'number' ? dom.maxStringLength : undefined;
150151
if (maxStringLength && maxStringLength > MAX_ALLOWED_STRING_LENGTH) {
151-
__DEBUG_BUILD__ &&
152+
DEBUG_BUILD &&
152153
logger.warn(
153154
`\`dom.maxStringLength\` cannot exceed ${MAX_ALLOWED_STRING_LENGTH}, but a value of ${maxStringLength} was configured. Sentry will use ${MAX_ALLOWED_STRING_LENGTH} instead.`,
154155
);

packages/browser/src/integrations/dedupe.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { Event, Exception, Integration, StackFrame } from '@sentry/types';
22
import { logger } from '@sentry/utils';
33

4+
import { DEBUG_BUILD } from '../debug-build';
5+
46
/** Deduplication filter */
57
export class Dedupe implements Integration {
68
/**
@@ -40,7 +42,7 @@ export class Dedupe implements Integration {
4042
// Juuust in case something goes wrong
4143
try {
4244
if (_shouldDropEvent(currentEvent, this._previousEvent)) {
43-
__DEBUG_BUILD__ && logger.warn('Event dropped due to being a duplicate of previously captured event.');
45+
DEBUG_BUILD && logger.warn('Event dropped due to being a duplicate of previously captured event.');
4446
return null;
4547
}
4648
} catch (_oO) {} // eslint-disable-line no-empty

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@sentry/utils';
1313

1414
import type { BrowserClient } from '../client';
15+
import { DEBUG_BUILD } from '../debug-build';
1516
import { eventFromUnknownInput } from '../eventbuilder';
1617
import { shouldIgnoreOnError } from '../helpers';
1718

@@ -254,7 +255,7 @@ function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column
254255
}
255256

256257
function globalHandlerLog(type: string): void {
257-
__DEBUG_BUILD__ && logger.log(`Global Handler attached: ${type}`);
258+
DEBUG_BUILD && logger.log(`Global Handler attached: ${type}`);
258259
}
259260

260261
function getHubAndOptions(): [Hub, StackParser, boolean | undefined] {

packages/browser/src/profiling/hubextensions.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { Transaction } from '@sentry/types';
33
import { logger, timestampInSeconds, uuid4 } from '@sentry/utils';
44

5+
import { DEBUG_BUILD } from '../debug-build';
56
import { WINDOW } from '../helpers';
67
import type { JSSelfProfile } from './jsSelfProfiling';
78
import {
@@ -21,7 +22,7 @@ import {
2122
*/
2223
export function onProfilingStartRouteTransaction(transaction: Transaction | undefined): Transaction | undefined {
2324
if (!transaction) {
24-
if (__DEBUG_BUILD__) {
25+
if (DEBUG_BUILD) {
2526
logger.log('[Profiling] Transaction is undefined, skipping profiling');
2627
}
2728
return transaction;
@@ -54,7 +55,7 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
5455
return transaction;
5556
}
5657

57-
if (__DEBUG_BUILD__) {
58+
if (DEBUG_BUILD) {
5859
logger.log(`[Profiling] started profiling transaction: ${transaction.name || transaction.description}`);
5960
}
6061

@@ -85,7 +86,7 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
8586
return null;
8687
}
8788
if (processedProfile) {
88-
if (__DEBUG_BUILD__) {
89+
if (DEBUG_BUILD) {
8990
logger.log(
9091
'[Profiling] profile for:',
9192
transaction.name || transaction.description,
@@ -103,13 +104,13 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
103104
maxDurationTimeoutID = undefined;
104105
}
105106

106-
if (__DEBUG_BUILD__) {
107+
if (DEBUG_BUILD) {
107108
logger.log(`[Profiling] stopped profiling of transaction: ${transaction.name || transaction.description}`);
108109
}
109110

110111
// In case of an overlapping transaction, stopProfiling may return null and silently ignore the overlapping profile.
111112
if (!profile) {
112-
if (__DEBUG_BUILD__) {
113+
if (DEBUG_BUILD) {
113114
logger.log(
114115
`[Profiling] profiler returned null profile for: ${transaction.name || transaction.description}`,
115116
'this may indicate an overlapping transaction or a call to stopProfiling with a profile title that was never started',
@@ -122,7 +123,7 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
122123
return null;
123124
})
124125
.catch(error => {
125-
if (__DEBUG_BUILD__) {
126+
if (DEBUG_BUILD) {
126127
logger.log('[Profiling] error while stopping profiler:', error);
127128
}
128129
return null;
@@ -131,7 +132,7 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
131132

132133
// Enqueue a timeout to prevent profiles from running over max duration.
133134
let maxDurationTimeoutID: number | undefined = WINDOW.setTimeout(() => {
134-
if (__DEBUG_BUILD__) {
135+
if (DEBUG_BUILD) {
135136
logger.log(
136137
'[Profiling] max profile duration elapsed, stopping profiling for:',
137138
transaction.name || transaction.description,

packages/browser/src/profiling/integration.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { EventProcessor, Hub, Integration, Transaction } from '@sentry/type
22
import type { Profile } from '@sentry/types/src/profiling';
33
import { logger } from '@sentry/utils';
44

5+
import { DEBUG_BUILD } from '../debug-build';
56
import { startProfileForTransaction } from './hubextensions';
67
import type { ProfiledEvent } from './utils';
78
import {
@@ -78,14 +79,12 @@ export class BrowserProfilingIntegration implements Integration {
7879
const start_timestamp = context && context['profile'] && context['profile']['start_timestamp'];
7980

8081
if (typeof profile_id !== 'string') {
81-
__DEBUG_BUILD__ &&
82-
logger.log('[Profiling] cannot find profile for a transaction without a profile context');
82+
DEBUG_BUILD && logger.log('[Profiling] cannot find profile for a transaction without a profile context');
8383
continue;
8484
}
8585

8686
if (!profile_id) {
87-
__DEBUG_BUILD__ &&
88-
logger.log('[Profiling] cannot find profile for a transaction without a profile context');
87+
DEBUG_BUILD && logger.log('[Profiling] cannot find profile for a transaction without a profile context');
8988
continue;
9089
}
9190

@@ -96,7 +95,7 @@ export class BrowserProfilingIntegration implements Integration {
9695

9796
const profile = takeProfileFromGlobalCache(profile_id);
9897
if (!profile) {
99-
__DEBUG_BUILD__ && logger.log(`[Profiling] Could not retrieve profile for transaction: ${profile_id}`);
98+
DEBUG_BUILD && logger.log(`[Profiling] Could not retrieve profile for transaction: ${profile_id}`);
10099
continue;
101100
}
102101

packages/browser/src/profiling/utils.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { DebugImage, Envelope, Event, StackFrame, StackParser, Transaction
55
import type { Profile, ThreadCpuProfile } from '@sentry/types/src/profiling';
66
import { browserPerformanceTimeOrigin, forEachEnvelopeItem, GLOBAL_OBJ, logger, uuid4 } from '@sentry/utils';
77

8+
import { DEBUG_BUILD } from '../debug-build';
89
import { getClient } from '../exports';
910
import { WINDOW } from '../helpers';
1011
import type { JSSelfProfile, JSSelfProfiler, JSSelfProfilerConstructor, JSSelfProfileStack } from './jsSelfProfiling';
@@ -96,7 +97,7 @@ function getTraceId(event: Event): string {
9697
// All profiles and transactions are rejected if this is the case and we want to
9798
// warn users that this is happening if they enable debug flag
9899
if (typeof traceId === 'string' && traceId.length !== 32) {
99-
if (__DEBUG_BUILD__) {
100+
if (DEBUG_BUILD) {
100101
logger.log(`[Profiling] Invalid traceId: ${traceId} on profiled event`);
101102
}
102103
}
@@ -418,7 +419,7 @@ export function applyDebugMetadata(resource_paths: ReadonlyArray<string>): Debug
418419
export function isValidSampleRate(rate: unknown): boolean {
419420
// we need to check NaN explicitly because it's of type 'number' and therefore wouldn't get caught by this typecheck
420421
if ((typeof rate !== 'number' && typeof rate !== 'boolean') || (typeof rate === 'number' && isNaN(rate))) {
421-
__DEBUG_BUILD__ &&
422+
DEBUG_BUILD &&
422423
logger.warn(
423424
`[Profiling] Invalid sample rate. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(
424425
rate,
@@ -434,16 +435,15 @@ export function isValidSampleRate(rate: unknown): boolean {
434435

435436
// in case sampleRate is a boolean, it will get automatically cast to 1 if it's true and 0 if it's false
436437
if (rate < 0 || rate > 1) {
437-
__DEBUG_BUILD__ &&
438-
logger.warn(`[Profiling] Invalid sample rate. Sample rate must be between 0 and 1. Got ${rate}.`);
438+
DEBUG_BUILD && logger.warn(`[Profiling] Invalid sample rate. Sample rate must be between 0 and 1. Got ${rate}.`);
439439
return false;
440440
}
441441
return true;
442442
}
443443

444444
function isValidProfile(profile: JSSelfProfile): profile is JSSelfProfile & { profile_id: string } {
445445
if (profile.samples.length < 2) {
446-
if (__DEBUG_BUILD__) {
446+
if (DEBUG_BUILD) {
447447
// Log a warning if the profile has less than 2 samples so users can know why
448448
// they are not seeing any profiling data and we cant avoid the back and forth
449449
// of asking them to provide us with a dump of the profile data.
@@ -453,7 +453,7 @@ function isValidProfile(profile: JSSelfProfile): profile is JSSelfProfile & { pr
453453
}
454454

455455
if (!profile.frames.length) {
456-
if (__DEBUG_BUILD__) {
456+
if (DEBUG_BUILD) {
457457
logger.log('[Profiling] Discarding profile because it contains no frames');
458458
}
459459
return false;
@@ -483,7 +483,7 @@ export function startJSSelfProfile(): JSSelfProfiler | undefined {
483483
const JSProfilerConstructor = WINDOW.Profiler;
484484

485485
if (!isJSProfilerSupported(JSProfilerConstructor)) {
486-
if (__DEBUG_BUILD__) {
486+
if (DEBUG_BUILD) {
487487
logger.log(
488488
'[Profiling] Profiling is not supported by this browser, Profiler interface missing on window object.',
489489
);
@@ -502,7 +502,7 @@ export function startJSSelfProfile(): JSSelfProfiler | undefined {
502502
try {
503503
return new JSProfilerConstructor({ sampleInterval: samplingIntervalMS, maxBufferSize: maxSamples });
504504
} catch (e) {
505-
if (__DEBUG_BUILD__) {
505+
if (DEBUG_BUILD) {
506506
logger.log(
507507
"[Profiling] Failed to initialize the Profiling constructor, this is likely due to a missing 'Document-Policy': 'js-profiling' header.",
508508
);
@@ -520,14 +520,14 @@ export function startJSSelfProfile(): JSSelfProfiler | undefined {
520520
export function shouldProfileTransaction(transaction: Transaction): boolean {
521521
// If constructor failed once, it will always fail, so we can early return.
522522
if (PROFILING_CONSTRUCTOR_FAILED) {
523-
if (__DEBUG_BUILD__) {
523+
if (DEBUG_BUILD) {
524524
logger.log('[Profiling] Profiling has been disabled for the duration of the current user session.');
525525
}
526526
return false;
527527
}
528528

529529
if (!transaction.sampled) {
530-
if (__DEBUG_BUILD__) {
530+
if (DEBUG_BUILD) {
531531
logger.log('[Profiling] Discarding profile because transaction was not sampled.');
532532
}
533533
return false;
@@ -536,7 +536,7 @@ export function shouldProfileTransaction(transaction: Transaction): boolean {
536536
const client = getClient();
537537
const options = client && client.getOptions();
538538
if (!options) {
539-
__DEBUG_BUILD__ && logger.log('[Profiling] Profiling disabled, no options found.');
539+
DEBUG_BUILD && logger.log('[Profiling] Profiling disabled, no options found.');
540540
return false;
541541
}
542542

@@ -546,13 +546,13 @@ export function shouldProfileTransaction(transaction: Transaction): boolean {
546546
// Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The
547547
// only valid values are booleans or numbers between 0 and 1.)
548548
if (!isValidSampleRate(profilesSampleRate)) {
549-
__DEBUG_BUILD__ && logger.warn('[Profiling] Discarding profile because of invalid sample rate.');
549+
DEBUG_BUILD && logger.warn('[Profiling] Discarding profile because of invalid sample rate.');
550550
return false;
551551
}
552552

553553
// if the function returned 0 (or false), or if `profileSampleRate` is 0, it's a sign the profile should be dropped
554554
if (!profilesSampleRate) {
555-
__DEBUG_BUILD__ &&
555+
DEBUG_BUILD &&
556556
logger.log(
557557
'[Profiling] Discarding profile because a negative sampling decision was inherited or profileSampleRate is set to 0',
558558
);
@@ -564,7 +564,7 @@ export function shouldProfileTransaction(transaction: Transaction): boolean {
564564
const sampled = profilesSampleRate === true ? true : Math.random() < profilesSampleRate;
565565
// Check if we should sample this profile
566566
if (!sampled) {
567-
__DEBUG_BUILD__ &&
567+
DEBUG_BUILD &&
568568
logger.log(
569569
`[Profiling] Discarding profile because it's not included in the random sample (sampling rate = ${Number(
570570
profilesSampleRate,

packages/browser/src/sdk.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717

1818
import type { BrowserClientOptions, BrowserOptions } from './client';
1919
import { BrowserClient } from './client';
20+
import { DEBUG_BUILD } from './debug-build';
2021
import type { ReportDialogOptions } from './helpers';
2122
import { WINDOW, wrap as internalWrap } from './helpers';
2223
import { Breadcrumbs, Dedupe, GlobalHandlers, HttpContext, LinkedErrors, TryCatch } from './integrations';
@@ -140,14 +141,14 @@ export function init(options: BrowserOptions = {}): void {
140141
export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = getCurrentHub()): void {
141142
// doesn't work without a document (React Native)
142143
if (!WINDOW.document) {
143-
__DEBUG_BUILD__ && logger.error('Global document not defined in showReportDialog call');
144+
DEBUG_BUILD && logger.error('Global document not defined in showReportDialog call');
144145
return;
145146
}
146147

147148
const { client, scope } = hub.getStackTop();
148149
const dsn = options.dsn || (client && client.getDsn());
149150
if (!dsn) {
150-
__DEBUG_BUILD__ && logger.error('DSN not configured for showReportDialog call');
151+
DEBUG_BUILD && logger.error('DSN not configured for showReportDialog call');
151152
return;
152153
}
153154

@@ -189,7 +190,7 @@ export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = g
189190
if (injectionPoint) {
190191
injectionPoint.appendChild(script);
191192
} else {
192-
__DEBUG_BUILD__ && logger.error('Not injecting report dialog. No injection point found in HTML');
193+
DEBUG_BUILD && logger.error('Not injecting report dialog. No injection point found in HTML');
193194
}
194195
}
195196

@@ -236,8 +237,7 @@ function startSessionOnHub(hub: Hub): void {
236237
*/
237238
function startSessionTracking(): void {
238239
if (typeof WINDOW.document === 'undefined') {
239-
__DEBUG_BUILD__ &&
240-
logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
240+
DEBUG_BUILD && logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
241241
return;
242242
}
243243

packages/browser/src/transports/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isNativeFetch, logger } from '@sentry/utils';
22

3+
import { DEBUG_BUILD } from '../debug-build';
34
import { WINDOW } from '../helpers';
45

56
let cachedFetchImpl: FetchImpl | undefined = undefined;
@@ -70,8 +71,7 @@ export function getNativeFetchImplementation(): FetchImpl {
7071
}
7172
document.head.removeChild(sandbox);
7273
} catch (e) {
73-
__DEBUG_BUILD__ &&
74-
logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
74+
DEBUG_BUILD && logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', e);
7575
}
7676
}
7777

0 commit comments

Comments
 (0)