Skip to content

Commit

Permalink
feat(core): Deprecate configureScope
Browse files Browse the repository at this point in the history
Instead, users should directly access the current scope via `getCurrentScope()`.
  • Loading branch information
mydea committed Dec 18, 2023
1 parent 35906d0 commit a2670a3
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 8 deletions.
8 changes: 8 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ npx @sentry/migr8@latest

This will let you select which updates to run, and automatically update your code. Make sure to still review all code changes!

## Deprecate `configureScope` in favor of using `getCurrentScope()`

Instead of updating the scope in a callback via `configureScope()`, you should access it via `getCurrentScope()` and configure it directly:

```js
Sentry.getCurrentScope().setTag('xx', 'yy');
```

## Deprecate `addGlobalEventProcessor` in favor of `addEventProcessor`

Instead of using `addGlobalEventProcessor`, you should use `addEventProcessor` which does not add the event processor globally, but to the current client.
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export {
captureMessage,
captureCheckIn,
withMonitor,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
// eslint-disable-next-line deprecation/deprecation
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export {
captureEvent,
captureMessage,
close,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
flush,
Expand Down
1 change: 1 addition & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export {
captureEvent,
captureMessage,
close,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
// eslint-disable-next-line deprecation/deprecation
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ export function captureEvent(event: Event, hint?: EventHint): ReturnType<Hub['ca
/**
* Callback to set context information onto the scope.
* @param callback Callback function that receives Scope.
*
* @deprecated Use getCurrentScope() directly.
*/
export function configureScope(callback: (scope: Scope) => void): ReturnType<Hub['configureScope']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().configureScope(callback);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ export class Hub implements HubInterface {

/**
* @inheritDoc
*
* @deprecated Use `getScope()` directly.
*/
public configureScope(callback: (scope: Scope) => void): void {
const { scope, client } = this.getStackTop();
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
captureEvent,
captureMessage,
close,
// eslint-disable-next-line deprecation/deprecation
configureScope,
flush,
lastEventId,
Expand Down
1 change: 1 addition & 0 deletions packages/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export {
captureEvent,
captureMessage,
close,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
// eslint-disable-next-line deprecation/deprecation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Envelope, EnvelopeItem, Event } from '@sentry/types';
import { parseEnvelope } from '@sentry/utils';
import * as fs from 'fs';
import * as http from 'http';
import * as https from 'https';
Expand All @@ -8,6 +6,8 @@ import * as os from 'os';
import * as path from 'path';
import * as util from 'util';
import * as zlib from 'zlib';
import type { Envelope, EnvelopeItem, Event } from '@sentry/types';
import { parseEnvelope } from '@sentry/utils';

const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from '@playwright/test';
import { expect, test } from '@playwright/test';
import axios, { AxiosError, AxiosResponse } from 'axios';
import { waitForError, waitForTransaction } from '../event-proxy-server';

Expand Down
1 change: 1 addition & 0 deletions packages/hub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const captureMessage = captureMessageCore;
/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
// eslint-disable-next-line deprecation/deprecation
export const configureScope = configureScopeCore;

/**
Expand Down
1 change: 1 addition & 0 deletions packages/node-experimental/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export {
captureEvent,
captureMessage,
close,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
// eslint-disable-next-line deprecation/deprecation
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export {
captureEvent,
captureMessage,
close,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
// eslint-disable-next-line deprecation/deprecation
Expand Down
8 changes: 3 additions & 5 deletions packages/node/src/integrations/hapi/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
SDK_VERSION,
captureException,
configureScope,
continueTrace,
getActiveTransaction,
SDK_VERSION,
getCurrentScope,
startTransaction,
} from '@sentry/core';
import type { Integration } from '@sentry/types';
Expand Down Expand Up @@ -80,9 +80,7 @@ export const hapiTracingPlugin = {
},
);

configureScope(scope => {
scope.setSpan(transaction);
});
getCurrentScope().setSpan(transaction);

return h.continue;
});
Expand Down
1 change: 1 addition & 0 deletions packages/remix/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export {
captureException,
captureEvent,
captureMessage,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
// eslint-disable-next-line deprecation/deprecation
Expand Down
1 change: 1 addition & 0 deletions packages/serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export {
captureMessage,
captureCheckIn,
withMonitor,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
getActiveTransaction,
Expand Down
1 change: 1 addition & 0 deletions packages/sveltekit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
captureMessage,
captureCheckIn,
withMonitor,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
// eslint-disable-next-line deprecation/deprecation
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export interface Hub {
* Callback to set context information onto the scope.
*
* @param callback Callback function that receives Scope.
* @deprecated Use `getScope()` directly.
*/
configureScope(callback: (scope: Scope) => void): void;

Expand Down
1 change: 1 addition & 0 deletions packages/vercel-edge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export {
captureEvent,
captureMessage,
close,
// eslint-disable-next-line deprecation/deprecation
configureScope,
createTransport,
// eslint-disable-next-line deprecation/deprecation
Expand Down

0 comments on commit a2670a3

Please sign in to comment.