Skip to content

Commit be0d7a9

Browse files
authored
feat(core): Make setXXX methods set on isolation scope (#10678)
The hub already writes there, but this circumvents the hub now!
1 parent 8af205e commit be0d7a9

File tree

4 files changed

+19
-78
lines changed

4 files changed

+19
-78
lines changed

packages/core/src/exports.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,15 @@ export function captureEvent(event: Event, hint?: EventHint): string {
8282
*/
8383
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8484
export function setContext(name: string, context: { [key: string]: any } | null): ReturnType<Hub['setContext']> {
85-
// eslint-disable-next-line deprecation/deprecation
86-
getCurrentHub().setContext(name, context);
85+
getIsolationScope().setContext(name, context);
8786
}
8887

8988
/**
9089
* Set an object that will be merged sent as extra data with the event.
9190
* @param extras Extras object to merge into current context.
9291
*/
9392
export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
94-
// eslint-disable-next-line deprecation/deprecation
95-
getCurrentHub().setExtras(extras);
93+
getIsolationScope().setExtras(extras);
9694
}
9795

9896
/**
@@ -101,17 +99,15 @@ export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
10199
* @param extra Any kind of data. This data will be normalized.
102100
*/
103101
export function setExtra(key: string, extra: Extra): ReturnType<Hub['setExtra']> {
104-
// eslint-disable-next-line deprecation/deprecation
105-
getCurrentHub().setExtra(key, extra);
102+
getIsolationScope().setExtra(key, extra);
106103
}
107104

108105
/**
109106
* Set an object that will be merged sent as tags data with the event.
110107
* @param tags Tags context object to merge into current context.
111108
*/
112109
export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['setTags']> {
113-
// eslint-disable-next-line deprecation/deprecation
114-
getCurrentHub().setTags(tags);
110+
getIsolationScope().setTags(tags);
115111
}
116112

117113
/**
@@ -123,8 +119,7 @@ export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['set
123119
* @param value Value of tag
124120
*/
125121
export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']> {
126-
// eslint-disable-next-line deprecation/deprecation
127-
getCurrentHub().setTag(key, value);
122+
getIsolationScope().setTag(key, value);
128123
}
129124

130125
/**
@@ -133,8 +128,7 @@ export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']>
133128
* @param user User context object to be set in the current context. Pass `null` to unset the user.
134129
*/
135130
export function setUser(user: User | null): ReturnType<Hub['setUser']> {
136-
// eslint-disable-next-line deprecation/deprecation
137-
getCurrentHub().setUser(user);
131+
getIsolationScope().setUser(user);
138132
}
139133

140134
/**

packages/node-experimental/src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ export {
3232
captureException,
3333
captureEvent,
3434
captureMessage,
35-
addEventProcessor,
36-
setContext,
37-
setExtra,
38-
setExtras,
39-
setTag,
40-
setTags,
41-
setUser,
4235
withScope,
4336
withIsolationScope,
4437
withActiveSpan,
@@ -84,6 +77,13 @@ export {
8477
functionToStringIntegration,
8578
inboundFiltersIntegration,
8679
linkedErrorsIntegration,
80+
addEventProcessor,
81+
setContext,
82+
setExtra,
83+
setExtras,
84+
setTag,
85+
setTags,
86+
setUser,
8787
SEMANTIC_ATTRIBUTE_SENTRY_OP,
8888
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
8989
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,

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

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
22

33
import type { Span } from '@opentelemetry/api';
44
import { context, trace } from '@opentelemetry/api';
5-
import type {
6-
CaptureContext,
7-
Event,
8-
EventHint,
9-
EventProcessor,
10-
Extra,
11-
Extras,
12-
Primitive,
13-
Scope,
14-
SeverityLevel,
15-
User,
16-
} from '@sentry/types';
5+
import type { CaptureContext, Event, EventHint, Scope, SeverityLevel } from '@sentry/types';
176
import { getContextFromScope, getScopesFromContext, setScopesOnContext } from '../utils/contextData';
187

198
import type { ExclusiveEventHintOrCaptureContext } from '../utils/prepareEvent';
@@ -112,44 +101,3 @@ export function captureMessage(message: string, captureContext?: CaptureContext
112101
export function captureEvent(event: Event, hint?: EventHint): string {
113102
return getCurrentScope().captureEvent(event, hint);
114103
}
115-
116-
/**
117-
* Add an event processor to the current isolation scope.
118-
*/
119-
export function addEventProcessor(eventProcessor: EventProcessor): void {
120-
getIsolationScope().addEventProcessor(eventProcessor);
121-
}
122-
123-
/** Set the user for the current isolation scope. */
124-
export function setUser(user: User | null): void {
125-
getIsolationScope().setUser(user);
126-
}
127-
128-
/** Set tags for the current isolation scope. */
129-
export function setTags(tags: { [key: string]: Primitive }): void {
130-
getIsolationScope().setTags(tags);
131-
}
132-
133-
/** Set a single tag user for the current isolation scope. */
134-
export function setTag(key: string, value: Primitive): void {
135-
getIsolationScope().setTag(key, value);
136-
}
137-
138-
/** Set extra data for the current isolation scope. */
139-
export function setExtra(key: string, extra: Extra): void {
140-
getIsolationScope().setExtra(key, extra);
141-
}
142-
143-
/** Set multiple extra data for the current isolation scope. */
144-
export function setExtras(extras: Extras): void {
145-
getIsolationScope().setExtras(extras);
146-
}
147-
148-
/** Set context data for the current isolation scope. */
149-
export function setContext(
150-
name: string,
151-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
152-
context: { [key: string]: any } | null,
153-
): void {
154-
getIsolationScope().setContext(name, context);
155-
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@ import type {
1010
TransactionContext,
1111
} from '@sentry/types';
1212

13-
import { addBreadcrumb, endSession, startSession } from '@sentry/core';
1413
import {
15-
captureEvent,
16-
getClient,
17-
getCurrentScope,
14+
addBreadcrumb,
15+
endSession,
1816
setContext,
1917
setExtra,
2018
setExtras,
2119
setTag,
2220
setTags,
2321
setUser,
24-
withScope,
25-
} from './api';
22+
startSession,
23+
} from '@sentry/core';
24+
import { captureEvent, getClient, getCurrentScope, withScope } from './api';
2625
import { callExtensionMethod, getGlobalCarrier } from './globals';
2726
import { getIsolationScope } from './scope';
2827
import type { SentryCarrier } from './types';

0 commit comments

Comments
 (0)