Skip to content

Commit b7251cc

Browse files
authored
feat: Delete @sentry/minimal (#4971)
Remove the minimal package and `callOnHub`. Instead, call hub methods directly. This gives static typing and bundle size improvements.
1 parent d53180e commit b7251cc

29 files changed

+169
-347
lines changed

CHANGELOG.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@
2020

2121
## 7.0.0-alpha.0
2222

23-
- **breaking** feat: Drop support for Node 6 (#4851)
24-
- **breaking** feat: Remove references to @sentry/apm (#4845)
25-
- **breaking** feat: Delete deprecated startSpan and child methods (#4849)
26-
- **breaking** feat(bundles): Stop publishing CDN bundles on npm (#4901)
27-
- **breaking** ref(build): Rename dist directories to cjs (#4900)
28-
- **breaking** ref(build): Update to TypeScript 3.8.3 (#4895)
29-
- **breaking** feat(browser): Remove top level eventbuilder exports (#4887)
30-
- **breaking** feat(core): Delete API class (#4848)
31-
- **breaking** feat(core): Remove whitelistUrls/blacklistUrls (#4850)
32-
- **breaking** feat(gatsby): Remove Sentry from window (#4857)
33-
- **breaking** feat(hub): Remove getActiveDomain (#4858)
34-
- **breaking** feat(hub): Remove setTransaction scope method (#4865)
35-
- **breaking** feat(integrations): Remove old angular, ember, and vue integrations (#4893)
36-
- **breaking** feat(node): Remove deprecated frameContextLines (#4884)
37-
- **breaking** feat(tracing): Rename registerRequestInstrumentation -> instrumentOutgoingRequests (#4859)
38-
- **breaking** feat(types): Remove deprecated user dsn field (#4864)
39-
- **breaking** feat(types): Delete RequestSessionStatus enum (#4889)
40-
- **breaking** feat(types): Delete Status enum (#4891)
41-
- **breaking** feat(types): Delete SessionStatus enum (#4890)
42-
-
23+
- **(breaking)** feat: Drop support for Node 6 (#4851)
24+
- **(breaking)** feat: Remove references to @sentry/apm (#4845)
25+
- **(breaking)** feat: Delete deprecated startSpan and child methods (#4849)
26+
- **(breaking)** feat(bundles): Stop publishing CDN bundles on npm (#4901)
27+
- **(breaking)** ref(build): Rename dist directories to cjs (#4900)
28+
- **(breaking)** ref(build): Update to TypeScript 3.8.3 (#4895)
29+
- **(breaking)** feat(browser): Remove top level eventbuilder exports (#4887)
30+
- **(breaking)** feat(core): Delete API class (#4848)
31+
- **(breaking)** feat(core): Remove whitelistUrls/blacklistUrls (#4850)
32+
- **(breaking)** feat(gatsby): Remove Sentry from window (#4857)
33+
- **(breaking)** feat(hub): Remove getActiveDomain (#4858)
34+
- **(breaking)** feat(hub): Remove setTransaction scope method (#4865)
35+
- **(breaking)** feat(integrations): Remove old angular, ember, and vue integrations (#4893)
36+
- **(breaking)** feat(node): Remove deprecated frameContextLines (#4884)
37+
- **(breaking)** feat(tracing): Rename registerRequestInstrumentation -> instrumentOutgoingRequests (#4859)
38+
- **(breaking)** feat(types): Remove deprecated user dsn field (#4864)
39+
- **(breaking)** feat(types): Delete RequestSessionStatus enum (#4889)
40+
- **(breaking)** feat(types): Delete Status enum (#4891)
41+
- **(breaking)** feat(types): Delete SessionStatus enum (#4890)
42+
4343
## 6.19.7
4444

4545
- fix(react): Add children prop type to ErrorBoundary component (#4966)

MIGRATION.md

+22
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ Node.js version 6 has reached end of life in April 2019. For Sentry JavaScript S
1010
As far as SDK development goes, dropping support means no longer running integration tests for Node.js version 6, and also no longer handling edge cases specific to version 6.
1111
Running the new SDK version on Node.js v6 is therefore highly discouraged.
1212

13+
## Removal of `@sentry/minimal`
14+
15+
The `@sentry/minimal` package was deleted and it's functionality was moved to `@sentry/hub`. All exports from `@sentry/minimal` should be avaliable in `@sentry/hub` other than `_callOnClient` function which was removed.
16+
17+
```ts
18+
// New in v7:
19+
import {
20+
addBreadcrumb,
21+
captureException,
22+
configureScope,
23+
setTag,
24+
} from '@sentry/hub';
25+
26+
// Before:
27+
import {
28+
addBreadcrumb,
29+
captureException,
30+
configureScope,
31+
setTag,
32+
} from '@sentry/minimal';
33+
```
34+
1335
## Removal Of Old Platform Integrations From `@sentry/integrations` Package
1436

1537
The following classes will be removed from the `@sentry/integrations` package and can no longer be used:

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ below:
104104
extensions for Performance Monitoring / Tracing
105105
- [`@sentry/hub`](https://github.com/getsentry/sentry-javascript/tree/master/packages/hub): Global state management of
106106
SDKs
107-
- [`@sentry/minimal`](https://github.com/getsentry/sentry-javascript/tree/master/packages/minimal): Minimal SDK for
108-
library authors to add Sentry support
109107
- [`@sentry/core`](https://github.com/getsentry/sentry-javascript/tree/master/packages/core): The base for all
110108
JavaScript SDKs with interfaces, type definitions and base classes.
111109
- [`@sentry/utils`](https://github.com/getsentry/sentry-javascript/tree/master/packages/utils): A set of helpers and

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"packages/hub",
4141
"packages/integration-tests",
4242
"packages/integrations",
43-
"packages/minimal",
4443
"packages/nextjs",
4544
"packages/node",
4645
"packages/node-integration-tests",

packages/core/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
},
1818
"dependencies": {
1919
"@sentry/hub": "7.0.0-alpha.1",
20-
"@sentry/minimal": "7.0.0-alpha.1",
2120
"@sentry/types": "7.0.0-alpha.1",
2221
"@sentry/utils": "7.0.0-alpha.1",
2322
"tslib": "^1.9.3"

packages/core/src/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ export {
1515
setTags,
1616
setUser,
1717
withScope,
18-
} from '@sentry/minimal';
19-
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, makeMain, Scope, Session } from '@sentry/hub';
18+
addGlobalEventProcessor,
19+
getCurrentHub,
20+
getHubFromCarrier,
21+
Hub,
22+
makeMain,
23+
Scope,
24+
Session,
25+
} from '@sentry/hub';
2026
export {
2127
getEnvelopeEndpointWithUrlEncodedAuth,
2228
getStoreEndpointWithUrlEncodedAuth,

packages/core/test/mocks/integration.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getCurrentHub } from '@sentry/hub';
2-
import { configureScope } from '@sentry/minimal';
1+
import { configureScope, getCurrentHub } from '@sentry/hub';
32
import { Event, EventProcessor, Integration } from '@sentry/types';
43

54
export class TestIntegration implements Integration {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getCurrentHub, Hub, Scope } from '@sentry/hub';
21
import {
32
Breadcrumb,
43
CaptureContext,
@@ -9,25 +8,19 @@ import {
98
Primitive,
109
Severity,
1110
SeverityLevel,
12-
Transaction,
1311
TransactionContext,
1412
User,
1513
} from '@sentry/types';
1614

17-
/**
18-
* This calls a function on the current hub.
19-
* @param method function to call on hub.
20-
* @param args to pass to function.
21-
*/
22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
function callOnHub<T>(method: string, ...args: any[]): T {
24-
const hub = getCurrentHub();
25-
if (hub && hub[method as keyof Hub]) {
26-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
27-
return (hub[method as keyof Hub] as any)(...args);
28-
}
29-
throw new Error(`No hub defined or ${method} was not found on the hub, please open a bug report.`);
30-
}
15+
import { getCurrentHub, Hub } from './hub';
16+
import { Scope } from './scope';
17+
18+
// Note: All functions in this file are typed with a return value of `ReturnType<Hub[HUB_FUNCTION]>`,
19+
// where HUB_FUNCTION is some method on the Hub class.
20+
//
21+
// This is done to make sure the top level SDK methods stay in sync with the hub methods.
22+
// Although every method here has an explicit return type, some of them (that map to void returns) do not
23+
// contain `return` keywords. This is done to save on bundle size, as `return` is not minifiable.
3124

3225
/**
3326
* Captures an exception event and sends it to Sentry.
@@ -36,14 +29,8 @@ function callOnHub<T>(method: string, ...args: any[]): T {
3629
* @returns The generated eventId.
3730
*/
3831
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
39-
export function captureException(exception: any, captureContext?: CaptureContext): string {
40-
const syntheticException = new Error('Sentry syntheticException');
41-
42-
return callOnHub('captureException', exception, {
43-
captureContext,
44-
originalException: exception,
45-
syntheticException,
46-
});
32+
export function captureException(exception: any, captureContext?: CaptureContext): ReturnType<Hub['captureException']> {
33+
return getCurrentHub().captureException(exception, { captureContext });
4734
}
4835

4936
/**
@@ -57,19 +44,12 @@ export function captureMessage(
5744
message: string,
5845
// eslint-disable-next-line deprecation/deprecation
5946
captureContext?: CaptureContext | Severity | SeverityLevel,
60-
): string {
61-
const syntheticException = new Error(message);
62-
47+
): ReturnType<Hub['captureMessage']> {
6348
// This is necessary to provide explicit scopes upgrade, without changing the original
6449
// arity of the `captureMessage(message, level)` method.
6550
const level = typeof captureContext === 'string' ? captureContext : undefined;
6651
const context = typeof captureContext !== 'string' ? { captureContext } : undefined;
67-
68-
return callOnHub('captureMessage', message, level, {
69-
originalException: message,
70-
syntheticException,
71-
...context,
72-
});
52+
return getCurrentHub().captureMessage(message, level, context);
7353
}
7454

7555
/**
@@ -78,16 +58,16 @@ export function captureMessage(
7858
* @param event The event to send to Sentry.
7959
* @returns The generated eventId.
8060
*/
81-
export function captureEvent(event: Event): string {
82-
return callOnHub('captureEvent', event);
61+
export function captureEvent(event: Event): ReturnType<Hub['captureEvent']> {
62+
return getCurrentHub().captureEvent(event);
8363
}
8464

8565
/**
8666
* Callback to set context information onto the scope.
8767
* @param callback Callback function that receives Scope.
8868
*/
89-
export function configureScope(callback: (scope: Scope) => void): void {
90-
callOnHub<void>('configureScope', callback);
69+
export function configureScope(callback: (scope: Scope) => void): ReturnType<Hub['configureScope']> {
70+
getCurrentHub().configureScope(callback);
9171
}
9272

9373
/**
@@ -98,8 +78,8 @@ export function configureScope(callback: (scope: Scope) => void): void {
9878
*
9979
* @param breadcrumb The breadcrumb to record.
10080
*/
101-
export function addBreadcrumb(breadcrumb: Breadcrumb): void {
102-
callOnHub<void>('addBreadcrumb', breadcrumb);
81+
export function addBreadcrumb(breadcrumb: Breadcrumb): ReturnType<Hub['addBreadcrumb']> {
82+
getCurrentHub().addBreadcrumb(breadcrumb);
10383
}
10484

10585
/**
@@ -108,33 +88,33 @@ export function addBreadcrumb(breadcrumb: Breadcrumb): void {
10888
* @param context Any kind of data. This data will be normalized.
10989
*/
11090
// eslint-disable-next-line @typescript-eslint/no-explicit-any
111-
export function setContext(name: string, context: { [key: string]: any } | null): void {
112-
callOnHub<void>('setContext', name, context);
91+
export function setContext(name: string, context: { [key: string]: any } | null): ReturnType<Hub['setContext']> {
92+
getCurrentHub().setContext(name, context);
11393
}
11494

11595
/**
11696
* Set an object that will be merged sent as extra data with the event.
11797
* @param extras Extras object to merge into current context.
11898
*/
119-
export function setExtras(extras: Extras): void {
120-
callOnHub<void>('setExtras', extras);
99+
export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
100+
getCurrentHub().setExtras(extras);
121101
}
122102

123103
/**
124-
* Set an object that will be merged sent as tags data with the event.
125-
* @param tags Tags context object to merge into current context.
104+
* Set key:value that will be sent as extra data with the event.
105+
* @param key String of extra
106+
* @param extra Any kind of data. This data will be normalized.
126107
*/
127-
export function setTags(tags: { [key: string]: Primitive }): void {
128-
callOnHub<void>('setTags', tags);
108+
export function setExtra(key: string, extra: Extra): ReturnType<Hub['setExtra']> {
109+
getCurrentHub().setExtra(key, extra);
129110
}
130111

131112
/**
132-
* Set key:value that will be sent as extra data with the event.
133-
* @param key String of extra
134-
* @param extra Any kind of data. This data will be normalized.
113+
* Set an object that will be merged sent as tags data with the event.
114+
* @param tags Tags context object to merge into current context.
135115
*/
136-
export function setExtra(key: string, extra: Extra): void {
137-
callOnHub<void>('setExtra', key, extra);
116+
export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['setTags']> {
117+
getCurrentHub().setTags(tags);
138118
}
139119

140120
/**
@@ -145,17 +125,17 @@ export function setExtra(key: string, extra: Extra): void {
145125
* @param key String key of tag
146126
* @param value Value of tag
147127
*/
148-
export function setTag(key: string, value: Primitive): void {
149-
callOnHub<void>('setTag', key, value);
128+
export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']> {
129+
getCurrentHub().setTag(key, value);
150130
}
151131

152132
/**
153133
* Updates user context information for future events.
154134
*
155135
* @param user User context object to be set in the current context. Pass `null` to unset the user.
156136
*/
157-
export function setUser(user: User | null): void {
158-
callOnHub<void>('setUser', user);
137+
export function setUser(user: User | null): ReturnType<Hub['setUser']> {
138+
getCurrentHub().setUser(user);
159139
}
160140

161141
/**
@@ -171,23 +151,8 @@ export function setUser(user: User | null): void {
171151
*
172152
* @param callback that will be enclosed into push/popScope.
173153
*/
174-
export function withScope(callback: (scope: Scope) => void): void {
175-
callOnHub<void>('withScope', callback);
176-
}
177-
178-
/**
179-
* Calls a function on the latest client. Use this with caution, it's meant as
180-
* in "internal" helper so we don't need to expose every possible function in
181-
* the shim. It is not guaranteed that the client actually implements the
182-
* function.
183-
*
184-
* @param method The method to call on the client/client.
185-
* @param args Arguments to pass to the client/fontend.
186-
* @hidden
187-
*/
188-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
189-
export function _callOnClient(method: string, ...args: any[]): void {
190-
callOnHub<void>('_invokeClient', method, ...args);
154+
export function withScope(callback: (scope: Scope) => void): ReturnType<Hub['withScope']> {
155+
getCurrentHub().withScope(callback);
191156
}
192157

193158
/**
@@ -210,6 +175,6 @@ export function _callOnClient(method: string, ...args: any[]): void {
210175
export function startTransaction(
211176
context: TransactionContext,
212177
customSamplingContext?: CustomSamplingContext,
213-
): Transaction {
214-
return callOnHub('startTransaction', { ...context }, customSamplingContext);
178+
): ReturnType<Hub['startTransaction']> {
179+
return getCurrentHub().startTransaction({ ...context }, customSamplingContext);
215180
}

0 commit comments

Comments
 (0)