Skip to content

Commit 25ec131

Browse files
committed
WIP better scope type
1 parent c24d043 commit 25ec131

File tree

3 files changed

+57
-36
lines changed

3 files changed

+57
-36
lines changed

packages/node-experimental/src/sdk/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function getClient<C extends Client>(): C {
4444

4545
/** Get the current scope. */
4646
export function getCurrentScope(): Scope {
47-
return getScopes().scope;
47+
return getScopes().scope as Scope;
4848
}
4949

5050
/**
@@ -63,12 +63,12 @@ export function getGlobalScope(): Scope {
6363
carrier.globalScope = new Scope();
6464
}
6565

66-
return carrier.globalScope;
66+
return carrier.globalScope as Scope;
6767
}
6868

6969
/** Get the currently active isolation scope. */
7070
export function getIsolationScope(): Scope {
71-
return getScopes().isolationScope;
71+
return getScopes().isolationScope as Scope;
7272
}
7373

7474
/**

packages/node-experimental/src/sdk/scope.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,13 @@
11
import { notifyEventProcessors } from '@sentry/core';
22
import { OpenTelemetryScope } from '@sentry/opentelemetry';
3-
import type {
4-
Attachment,
5-
Breadcrumb,
6-
Client,
7-
Contexts,
8-
Event,
9-
EventHint,
10-
EventProcessor,
11-
Extras,
12-
Primitive,
13-
PropagationContext,
14-
Severity,
15-
SeverityLevel,
16-
User,
17-
} from '@sentry/types';
3+
import type { Breadcrumb, Client, Event, EventHint, EventProcessor, Severity, SeverityLevel } from '@sentry/types';
184
import { uuid4 } from '@sentry/utils';
195

206
import { getClient, getGlobalScope, getIsolationScope } from './api';
21-
22-
interface ScopeData {
23-
eventProcessors: EventProcessor[];
24-
breadcrumbs: Breadcrumb[];
25-
user: User;
26-
tags: { [key: string]: Primitive };
27-
extra: Extras;
28-
contexts: Contexts;
29-
attachments: Attachment[];
30-
propagationContext: PropagationContext;
31-
sdkProcessingMetadata: { [key: string]: unknown };
32-
fingerprint: string[];
33-
// eslint-disable-next-line deprecation/deprecation
34-
level?: Severity | SeverityLevel;
35-
}
7+
import type { Scope as ScopeInterface, ScopeData } from './types';
368

379
/** A fork of the classic scope with some otel specific stuff. */
38-
export class Scope extends OpenTelemetryScope {
10+
export class Scope extends OpenTelemetryScope implements ScopeInterface {
3911
// Overwrite this if you want to use a specific isolation scope here
4012
public isolationScope: Scope | undefined;
4113

packages/node-experimental/src/sdk/types.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
1-
import type { Hub, Integration } from '@sentry/types';
2-
import type { Scope } from './scope';
1+
import type {
2+
Attachment,
3+
Breadcrumb,
4+
Client,
5+
Contexts,
6+
Event,
7+
EventHint,
8+
EventProcessor,
9+
Extras,
10+
Hub,
11+
Integration,
12+
Primitive,
13+
PropagationContext,
14+
Scope as BaseScope,
15+
Severity,
16+
SeverityLevel,
17+
User,
18+
} from '@sentry/types';
19+
20+
export interface ScopeData {
21+
eventProcessors: EventProcessor[];
22+
breadcrumbs: Breadcrumb[];
23+
user: User;
24+
tags: { [key: string]: Primitive };
25+
extra: Extras;
26+
contexts: Contexts;
27+
attachments: Attachment[];
28+
propagationContext: PropagationContext;
29+
sdkProcessingMetadata: { [key: string]: unknown };
30+
fingerprint: string[];
31+
level?: SeverityLevel;
32+
}
33+
34+
export interface Scope extends BaseScope {
35+
// @ts-expect-error typeof this is what we want here
36+
isolationScope: typeof this | undefined;
37+
// @ts-expect-error typeof this is what we want here
38+
clone(scope?: Scope): typeof this;
39+
setClient(client: Client): void;
40+
getClient(): Client | undefined;
41+
captureException(exception: unknown, hint?: EventHint): string;
42+
captureMessage(
43+
message: string,
44+
// eslint-disable-next-line deprecation/deprecation
45+
level?: Severity | SeverityLevel,
46+
hint?: EventHint,
47+
): string;
48+
captureEvent(event: Event, hint?: EventHint): string;
49+
lastEventId(): string | undefined;
50+
getScopeData(): ScopeData;
51+
}
352

453
export interface CurrentScopes {
554
scope: Scope;

0 commit comments

Comments
 (0)