Skip to content

feat(core): Make setXXX methods set on isolation scope #10678

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 1 commit into from
Feb 15, 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
18 changes: 6 additions & 12 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,15 @@ export function captureEvent(event: Event, hint?: EventHint): string {
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function setContext(name: string, context: { [key: string]: any } | null): ReturnType<Hub['setContext']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().setContext(name, context);
getIsolationScope().setContext(name, context);
}

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

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

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

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

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

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/node-experimental/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ export {
captureException,
captureEvent,
captureMessage,
addEventProcessor,
setContext,
setExtra,
setExtras,
setTag,
setTags,
setUser,
withScope,
withIsolationScope,
withActiveSpan,
Expand Down Expand Up @@ -84,6 +77,13 @@ export {
functionToStringIntegration,
inboundFiltersIntegration,
linkedErrorsIntegration,
addEventProcessor,
setContext,
setExtra,
setExtras,
setTag,
setTags,
setUser,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
Expand Down
54 changes: 1 addition & 53 deletions packages/node-experimental/src/sdk/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@

import type { Span } from '@opentelemetry/api';
import { context, trace } from '@opentelemetry/api';
import type {
CaptureContext,
Event,
EventHint,
EventProcessor,
Extra,
Extras,
Primitive,
Scope,
SeverityLevel,
User,
} from '@sentry/types';
import type { CaptureContext, Event, EventHint, Scope, SeverityLevel } from '@sentry/types';
import { getContextFromScope, getScopesFromContext, setScopesOnContext } from '../utils/contextData';

import type { ExclusiveEventHintOrCaptureContext } from '../utils/prepareEvent';
Expand Down Expand Up @@ -112,44 +101,3 @@ export function captureMessage(message: string, captureContext?: CaptureContext
export function captureEvent(event: Event, hint?: EventHint): string {
return getCurrentScope().captureEvent(event, hint);
}

/**
* Add an event processor to the current isolation scope.
*/
export function addEventProcessor(eventProcessor: EventProcessor): void {
getIsolationScope().addEventProcessor(eventProcessor);
}

/** Set the user for the current isolation scope. */
export function setUser(user: User | null): void {
getIsolationScope().setUser(user);
}

/** Set tags for the current isolation scope. */
export function setTags(tags: { [key: string]: Primitive }): void {
getIsolationScope().setTags(tags);
}

/** Set a single tag user for the current isolation scope. */
export function setTag(key: string, value: Primitive): void {
getIsolationScope().setTag(key, value);
}

/** Set extra data for the current isolation scope. */
export function setExtra(key: string, extra: Extra): void {
getIsolationScope().setExtra(key, extra);
}

/** Set multiple extra data for the current isolation scope. */
export function setExtras(extras: Extras): void {
getIsolationScope().setExtras(extras);
}

/** Set context data for the current isolation scope. */
export function setContext(
name: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context: { [key: string]: any } | null,
): void {
getIsolationScope().setContext(name, context);
}
11 changes: 5 additions & 6 deletions packages/node-experimental/src/sdk/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import type {
TransactionContext,
} from '@sentry/types';

import { addBreadcrumb, endSession, startSession } from '@sentry/core';
import {
captureEvent,
getClient,
getCurrentScope,
addBreadcrumb,
endSession,
setContext,
setExtra,
setExtras,
setTag,
setTags,
setUser,
withScope,
} from './api';
startSession,
} from '@sentry/core';
import { captureEvent, getClient, getCurrentScope, withScope } from './api';
import { callExtensionMethod, getGlobalCarrier } from './globals';
import { getIsolationScope } from './scope';
import type { SentryCarrier } from './types';
Expand Down