Skip to content

ref(v8): Remove pushScope, popScope, isOlderThan, shouldSendDefaultPii from hub #11404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2024
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
97 changes: 31 additions & 66 deletions packages/core/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,6 @@ export class Hub implements HubInterface {
this._isolationScope = assignedIsolationScope;
}

/**
* Checks if this hub's version is older than the given version.
*
* @param version A version number to compare to.
* @return True if the given version is newer; otherwise false.
*
* @deprecated This will be removed in v8.
*/
public isOlderThan(version: number): boolean {
return this._version < version;
}

/**
* This binds the given client to the current scope.
* @param client An SDK client (client) instance.
Expand All @@ -170,72 +158,37 @@ export class Hub implements HubInterface {
}
}

/**
* @inheritDoc
*
* @deprecated Use `withScope` instead.
*/
public pushScope(): ScopeInterface {
// We want to clone the content of prev scope
// eslint-disable-next-line deprecation/deprecation
const scope = this.getScope().clone();
// eslint-disable-next-line deprecation/deprecation
this.getStack().push({
// eslint-disable-next-line deprecation/deprecation
client: this.getClient(),
scope,
});
return scope;
}

/**
* @inheritDoc
*
* @deprecated Use `withScope` instead.
*/
public popScope(): boolean {
// eslint-disable-next-line deprecation/deprecation
if (this.getStack().length <= 1) return false;
// eslint-disable-next-line deprecation/deprecation
return !!this.getStack().pop();
}

/**
* @inheritDoc
*
* @deprecated Use `Sentry.withScope()` instead.
*/
public withScope<T>(callback: (scope: ScopeInterface) => T): T {
// eslint-disable-next-line deprecation/deprecation
const scope = this.pushScope();
const scope = this._pushScope();

let maybePromiseResult: T;
try {
maybePromiseResult = callback(scope);
} catch (e) {
// eslint-disable-next-line deprecation/deprecation
this.popScope();
this._popScope();
throw e;
}

if (isThenable(maybePromiseResult)) {
// @ts-expect-error - isThenable returns the wrong type
return maybePromiseResult.then(
res => {
// eslint-disable-next-line deprecation/deprecation
this.popScope();
this._popScope();
return res;
},
e => {
// eslint-disable-next-line deprecation/deprecation
this.popScope();
this._popScope();
throw e;
},
);
}

// eslint-disable-next-line deprecation/deprecation
this.popScope();
this._popScope();
return maybePromiseResult;
}

Expand Down Expand Up @@ -501,20 +454,6 @@ export class Hub implements HubInterface {
return session;
}

/**
* Returns if default PII should be sent to Sentry and propagated in ourgoing requests
* when Tracing is used.
*
* @deprecated Use top-level `getClient().getOptions().sendDefaultPii` instead. This function
* only unnecessarily increased API surface but only wrapped accessing the option.
*/
public shouldSendDefaultPii(): boolean {
// eslint-disable-next-line deprecation/deprecation
const client = this.getClient();
const options = client && client.getOptions();
return Boolean(options && options.sendDefaultPii);
}

/**
* Sends the current Session on the scope
*/
Expand All @@ -527,6 +466,32 @@ export class Hub implements HubInterface {
client.captureSession(session);
}
}

/**
* Push a scope to the stack.
*/
private _pushScope(): ScopeInterface {
// We want to clone the content of prev scope
// eslint-disable-next-line deprecation/deprecation
const scope = this.getScope().clone();
// eslint-disable-next-line deprecation/deprecation
this.getStack().push({
// eslint-disable-next-line deprecation/deprecation
client: this.getClient(),
scope,
});
return scope;
}

/**
* Pop a scope from the stack.
*/
private _popScope(): boolean {
// eslint-disable-next-line deprecation/deprecation
if (this.getStack().length <= 1) return false;
// eslint-disable-next-line deprecation/deprecation
return !!this.getStack().pop();
}
}

/**
Expand Down
21 changes: 1 addition & 20 deletions packages/opentelemetry/src/custom/getCurrentHub.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client, EventHint, Hub, Integration, IntegrationClass, Scope, SeverityLevel } from '@sentry/types';
import type { Client, EventHint, Hub, Integration, IntegrationClass, SeverityLevel } from '@sentry/types';

import {
addBreadcrumb,
Expand All @@ -23,25 +23,11 @@ import {
*/
export function getCurrentHub(): Hub {
return {
isOlderThan(_version: number): boolean {
return false;
},

bindClient(client: Client): void {
const scope = getCurrentScope();
scope.setClient(client);
},

pushScope(): Scope {
// TODO: This does not work and is actually deprecated
return getCurrentScope();
},

popScope(): boolean {
// TODO: This does not work and is actually deprecated
return false;
},

withScope,
getClient: <C extends Client>() => getClient() as C | undefined,
getScope: getCurrentScope,
Expand Down Expand Up @@ -79,11 +65,6 @@ export function getCurrentHub(): Hub {
// only send the update
_sendSessionUpdate();
},

shouldSendDefaultPii(): boolean {
const client = getClient();
return Boolean(client ? client.getOptions().sendDefaultPii : false);
},
};
}

Expand Down
44 changes: 0 additions & 44 deletions packages/types/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ import type { User } from './user';
* working in case we have a version conflict.
*/
export interface Hub {
/**
* Checks if this hub's version is older than the given version.
*
* @param version A version number to compare to.
* @return True if the given version is newer; otherwise false.
*
* @deprecated This will be removed in v8.
*/
isOlderThan(version: number): boolean;

/**
* This binds the given client to the current scope.
* @param client An SDK client (client) instance.
Expand All @@ -32,31 +22,6 @@ export interface Hub {
*/
bindClient(client?: Client): void;

/**
* Create a new scope to store context information.
*
* The scope will be layered on top of the current one. It is isolated, i.e. all
* breadcrumbs and context information added to this scope will be removed once
* the scope ends. Be sure to always remove this scope with {@link this.popScope}
* when the operation finishes or throws.
*
* @returns Scope, the new cloned scope
*
* @deprecated Use `withScope` instead.
*/
pushScope(): Scope;

/**
* Removes a previously pushed scope from the stack.
*
* This restores the state before the scope was pushed. All breadcrumbs and
* context information added since the last call to {@link this.pushScope} are
* discarded.
*
* @deprecated Use `withScope` instead.
*/
popScope(): boolean;

/**
* Creates a new scope with and executes the given operation within.
* The scope is automatically removed once the operation
Expand Down Expand Up @@ -234,13 +199,4 @@ export interface Hub {
* @deprecated Use top-level `captureSession` instead.
*/
captureSession(endSession?: boolean): void;

/**
* Returns if default PII should be sent to Sentry and propagated in outgoing requests
* when Tracing is used.
*
* @deprecated Use top-level `getClient().getOptions().sendDefaultPii` instead. This function
* only unnecessarily increased API surface but only wrapped accessing the option.
*/
shouldSendDefaultPii(): boolean;
}