Skip to content

fix(types): Add addScopeListener to Scope interface #10952

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 3 commits into from
Mar 7, 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
34 changes: 10 additions & 24 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class Scope implements ScopeInterface {
}

/**
* Clone this scope instance.
* @inheritDoc
*/
public clone(): Scope {
const newScope = new Scope();
Expand All @@ -145,23 +145,22 @@ export class Scope implements ScopeInterface {
return newScope;
}

/** Update the client on the scope. */
/**
* @inheritDoc
*/
public setClient(client: Client | undefined): void {
this._client = client;
}

/**
* Get the client assigned to this scope.
*
* It is generally recommended to use the global function `Sentry.getClient()` instead, unless you know what you are doing.
* @inheritDoc
*/
public getClient<C extends Client>(): C | undefined {
return this._client as C | undefined;
}

/**
* Add internal on change listener. Used for sub SDKs that need to store the scope.
* @hidden
* @inheritDoc
*/
public addScopeListener(callback: (scope: Scope) => void): void {
this._scopeListeners.push(callback);
Expand Down Expand Up @@ -542,7 +541,7 @@ export class Scope implements ScopeInterface {
}

/**
* Add data which will be accessible during event processing but won't get sent to Sentry
* @inheritDoc
*/
public setSDKProcessingMetadata(newData: { [key: string]: unknown }): this {
this._sdkProcessingMetadata = { ...this._sdkProcessingMetadata, ...newData };
Expand All @@ -566,11 +565,7 @@ export class Scope implements ScopeInterface {
}

/**
* Capture an exception for this scope.
*
* @param exception The exception to capture.
* @param hint Optinal additional data to attach to the Sentry event.
* @returns the id of the captured Sentry event.
* @inheritDoc
*/
public captureException(exception: unknown, hint?: EventHint): string {
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
Expand All @@ -597,12 +592,7 @@ export class Scope implements ScopeInterface {
}

/**
* Capture a message for this scope.
*
* @param message The message to capture.
* @param level An optional severity level to report the message with.
* @param hint Optional additional data to attach to the Sentry event.
* @returns the id of the captured message.
* @inheritDoc
*/
public captureMessage(message: string, level?: SeverityLevel, hint?: EventHint): string {
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
Expand Down Expand Up @@ -630,11 +620,7 @@ export class Scope implements ScopeInterface {
}

/**
* Captures a manually created event for this scope and sends it to Sentry.
*
* @param exception The event to capture.
* @param hint Optional additional data to attach to the Sentry event.
* @returns the id of the captured event.
* @inheritDoc
*/
public captureEvent(event: Event, hint?: EventHint): string {
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export interface Scope {
*/
getClient<C extends Client>(): C | undefined;

/**
* Add internal on change listener. Used for sub SDKs that need to store the scope.
* @hidden
*/
addScopeListener(callback: (scope: Scope) => void): void;

/** Add new event processor that will be called during event processing. */
addEventProcessor(callback: EventProcessor): this;

Expand Down