Skip to content

Commit 04a1ebe

Browse files
authored
fix(types): Add addScopeListener to Scope interface (#10952)
`getCurrentScope()` has been changed to return the `Scope` interface rather than the `Scope` class. This means it's no longer possible to access `addScopeListener` on the returned scope. This PR adds this method to the interface. I also updated all the jsdocs in the class to use `@inheritDoc` so these docs aren't duplicated.
1 parent 560a774 commit 04a1ebe

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

packages/core/src/scope.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class Scope implements ScopeInterface {
121121
}
122122

123123
/**
124-
* Clone this scope instance.
124+
* @inheritDoc
125125
*/
126126
public clone(): Scope {
127127
const newScope = new Scope();
@@ -145,23 +145,22 @@ export class Scope implements ScopeInterface {
145145
return newScope;
146146
}
147147

148-
/** Update the client on the scope. */
148+
/**
149+
* @inheritDoc
150+
*/
149151
public setClient(client: Client | undefined): void {
150152
this._client = client;
151153
}
152154

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

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

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

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

599594
/**
600-
* Capture a message for this scope.
601-
*
602-
* @param message The message to capture.
603-
* @param level An optional severity level to report the message with.
604-
* @param hint Optional additional data to attach to the Sentry event.
605-
* @returns the id of the captured message.
595+
* @inheritDoc
606596
*/
607597
public captureMessage(message: string, level?: SeverityLevel, hint?: EventHint): string {
608598
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
@@ -630,11 +620,7 @@ export class Scope implements ScopeInterface {
630620
}
631621

632622
/**
633-
* Captures a manually created event for this scope and sends it to Sentry.
634-
*
635-
* @param exception The event to capture.
636-
* @param hint Optional additional data to attach to the Sentry event.
637-
* @returns the id of the captured event.
623+
* @inheritDoc
638624
*/
639625
public captureEvent(event: Event, hint?: EventHint): string {
640626
const eventId = hint && hint.event_id ? hint.event_id : uuid4();

packages/types/src/scope.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export interface Scope {
6161
*/
6262
getClient<C extends Client>(): C | undefined;
6363

64+
/**
65+
* Add internal on change listener. Used for sub SDKs that need to store the scope.
66+
* @hidden
67+
*/
68+
addScopeListener(callback: (scope: Scope) => void): void;
69+
6470
/** Add new event processor that will be called during event processing. */
6571
addEventProcessor(callback: EventProcessor): this;
6672

0 commit comments

Comments
 (0)