Skip to content

Commit 0757de1

Browse files
committed
make it backwards compat
1 parent 33e25b8 commit 0757de1

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

packages/browser/src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ export class BrowserClient extends Client<BrowserClientOptions> {
8585

8686
super(opts);
8787

88-
const { sendDefaultPii, sendClientReports, enableLogs } = this._options;
88+
const { sendDefaultPii, sendClientReports, enableLogs, _experiments } = this._options;
89+
const shouldEnableLogs = enableLogs ?? _experiments?.enableLogs;
8990

90-
if (WINDOW.document && (sendClientReports || enableLogs)) {
91+
if (WINDOW.document && (sendClientReports || shouldEnableLogs)) {
9192
WINDOW.document.addEventListener('visibilitychange', () => {
9293
if (WINDOW.document.visibilityState === 'hidden') {
9394
if (sendClientReports) {

packages/core/src/logs/console-integration.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ const _consoleLoggingIntegration = ((options: Partial<CaptureConsoleOptions> = {
3333
return {
3434
name: INTEGRATION_NAME,
3535
setup(client) {
36-
const { enableLogs, normalizeDepth = 3, normalizeMaxBreadth = 1_000 } = client.getOptions();
37-
if (!enableLogs) {
36+
const { enableLogs, _experiments, normalizeDepth = 3, normalizeMaxBreadth = 1_000 } = client.getOptions();
37+
// eslint-disable-next-line deprecation/deprecation
38+
const shouldEnableLogs = enableLogs ?? _experiments?.enableLogs;
39+
if (!shouldEnableLogs) {
3840
DEBUG_BUILD && debug.warn('`enableLogs` is not enabled, ConsoleLogs integration disabled');
3941
return;
4042
}

packages/core/src/logs/exports.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ export function _INTERNAL_captureLog(
124124
return;
125125
}
126126

127-
const { release, environment, enableLogs = false, beforeSendLog } = client.getOptions();
128-
if (!enableLogs) {
127+
const { release, environment, enableLogs = false, beforeSendLog, _experiments } = client.getOptions();
128+
// eslint-disable-next-line deprecation/deprecation
129+
const shouldEnableLogs = enableLogs ?? _experiments?.enableLogs;
130+
if (!shouldEnableLogs) {
129131
DEBUG_BUILD && debug.warn('logging option not enabled, log will not be captured.');
130132
return;
131133
}
134+
// eslint-disable-next-line deprecation/deprecation
135+
const actualBeforeSendLog = beforeSendLog ?? _experiments?.beforeSendLog;
132136

133137
const [, traceContext] = _getTraceInfoFromScope(client, currentScope);
134138

@@ -168,7 +172,7 @@ export function _INTERNAL_captureLog(
168172
client.emit('beforeCaptureLog', processedLog);
169173

170174
// We need to wrap this in `consoleSandbox` to avoid recursive calls to `beforeSendLog`
171-
const log = beforeSendLog ? consoleSandbox(() => beforeSendLog(processedLog)) : processedLog;
175+
const log = actualBeforeSendLog ? consoleSandbox(() => actualBeforeSendLog(processedLog)) : processedLog;
172176
if (!log) {
173177
client.recordDroppedEvent('before_send', 'log_item', 1);
174178
DEBUG_BUILD && debug.warn('beforeSendLog returned null, log will not be captured.');

packages/core/src/server-runtime-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export class ServerRuntimeClient<
4949

5050
this._logWeight = 0;
5151

52-
if (this._options.enableLogs) {
52+
// eslint-disable-next-line deprecation/deprecation
53+
const shouldEnableLogs = this._options.enableLogs ?? this._options._experiments?.enableLogs;
54+
if (shouldEnableLogs) {
5355
// eslint-disable-next-line @typescript-eslint/no-this-alias
5456
const client = this;
5557

packages/core/src/types-hoist/options.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,31 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
246246
_experiments?: {
247247
// eslint-disable-next-line @typescript-eslint/no-explicit-any
248248
[key: string]: any;
249+
250+
/**
251+
* If logs support should be enabled.
252+
*
253+
* @deprecated Use the top-level `enableLogs` option instead.
254+
*
255+
* @default false
256+
*/
257+
enableLogs?: boolean;
258+
259+
/**
260+
* An event-processing callback for logs, guaranteed to be invoked after all other log
261+
* processors. This allows a log to be modified or dropped before it's sent.
262+
*
263+
* Note that you must return a valid log from this callback. If you do not wish to modify the log, simply return
264+
* it at the end. Returning `null` will cause the log to be dropped.
265+
*
266+
* @deprecated Use the top-level `beforeSendLog` option instead.
267+
*
268+
* @default undefined
269+
*
270+
* @param log The log generated by the SDK.
271+
* @returns A new log that will be sent | null.
272+
*/
273+
beforeSendLog?: (log: Log) => Log | null;
249274
};
250275

251276
/**

packages/node-core/src/sdk/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export class NodeClient extends ServerRuntimeClient<NodeClientOptions> {
4545

4646
super(clientOptions);
4747

48-
if (this.getOptions().enableLogs) {
48+
const { enableLogs, _experiments } = this.getOptions();
49+
// eslint-disable-next-line deprecation/deprecation
50+
const shouldEnableLogs = enableLogs ?? _experiments?.enableLogs;
51+
if (shouldEnableLogs) {
4952
this._logOnExitFlushListener = () => {
5053
_INTERNAL_flushLogsBuffer(this);
5154
};

0 commit comments

Comments
 (0)