Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,15 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 9.8.0

- feat(node): Implement new continuous profiling API spec ([#15635](https://github.com/getsentry/sentry-javascript/pull/15635))
- feat(profiling): Add platform to chunk envelope ([#15758](https://github.com/getsentry/sentry-javascript/pull/15758))
- feat(react): Export captureReactException method ([#15746](https://github.com/getsentry/sentry-javascript/pull/15746))
- fix(node): Check for `res.end` before passing to Proxy ([#15776](https://github.com/getsentry/sentry-javascript/pull/15776))
- perf(core): Add short-circuits to `eventFilters` integration ([#15752](https://github.com/getsentry/sentry-javascript/pull/15752))
- perf(node): Short circuit flushing on Vercel only for Vercel ([#15734](https://github.com/getsentry/sentry-javascript/pull/15734))

## 9.7.0

- feat(core): Add `captureLog` method ([#15717](https://github.com/getsentry/sentry-javascript/pull/15717))
Expand Down
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
136 changes: 71 additions & 65 deletions packages/core/src/integrations/eventFilters.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,6 @@ export interface EventFiltersOptions {

const INTEGRATION_NAME = 'EventFilters';

const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
}) satisfies IntegrationFn;

/**
* An integration that filters out events (errors and transactions) based on:
*
Expand All@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
*
* Events filtered by this integration will not be sent to Sentry.
*/
export const eventFiltersIntegration = defineIntegration(_eventFiltersIntegration);
export const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {
let mergedOptions: Partial<EventFiltersOptions> | undefined;
return {
name: INTEGRATION_NAME,
setup(client) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
},
processEvent(event, _hint, client) {
if (!mergedOptions) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
}
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
});

/**
* An integration that filters out events (errors and transactions) based on:
Expand DownExpand Up@@ -102,66 +107,72 @@ function _mergeOptions(
}

function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {
if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
if (!event.type) {
// Filter errors

if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
} else if (event.type === 'transaction') {
// Filter transactions

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
}
return false;
}

function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {
// If event.type, this is not an error
if (event.type || !ignoreErrors || !ignoreErrors.length) {
if (!ignoreErrors?.length) {
return false;
}

return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
}

function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
if (!ignoreTransactions?.length) {
return false;
}

Expand DownExpand Up@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception?.values?.length) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,17 @@ import { stealthWrap } from './utils';
type Http = typeof http;
type Https = typeof https;

// The reason this "before OTEL" integration even exists is due to timing reasons. We need to be able to register a
// `res.on('close')` handler **after** OTEL registers its own handler (which it uses to end spans), so that we can do
// something (ie. flush) after OTEL has ended a span for a request. If you think about it like an onion:
//
// (Sentry after OTEL instrumentation
// (OTEL instrumentation
// (Sentry before OTEL instrumentation
// (orig HTTP request handler))))
//
// registering an instrumentation before OTEL allows us to do this for incoming requests.

/**
* A Sentry specific http instrumentation that is applied before the otel instrumentation.
*/
Expand DownExpand Up@@ -70,46 +81,50 @@ export class SentryHttpInstrumentationBeforeOtel extends InstrumentationBase {
function patchResponseToFlushOnServerlessPlatforms(res: http.OutgoingMessage): void {
// Freely extend this function with other platforms if necessary
if (process.env.VERCEL) {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
// https://github.com/getsentry/sentry-javascript/issues/15759
if (typeof res.end === 'function') {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
}
}
}
16 changes: 12 additions & 4 deletions packages/node/src/integrations/http/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentSentryHttpBeforeOtel();
// Below, we instrument the Node.js HTTP API three times. 2 times Sentry-specific, 1 time OTEL specific.
// Due to timing reasons, we sometimes need to apply Sentry instrumentation _before_ we apply the OTEL
// instrumentation (e.g. to flush on serverless platforms), and sometimes we need to apply Sentry instrumentation
// _after_ we apply OTEL instrumentation (e.g. for isolation scope handling and breadcrumbs).

// This is Sentry-specific instrumentation that is applied _before_ any OTEL instrumentation.
if (process.env.VERCEL) {
// Currently this instrumentation only does something when deployed on Vercel, so to save some overhead, we short circuit adding it here only for Vercel.
// If it's functionality is extended in the future, feel free to remove the if statement and this comment.
instrumentSentryHttpBeforeOtel();
}

const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());

Expand All@@ -152,9 +162,7 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
instrumentOtelHttp(instrumentationConfig);
}

// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
// Note that this _has_ to be wrapped after the OTEL instrumentation,
// otherwise the isolation will not work correctly
// This is Sentry-specific instrumentation that is applied _after_ any OTEL instrumentation.
instrumentSentryHttp({
...options,
// If spans are not instrumented, it means the HttpInstrumentation has not been added
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,15 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 9.8.0

- feat(node): Implement new continuous profiling API spec ([#15635](https://github.com/getsentry/sentry-javascript/pull/15635))
- feat(profiling): Add platform to chunk envelope ([#15758](https://github.com/getsentry/sentry-javascript/pull/15758))
- feat(react): Export captureReactException method ([#15746](https://github.com/getsentry/sentry-javascript/pull/15746))
- fix(node): Check for `res.end` before passing to Proxy ([#15776](https://github.com/getsentry/sentry-javascript/pull/15776))
- perf(core): Add short-circuits to `eventFilters` integration ([#15752](https://github.com/getsentry/sentry-javascript/pull/15752))
- perf(node): Short circuit flushing on Vercel only for Vercel ([#15734](https://github.com/getsentry/sentry-javascript/pull/15734))

## 9.7.0

- feat(core): Add `captureLog` method ([#15717](https://github.com/getsentry/sentry-javascript/pull/15717))
Expand Down
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
136 changes: 71 additions & 65 deletions packages/core/src/integrations/eventFilters.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,6 @@ export interface EventFiltersOptions {

const INTEGRATION_NAME = 'EventFilters';

const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
}) satisfies IntegrationFn;

/**
* An integration that filters out events (errors and transactions) based on:
*
Expand All@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
*
* Events filtered by this integration will not be sent to Sentry.
*/
export const eventFiltersIntegration = defineIntegration(_eventFiltersIntegration);
export const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {
let mergedOptions: Partial<EventFiltersOptions> | undefined;
return {
name: INTEGRATION_NAME,
setup(client) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
},
processEvent(event, _hint, client) {
if (!mergedOptions) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
}
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
});

/**
* An integration that filters out events (errors and transactions) based on:
Expand DownExpand Up@@ -102,66 +107,72 @@ function _mergeOptions(
}

function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {
if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
if (!event.type) {
// Filter errors

if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
} else if (event.type === 'transaction') {
// Filter transactions

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
}
return false;
}

function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {
// If event.type, this is not an error
if (event.type || !ignoreErrors || !ignoreErrors.length) {
if (!ignoreErrors?.length) {
return false;
}

return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
}

function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
if (!ignoreTransactions?.length) {
return false;
}

Expand DownExpand Up@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception?.values?.length) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,17 @@ import { stealthWrap } from './utils';
type Http = typeof http;
type Https = typeof https;

// The reason this "before OTEL" integration even exists is due to timing reasons. We need to be able to register a
// `res.on('close')` handler **after** OTEL registers its own handler (which it uses to end spans), so that we can do
// something (ie. flush) after OTEL has ended a span for a request. If you think about it like an onion:
//
// (Sentry after OTEL instrumentation
// (OTEL instrumentation
// (Sentry before OTEL instrumentation
// (orig HTTP request handler))))
//
// registering an instrumentation before OTEL allows us to do this for incoming requests.

/**
* A Sentry specific http instrumentation that is applied before the otel instrumentation.
*/
Expand DownExpand Up@@ -70,46 +81,50 @@ export class SentryHttpInstrumentationBeforeOtel extends InstrumentationBase {
function patchResponseToFlushOnServerlessPlatforms(res: http.OutgoingMessage): void {
// Freely extend this function with other platforms if necessary
if (process.env.VERCEL) {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
// https://github.com/getsentry/sentry-javascript/issues/15759
if (typeof res.end === 'function') {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
}
}
}
16 changes: 12 additions & 4 deletions packages/node/src/integrations/http/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentSentryHttpBeforeOtel();
// Below, we instrument the Node.js HTTP API three times. 2 times Sentry-specific, 1 time OTEL specific.
// Due to timing reasons, we sometimes need to apply Sentry instrumentation _before_ we apply the OTEL
// instrumentation (e.g. to flush on serverless platforms), and sometimes we need to apply Sentry instrumentation
// _after_ we apply OTEL instrumentation (e.g. for isolation scope handling and breadcrumbs).

// This is Sentry-specific instrumentation that is applied _before_ any OTEL instrumentation.
if (process.env.VERCEL) {
// Currently this instrumentation only does something when deployed on Vercel, so to save some overhead, we short circuit adding it here only for Vercel.
// If it's functionality is extended in the future, feel free to remove the if statement and this comment.
instrumentSentryHttpBeforeOtel();
}

const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());

Expand All@@ -152,9 +162,7 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
instrumentOtelHttp(instrumentationConfig);
}

// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
// Note that this _has_ to be wrapped after the OTEL instrumentation,
// otherwise the isolation will not work correctly
// This is Sentry-specific instrumentation that is applied _after_ any OTEL instrumentation.
instrumentSentryHttp({
...options,
// If spans are not instrumented, it means the HttpInstrumentation has not been added
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,15 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 9.8.0

- feat(node): Implement new continuous profiling API spec ([#15635](https://github.com/getsentry/sentry-javascript/pull/15635))
- feat(profiling): Add platform to chunk envelope ([#15758](https://github.com/getsentry/sentry-javascript/pull/15758))
- feat(react): Export captureReactException method ([#15746](https://github.com/getsentry/sentry-javascript/pull/15746))
- fix(node): Check for `res.end` before passing to Proxy ([#15776](https://github.com/getsentry/sentry-javascript/pull/15776))
- perf(core): Add short-circuits to `eventFilters` integration ([#15752](https://github.com/getsentry/sentry-javascript/pull/15752))
- perf(node): Short circuit flushing on Vercel only for Vercel ([#15734](https://github.com/getsentry/sentry-javascript/pull/15734))

## 9.7.0

- feat(core): Add `captureLog` method ([#15717](https://github.com/getsentry/sentry-javascript/pull/15717))
Expand Down
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
136 changes: 71 additions & 65 deletions packages/core/src/integrations/eventFilters.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,6 @@ export interface EventFiltersOptions {

const INTEGRATION_NAME = 'EventFilters';

const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
}) satisfies IntegrationFn;

/**
* An integration that filters out events (errors and transactions) based on:
*
Expand All@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
*
* Events filtered by this integration will not be sent to Sentry.
*/
export const eventFiltersIntegration = defineIntegration(_eventFiltersIntegration);
export const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {
let mergedOptions: Partial<EventFiltersOptions> | undefined;
return {
name: INTEGRATION_NAME,
setup(client) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
},
processEvent(event, _hint, client) {
if (!mergedOptions) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
}
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
});

/**
* An integration that filters out events (errors and transactions) based on:
Expand DownExpand Up@@ -102,66 +107,72 @@ function _mergeOptions(
}

function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {
if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
if (!event.type) {
// Filter errors

if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
} else if (event.type === 'transaction') {
// Filter transactions

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
}
return false;
}

function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {
// If event.type, this is not an error
if (event.type || !ignoreErrors || !ignoreErrors.length) {
if (!ignoreErrors?.length) {
return false;
}

return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
}

function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
if (!ignoreTransactions?.length) {
return false;
}

Expand DownExpand Up@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception?.values?.length) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,17 @@ import { stealthWrap } from './utils';
type Http = typeof http;
type Https = typeof https;

// The reason this "before OTEL" integration even exists is due to timing reasons. We need to be able to register a
// `res.on('close')` handler **after** OTEL registers its own handler (which it uses to end spans), so that we can do
// something (ie. flush) after OTEL has ended a span for a request. If you think about it like an onion:
//
// (Sentry after OTEL instrumentation
// (OTEL instrumentation
// (Sentry before OTEL instrumentation
// (orig HTTP request handler))))
//
// registering an instrumentation before OTEL allows us to do this for incoming requests.

/**
* A Sentry specific http instrumentation that is applied before the otel instrumentation.
*/
Expand DownExpand Up@@ -70,46 +81,50 @@ export class SentryHttpInstrumentationBeforeOtel extends InstrumentationBase {
function patchResponseToFlushOnServerlessPlatforms(res: http.OutgoingMessage): void {
// Freely extend this function with other platforms if necessary
if (process.env.VERCEL) {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
// https://github.com/getsentry/sentry-javascript/issues/15759
if (typeof res.end === 'function') {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
}
}
}
16 changes: 12 additions & 4 deletions packages/node/src/integrations/http/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentSentryHttpBeforeOtel();
// Below, we instrument the Node.js HTTP API three times. 2 times Sentry-specific, 1 time OTEL specific.
// Due to timing reasons, we sometimes need to apply Sentry instrumentation _before_ we apply the OTEL
// instrumentation (e.g. to flush on serverless platforms), and sometimes we need to apply Sentry instrumentation
// _after_ we apply OTEL instrumentation (e.g. for isolation scope handling and breadcrumbs).

// This is Sentry-specific instrumentation that is applied _before_ any OTEL instrumentation.
if (process.env.VERCEL) {
// Currently this instrumentation only does something when deployed on Vercel, so to save some overhead, we short circuit adding it here only for Vercel.
// If it's functionality is extended in the future, feel free to remove the if statement and this comment.
instrumentSentryHttpBeforeOtel();
}

const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());

Expand All@@ -152,9 +162,7 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
instrumentOtelHttp(instrumentationConfig);
}

// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
// Note that this _has_ to be wrapped after the OTEL instrumentation,
// otherwise the isolation will not work correctly
// This is Sentry-specific instrumentation that is applied _after_ any OTEL instrumentation.
instrumentSentryHttp({
...options,
// If spans are not instrumented, it means the HttpInstrumentation has not been added
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,15 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 9.8.0

- feat(node): Implement new continuous profiling API spec ([#15635](https://github.com/getsentry/sentry-javascript/pull/15635))
- feat(profiling): Add platform to chunk envelope ([#15758](https://github.com/getsentry/sentry-javascript/pull/15758))
- feat(react): Export captureReactException method ([#15746](https://github.com/getsentry/sentry-javascript/pull/15746))
- fix(node): Check for `res.end` before passing to Proxy ([#15776](https://github.com/getsentry/sentry-javascript/pull/15776))
- perf(core): Add short-circuits to `eventFilters` integration ([#15752](https://github.com/getsentry/sentry-javascript/pull/15752))
- perf(node): Short circuit flushing on Vercel only for Vercel ([#15734](https://github.com/getsentry/sentry-javascript/pull/15734))

## 9.7.0

- feat(core): Add `captureLog` method ([#15717](https://github.com/getsentry/sentry-javascript/pull/15717))
Expand Down
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
136 changes: 71 additions & 65 deletions packages/core/src/integrations/eventFilters.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,6 @@ export interface EventFiltersOptions {

const INTEGRATION_NAME = 'EventFilters';

const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
}) satisfies IntegrationFn;

/**
* An integration that filters out events (errors and transactions) based on:
*
Expand All@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
*
* Events filtered by this integration will not be sent to Sentry.
*/
export const eventFiltersIntegration = defineIntegration(_eventFiltersIntegration);
export const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {
let mergedOptions: Partial<EventFiltersOptions> | undefined;
return {
name: INTEGRATION_NAME,
setup(client) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
},
processEvent(event, _hint, client) {
if (!mergedOptions) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
}
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
});

/**
* An integration that filters out events (errors and transactions) based on:
Expand DownExpand Up@@ -102,66 +107,72 @@ function _mergeOptions(
}

function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {
if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
if (!event.type) {
// Filter errors

if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
} else if (event.type === 'transaction') {
// Filter transactions

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
}
return false;
}

function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {
// If event.type, this is not an error
if (event.type || !ignoreErrors || !ignoreErrors.length) {
if (!ignoreErrors?.length) {
return false;
}

return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
}

function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
if (!ignoreTransactions?.length) {
return false;
}

Expand DownExpand Up@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception?.values?.length) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,17 @@ import { stealthWrap } from './utils';
type Http = typeof http;
type Https = typeof https;

// The reason this "before OTEL" integration even exists is due to timing reasons. We need to be able to register a
// `res.on('close')` handler **after** OTEL registers its own handler (which it uses to end spans), so that we can do
// something (ie. flush) after OTEL has ended a span for a request. If you think about it like an onion:
//
// (Sentry after OTEL instrumentation
// (OTEL instrumentation
// (Sentry before OTEL instrumentation
// (orig HTTP request handler))))
//
// registering an instrumentation before OTEL allows us to do this for incoming requests.

/**
* A Sentry specific http instrumentation that is applied before the otel instrumentation.
*/
Expand DownExpand Up@@ -70,46 +81,50 @@ export class SentryHttpInstrumentationBeforeOtel extends InstrumentationBase {
function patchResponseToFlushOnServerlessPlatforms(res: http.OutgoingMessage): void {
// Freely extend this function with other platforms if necessary
if (process.env.VERCEL) {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
// https://github.com/getsentry/sentry-javascript/issues/15759
if (typeof res.end === 'function') {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
}
}
}
16 changes: 12 additions & 4 deletions packages/node/src/integrations/http/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentSentryHttpBeforeOtel();
// Below, we instrument the Node.js HTTP API three times. 2 times Sentry-specific, 1 time OTEL specific.
// Due to timing reasons, we sometimes need to apply Sentry instrumentation _before_ we apply the OTEL
// instrumentation (e.g. to flush on serverless platforms), and sometimes we need to apply Sentry instrumentation
// _after_ we apply OTEL instrumentation (e.g. for isolation scope handling and breadcrumbs).

// This is Sentry-specific instrumentation that is applied _before_ any OTEL instrumentation.
if (process.env.VERCEL) {
// Currently this instrumentation only does something when deployed on Vercel, so to save some overhead, we short circuit adding it here only for Vercel.
// If it's functionality is extended in the future, feel free to remove the if statement and this comment.
instrumentSentryHttpBeforeOtel();
}

const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());

Expand All@@ -152,9 +162,7 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
instrumentOtelHttp(instrumentationConfig);
}

// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
// Note that this _has_ to be wrapped after the OTEL instrumentation,
// otherwise the isolation will not work correctly
// This is Sentry-specific instrumentation that is applied _after_ any OTEL instrumentation.
instrumentSentryHttp({
...options,
// If spans are not instrumented, it means the HttpInstrumentation has not been added
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,15 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 9.8.0

- feat(node): Implement new continuous profiling API spec ([#15635](https://github.com/getsentry/sentry-javascript/pull/15635))
- feat(profiling): Add platform to chunk envelope ([#15758](https://github.com/getsentry/sentry-javascript/pull/15758))
- feat(react): Export captureReactException method ([#15746](https://github.com/getsentry/sentry-javascript/pull/15746))
- fix(node): Check for `res.end` before passing to Proxy ([#15776](https://github.com/getsentry/sentry-javascript/pull/15776))
- perf(core): Add short-circuits to `eventFilters` integration ([#15752](https://github.com/getsentry/sentry-javascript/pull/15752))
- perf(node): Short circuit flushing on Vercel only for Vercel ([#15734](https://github.com/getsentry/sentry-javascript/pull/15734))

## 9.7.0

- feat(core): Add `captureLog` method ([#15717](https://github.com/getsentry/sentry-javascript/pull/15717))
Expand Down
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
136 changes: 71 additions & 65 deletions packages/core/src/integrations/eventFilters.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,6 @@ export interface EventFiltersOptions {

const INTEGRATION_NAME = 'EventFilters';

const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
}) satisfies IntegrationFn;

/**
* An integration that filters out events (errors and transactions) based on:
*
Expand All@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
*
* Events filtered by this integration will not be sent to Sentry.
*/
export const eventFiltersIntegration = defineIntegration(_eventFiltersIntegration);
export const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {
let mergedOptions: Partial<EventFiltersOptions> | undefined;
return {
name: INTEGRATION_NAME,
setup(client) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
},
processEvent(event, _hint, client) {
if (!mergedOptions) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
}
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
});

/**
* An integration that filters out events (errors and transactions) based on:
Expand DownExpand Up@@ -102,66 +107,72 @@ function _mergeOptions(
}

function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {
if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
if (!event.type) {
// Filter errors

if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
} else if (event.type === 'transaction') {
// Filter transactions

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
}
return false;
}

function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {
// If event.type, this is not an error
if (event.type || !ignoreErrors || !ignoreErrors.length) {
if (!ignoreErrors?.length) {
return false;
}

return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
}

function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
if (!ignoreTransactions?.length) {
return false;
}

Expand DownExpand Up@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception?.values?.length) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,17 @@ import { stealthWrap } from './utils';
type Http = typeof http;
type Https = typeof https;

// The reason this "before OTEL" integration even exists is due to timing reasons. We need to be able to register a
// `res.on('close')` handler **after** OTEL registers its own handler (which it uses to end spans), so that we can do
// something (ie. flush) after OTEL has ended a span for a request. If you think about it like an onion:
//
// (Sentry after OTEL instrumentation
// (OTEL instrumentation
// (Sentry before OTEL instrumentation
// (orig HTTP request handler))))
//
// registering an instrumentation before OTEL allows us to do this for incoming requests.

/**
* A Sentry specific http instrumentation that is applied before the otel instrumentation.
*/
Expand DownExpand Up@@ -70,46 +81,50 @@ export class SentryHttpInstrumentationBeforeOtel extends InstrumentationBase {
function patchResponseToFlushOnServerlessPlatforms(res: http.OutgoingMessage): void {
// Freely extend this function with other platforms if necessary
if (process.env.VERCEL) {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
// https://github.com/getsentry/sentry-javascript/issues/15759
if (typeof res.end === 'function') {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
}
}
}
16 changes: 12 additions & 4 deletions packages/node/src/integrations/http/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentSentryHttpBeforeOtel();
// Below, we instrument the Node.js HTTP API three times. 2 times Sentry-specific, 1 time OTEL specific.
// Due to timing reasons, we sometimes need to apply Sentry instrumentation _before_ we apply the OTEL
// instrumentation (e.g. to flush on serverless platforms), and sometimes we need to apply Sentry instrumentation
// _after_ we apply OTEL instrumentation (e.g. for isolation scope handling and breadcrumbs).

// This is Sentry-specific instrumentation that is applied _before_ any OTEL instrumentation.
if (process.env.VERCEL) {
// Currently this instrumentation only does something when deployed on Vercel, so to save some overhead, we short circuit adding it here only for Vercel.
// If it's functionality is extended in the future, feel free to remove the if statement and this comment.
instrumentSentryHttpBeforeOtel();
}

const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());

Expand All@@ -152,9 +162,7 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
instrumentOtelHttp(instrumentationConfig);
}

// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
// Note that this _has_ to be wrapped after the OTEL instrumentation,
// otherwise the isolation will not work correctly
// This is Sentry-specific instrumentation that is applied _after_ any OTEL instrumentation.
instrumentSentryHttp({
...options,
// If spans are not instrumented, it means the HttpInstrumentation has not been added
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,15 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 9.8.0

- feat(node): Implement new continuous profiling API spec ([#15635](https://github.com/getsentry/sentry-javascript/pull/15635))
- feat(profiling): Add platform to chunk envelope ([#15758](https://github.com/getsentry/sentry-javascript/pull/15758))
- feat(react): Export captureReactException method ([#15746](https://github.com/getsentry/sentry-javascript/pull/15746))
- fix(node): Check for `res.end` before passing to Proxy ([#15776](https://github.com/getsentry/sentry-javascript/pull/15776))
- perf(core): Add short-circuits to `eventFilters` integration ([#15752](https://github.com/getsentry/sentry-javascript/pull/15752))
- perf(node): Short circuit flushing on Vercel only for Vercel ([#15734](https://github.com/getsentry/sentry-javascript/pull/15734))

## 9.7.0

- feat(core): Add `captureLog` method ([#15717](https://github.com/getsentry/sentry-javascript/pull/15717))
Expand Down
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
136 changes: 71 additions & 65 deletions packages/core/src/integrations/eventFilters.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,6 @@ export interface EventFiltersOptions {

const INTEGRATION_NAME = 'EventFilters';

const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
}) satisfies IntegrationFn;

/**
* An integration that filters out events (errors and transactions) based on:
*
Expand All@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
*
* Events filtered by this integration will not be sent to Sentry.
*/
export const eventFiltersIntegration = defineIntegration(_eventFiltersIntegration);
export const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {
let mergedOptions: Partial<EventFiltersOptions> | undefined;
return {
name: INTEGRATION_NAME,
setup(client) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
},
processEvent(event, _hint, client) {
if (!mergedOptions) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
}
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
});

/**
* An integration that filters out events (errors and transactions) based on:
Expand DownExpand Up@@ -102,66 +107,72 @@ function _mergeOptions(
}

function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {
if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
if (!event.type) {
// Filter errors

if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
} else if (event.type === 'transaction') {
// Filter transactions

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
}
return false;
}

function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {
// If event.type, this is not an error
if (event.type || !ignoreErrors || !ignoreErrors.length) {
if (!ignoreErrors?.length) {
return false;
}

return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
}

function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
if (!ignoreTransactions?.length) {
return false;
}

Expand DownExpand Up@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception?.values?.length) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,17 @@ import { stealthWrap } from './utils';
type Http = typeof http;
type Https = typeof https;

// The reason this "before OTEL" integration even exists is due to timing reasons. We need to be able to register a
// `res.on('close')` handler **after** OTEL registers its own handler (which it uses to end spans), so that we can do
// something (ie. flush) after OTEL has ended a span for a request. If you think about it like an onion:
//
// (Sentry after OTEL instrumentation
// (OTEL instrumentation
// (Sentry before OTEL instrumentation
// (orig HTTP request handler))))
//
// registering an instrumentation before OTEL allows us to do this for incoming requests.

/**
* A Sentry specific http instrumentation that is applied before the otel instrumentation.
*/
Expand DownExpand Up@@ -70,46 +81,50 @@ export class SentryHttpInstrumentationBeforeOtel extends InstrumentationBase {
function patchResponseToFlushOnServerlessPlatforms(res: http.OutgoingMessage): void {
// Freely extend this function with other platforms if necessary
if (process.env.VERCEL) {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
// https://github.com/getsentry/sentry-javascript/issues/15759
if (typeof res.end === 'function') {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
}
}
}
16 changes: 12 additions & 4 deletions packages/node/src/integrations/http/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentSentryHttpBeforeOtel();
// Below, we instrument the Node.js HTTP API three times. 2 times Sentry-specific, 1 time OTEL specific.
// Due to timing reasons, we sometimes need to apply Sentry instrumentation _before_ we apply the OTEL
// instrumentation (e.g. to flush on serverless platforms), and sometimes we need to apply Sentry instrumentation
// _after_ we apply OTEL instrumentation (e.g. for isolation scope handling and breadcrumbs).

// This is Sentry-specific instrumentation that is applied _before_ any OTEL instrumentation.
if (process.env.VERCEL) {
// Currently this instrumentation only does something when deployed on Vercel, so to save some overhead, we short circuit adding it here only for Vercel.
// If it's functionality is extended in the future, feel free to remove the if statement and this comment.
instrumentSentryHttpBeforeOtel();
}

const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());

Expand All@@ -152,9 +162,7 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
instrumentOtelHttp(instrumentationConfig);
}

// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
// Note that this _has_ to be wrapped after the OTEL instrumentation,
// otherwise the isolation will not work correctly
// This is Sentry-specific instrumentation that is applied _after_ any OTEL instrumentation.
instrumentSentryHttp({
...options,
// If spans are not instrumented, it means the HttpInstrumentation has not been added
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,15 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 9.8.0

- feat(node): Implement new continuous profiling API spec ([#15635](https://github.com/getsentry/sentry-javascript/pull/15635))
- feat(profiling): Add platform to chunk envelope ([#15758](https://github.com/getsentry/sentry-javascript/pull/15758))
- feat(react): Export captureReactException method ([#15746](https://github.com/getsentry/sentry-javascript/pull/15746))
- fix(node): Check for `res.end` before passing to Proxy ([#15776](https://github.com/getsentry/sentry-javascript/pull/15776))
- perf(core): Add short-circuits to `eventFilters` integration ([#15752](https://github.com/getsentry/sentry-javascript/pull/15752))
- perf(node): Short circuit flushing on Vercel only for Vercel ([#15734](https://github.com/getsentry/sentry-javascript/pull/15734))

## 9.7.0

- feat(core): Add `captureLog` method ([#15717](https://github.com/getsentry/sentry-javascript/pull/15717))
Expand Down
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
136 changes: 71 additions & 65 deletions packages/core/src/integrations/eventFilters.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,6 @@ export interface EventFiltersOptions {

const INTEGRATION_NAME = 'EventFilters';

const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
}) satisfies IntegrationFn;

/**
* An integration that filters out events (errors and transactions) based on:
*
Expand All@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
*
* Events filtered by this integration will not be sent to Sentry.
*/
export const eventFiltersIntegration = defineIntegration(_eventFiltersIntegration);
export const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {
let mergedOptions: Partial<EventFiltersOptions> | undefined;
return {
name: INTEGRATION_NAME,
setup(client) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
},
processEvent(event, _hint, client) {
if (!mergedOptions) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
}
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
});

/**
* An integration that filters out events (errors and transactions) based on:
Expand DownExpand Up@@ -102,66 +107,72 @@ function _mergeOptions(
}

function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {
if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
if (!event.type) {
// Filter errors

if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
} else if (event.type === 'transaction') {
// Filter transactions

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
}
return false;
}

function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {
// If event.type, this is not an error
if (event.type || !ignoreErrors || !ignoreErrors.length) {
if (!ignoreErrors?.length) {
return false;
}

return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
}

function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
if (!ignoreTransactions?.length) {
return false;
}

Expand DownExpand Up@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception?.values?.length) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,17 @@ import { stealthWrap } from './utils';
type Http = typeof http;
type Https = typeof https;

// The reason this "before OTEL" integration even exists is due to timing reasons. We need to be able to register a
// `res.on('close')` handler **after** OTEL registers its own handler (which it uses to end spans), so that we can do
// something (ie. flush) after OTEL has ended a span for a request. If you think about it like an onion:
//
// (Sentry after OTEL instrumentation
// (OTEL instrumentation
// (Sentry before OTEL instrumentation
// (orig HTTP request handler))))
//
// registering an instrumentation before OTEL allows us to do this for incoming requests.

/**
* A Sentry specific http instrumentation that is applied before the otel instrumentation.
*/
Expand DownExpand Up@@ -70,46 +81,50 @@ export class SentryHttpInstrumentationBeforeOtel extends InstrumentationBase {
function patchResponseToFlushOnServerlessPlatforms(res: http.OutgoingMessage): void {
// Freely extend this function with other platforms if necessary
if (process.env.VERCEL) {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
// https://github.com/getsentry/sentry-javascript/issues/15759
if (typeof res.end === 'function') {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
}
}
}
16 changes: 12 additions & 4 deletions packages/node/src/integrations/http/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentSentryHttpBeforeOtel();
// Below, we instrument the Node.js HTTP API three times. 2 times Sentry-specific, 1 time OTEL specific.
// Due to timing reasons, we sometimes need to apply Sentry instrumentation _before_ we apply the OTEL
// instrumentation (e.g. to flush on serverless platforms), and sometimes we need to apply Sentry instrumentation
// _after_ we apply OTEL instrumentation (e.g. for isolation scope handling and breadcrumbs).

// This is Sentry-specific instrumentation that is applied _before_ any OTEL instrumentation.
if (process.env.VERCEL) {
// Currently this instrumentation only does something when deployed on Vercel, so to save some overhead, we short circuit adding it here only for Vercel.
// If it's functionality is extended in the future, feel free to remove the if statement and this comment.
instrumentSentryHttpBeforeOtel();
}

const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());

Expand All@@ -152,9 +162,7 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
instrumentOtelHttp(instrumentationConfig);
}

// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
// Note that this _has_ to be wrapped after the OTEL instrumentation,
// otherwise the isolation will not work correctly
// This is Sentry-specific instrumentation that is applied _after_ any OTEL instrumentation.
instrumentSentryHttp({
...options,
// If spans are not instrumented, it means the HttpInstrumentation has not been added
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,15 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 9.8.0

- feat(node): Implement new continuous profiling API spec ([#15635](https://github.com/getsentry/sentry-javascript/pull/15635))
- feat(profiling): Add platform to chunk envelope ([#15758](https://github.com/getsentry/sentry-javascript/pull/15758))
- feat(react): Export captureReactException method ([#15746](https://github.com/getsentry/sentry-javascript/pull/15746))
- fix(node): Check for `res.end` before passing to Proxy ([#15776](https://github.com/getsentry/sentry-javascript/pull/15776))
- perf(core): Add short-circuits to `eventFilters` integration ([#15752](https://github.com/getsentry/sentry-javascript/pull/15752))
- perf(node): Short circuit flushing on Vercel only for Vercel ([#15734](https://github.com/getsentry/sentry-javascript/pull/15734))

## 9.7.0

- feat(core): Add `captureLog` method ([#15717](https://github.com/getsentry/sentry-javascript/pull/15717))
Expand Down
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
136 changes: 71 additions & 65 deletions packages/core/src/integrations/eventFilters.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,6 @@ export interface EventFiltersOptions {

const INTEGRATION_NAME = 'EventFilters';

const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
}) satisfies IntegrationFn;

/**
* An integration that filters out events (errors and transactions) based on:
*
Expand All@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
*
* Events filtered by this integration will not be sent to Sentry.
*/
export const eventFiltersIntegration = defineIntegration(_eventFiltersIntegration);
export const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {
let mergedOptions: Partial<EventFiltersOptions> | undefined;
return {
name: INTEGRATION_NAME,
setup(client) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
},
processEvent(event, _hint, client) {
if (!mergedOptions) {
const clientOptions = client.getOptions();
mergedOptions = _mergeOptions(options, clientOptions);
}
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
});

/**
* An integration that filters out events (errors and transactions) based on:
Expand DownExpand Up@@ -102,66 +107,72 @@ function _mergeOptions(
}

function _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {
if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
if (!event.type) {
// Filter errors

if (options.ignoreInternal && _isSentryError(event)) {
DEBUG_BUILD &&
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (_isIgnoredError(event, options.ignoreErrors)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isDeniedUrl(event, options.denyUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
if (!_isAllowedUrl(event, options.allowUrls)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${_getEventFilterUrl(event)}`,
);
return true;
}
} else if (event.type === 'transaction') {
// Filter transactions

if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
}
return false;
}

function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {
// If event.type, this is not an error
if (event.type || !ignoreErrors || !ignoreErrors.length) {
if (!ignoreErrors?.length) {
return false;
}

return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
}

function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
if (!ignoreTransactions?.length) {
return false;
}

Expand DownExpand Up@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception?.values?.length) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,17 @@ import { stealthWrap } from './utils';
type Http = typeof http;
type Https = typeof https;

// The reason this "before OTEL" integration even exists is due to timing reasons. We need to be able to register a
// `res.on('close')` handler **after** OTEL registers its own handler (which it uses to end spans), so that we can do
// something (ie. flush) after OTEL has ended a span for a request. If you think about it like an onion:
//
// (Sentry after OTEL instrumentation
// (OTEL instrumentation
// (Sentry before OTEL instrumentation
// (orig HTTP request handler))))
//
// registering an instrumentation before OTEL allows us to do this for incoming requests.

/**
* A Sentry specific http instrumentation that is applied before the otel instrumentation.
*/
Expand DownExpand Up@@ -70,46 +81,50 @@ export class SentryHttpInstrumentationBeforeOtel extends InstrumentationBase {
function patchResponseToFlushOnServerlessPlatforms(res: http.OutgoingMessage): void {
// Freely extend this function with other platforms if necessary
if (process.env.VERCEL) {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
// https://github.com/getsentry/sentry-javascript/issues/15759
if (typeof res.end === 'function') {
let markOnEndDone = (): void => undefined;
const onEndDonePromise = new Promise<void>(res => {
markOnEndDone = res;
});

res.on('close', () => {
markOnEndDone();
});

// eslint-disable-next-line @typescript-eslint/unbound-method
res.end = new Proxy(res.end, {
apply(target, thisArg, argArray) {
vercelWaitUntil(
new Promise<void>(finishWaitUntil => {
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
const timeout = setTimeout(() => {
finishWaitUntil();
}, 2000);

onEndDonePromise
.then(() => {
DEBUG_BUILD && logger.log('Flushing events before Vercel Lambda freeze');
return flush(2000);
})
.then(
() => {
clearTimeout(timeout);
finishWaitUntil();
},
e => {
clearTimeout(timeout);
DEBUG_BUILD && logger.log('Error while flushing events for Vercel:\n', e);
finishWaitUntil();
},
);
}),
);

return target.apply(thisArg, argArray);
},
});
}
}
}
16 changes: 12 additions & 4 deletions packages/node/src/integrations/http/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentSentryHttpBeforeOtel();
// Below, we instrument the Node.js HTTP API three times. 2 times Sentry-specific, 1 time OTEL specific.
// Due to timing reasons, we sometimes need to apply Sentry instrumentation _before_ we apply the OTEL
// instrumentation (e.g. to flush on serverless platforms), and sometimes we need to apply Sentry instrumentation
// _after_ we apply OTEL instrumentation (e.g. for isolation scope handling and breadcrumbs).

// This is Sentry-specific instrumentation that is applied _before_ any OTEL instrumentation.
if (process.env.VERCEL) {
// Currently this instrumentation only does something when deployed on Vercel, so to save some overhead, we short circuit adding it here only for Vercel.
// If it's functionality is extended in the future, feel free to remove the if statement and this comment.
instrumentSentryHttpBeforeOtel();
}

const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());

Expand All@@ -152,9 +162,7 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
instrumentOtelHttp(instrumentationConfig);
}

// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
// Note that this _has_ to be wrapped after the OTEL instrumentation,
// otherwise the isolation will not work correctly
// This is Sentry-specific instrumentation that is applied _after_ any OTEL instrumentation.
instrumentSentryHttp({
...options,
// If spans are not instrumented, it means the HttpInstrumentation has not been added
Expand Down
Loading