Skip to content

Commit 9ca911b

Browse files
authored
ref(types): Move SeverityLevel and SeverityLevels to @sentry/utils (#4492)
This includes three changes: - It moves the type `SeverityLevel` and the const string array `SeverityLevels` from `@sentry/types` to `@sentry/utils`, in order that only types get exported from `@sentry/types`. Since every package other than `@sentry/types` depends on `@sentry/utils`, they're still accessible to any package which needs them. - It changes all of our uses of `SeverityLevel` and `SeverityLevels` so that they point to the copies in `@sentry/utils` rather than those in `@sentry/types`. - It adds a corresponding entry to the migration guide. The copies of `SeverityLevel` and `SeverityLevels` in `@sentry/types` remain, for backwards compatibility, but can be removed in v7.
1 parent b6a6142 commit 9ca911b

File tree

11 files changed

+44
-11
lines changed

11 files changed

+44
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

7+
This release deprecates the `Severity` enum, the `SeverityLevel` type, and the internal `SeverityLevels` array, all from `@sentry/types`. In v7, `Severity` will disappear (in favor of `SeverityLevel`) and `SeverityLevel` and `SeverityLevels` will live in `@sentry/utils`. If you are using any of the three, we encourage you to migrate your usage now, using our [migration guide](./MIGRATION.md#upgrading-from-6.x-to-6.17.x).
8+
79
## 6.17.4
810

911
- chore(deps): Bump `@sentry/webpack-plugin` from 1.18.3 to 1.18.4 (#4464)
@@ -37,7 +39,7 @@ Work in this release contributed by @datbth. Thank you for your contribution!
3739

3840
## 6.17.0
3941

40-
This release contains several internal refactors that help reduce the bundle size of the SDK and help prep for our [upcoming major release](https://github.com/getsentry/sentry-javascript/issues/4240). There are no breaking changes in this patch unless you are using our internal `Dsn` class, which has been removed. We also deprecated a few of our typescript enums and our internal `API` class. We've detailed in our [migration documentation](./MIGRATION.md#upgrading-from-6.x-to-6.17.0) how to update your sdk usage if you are using any of these in your code.
42+
This release contains several internal refactors that help reduce the bundle size of the SDK and help prep for our [upcoming major release](https://github.com/getsentry/sentry-javascript/issues/4240). There are no breaking changes in this patch unless you are using our internal `Dsn` class, which has been removed. We also deprecated a few of our typescript enums and our internal `API` class. We've detailed in our [migration documentation](./MIGRATION.md#upgrading-from-6.x-to-6.17.x) how to update your sdk usage if you are using any of these in your code.
4143

4244
- feat: Remove Dsn class (#4325)
4345
- feat(core): Add processing metadata to scope and event (#4252)

MIGRATION.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Upgrading from 6.x to 6.17.0
1+
# Upgrading from 6.x to 6.17.x
22

3-
You only need to make changes when migrating to `6.17.0` if you are using our internal `Dsn` class. Our internal API class and typescript enums were deprecated, so we recommend you migrate them as well.
3+
You only need to make changes when migrating to `6.17.x` if you are using our internal `Dsn` class. Our internal API class and typescript enums were deprecated, so we recommend you migrate them as well.
44

55
The internal `Dsn` class was removed in `6.17.0`. For additional details, you can look at the [PR where this change happened](https://github.com/getsentry/sentry-javascript/pull/4325). To migrate, see the following example.
66

@@ -44,7 +44,7 @@ const envelopeEndpoint = api.getEnvelopeEndpointWithUrlEncodedAuth();
4444

4545
## Enum changes
4646

47-
The enums `Status` and `SpanStatus` were deprecated, and we've detailed how to migrate away from them below. We also deprecated the `TransactionMethod`, `Outcome` and `RequestSessionStatus` enums, but those are internal-only APIs. If you are using them, we encourage you to take a look at the corresponding PRs to see how we've changed our code as a result.
47+
The enums `Status`, `SpanStatus`, and `Severity` were deprecated, and we've detailed how to migrate away from them below. We also deprecated the `TransactionMethod`, `Outcome` and `RequestSessionStatus` enums, but those are internal-only APIs. If you are using them, we encourage you to take a look at the corresponding PRs to see how we've changed our code as a result.
4848

4949
- `TransactionMethod`: https://github.com/getsentry/sentry-javascript/pull/4314
5050
- `Outcome`: https://github.com/getsentry/sentry-javascript/pull/4315
@@ -82,6 +82,27 @@ import { SpanStatus } from '@sentry/tracing';
8282
const status = SpanStatus.fromHttpCode(403);
8383
```
8484

85+
#### Severity, SeverityLevel, and SeverityLevels
86+
87+
We deprecated the `Severity` enum in `@sentry/types` and it will be removed in the next major release. We recommend using string literals (typed as `SeverityLevel`) to save on bundle size.
88+
89+
`SeverityLevel` and `SeverityLevels` will continue to exist in v7, but they will live in `@sentry/utils` rather than `@sentry/types`. Currently, they live in both, for ease of migration. (`SeverityLevels` isn't included in the examples below because it is only useful internally.)
90+
91+
```js
92+
// New in 6.17.5:
93+
import { SeverityLevel } from '@sentry/utils';
94+
95+
const levelA = "error" as SeverityLevel;
96+
97+
const levelB: SeverityLevel = "error"
98+
99+
// Before:
100+
import { Severity, SeverityLevel } from '@sentry/types';
101+
102+
const levelA = Severity.error;
103+
104+
const levelB: SeverityLevel = "error"
105+
85106
# Upgrading from 4.x to 5.x/6.x
86107

87108
In this version upgrade, there are a few breaking changes. This guide should help you update your code accordingly.

packages/browser/src/exports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ export {
99
Exception,
1010
Response,
1111
Severity,
12-
SeverityLevel,
1312
StackFrame,
1413
Stacktrace,
1514
Thread,
1615
User,
1716
} from '@sentry/types';
1817

18+
export { SeverityLevel } from '@sentry/utils';
19+
1920
export {
2021
addGlobalEventProcessor,
2122
addBreadcrumb,

packages/node/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ export {
99
Exception,
1010
Response,
1111
Severity,
12-
SeverityLevel,
1312
StackFrame,
1413
Stacktrace,
1514
Thread,
1615
User,
1716
} from '@sentry/types';
1817

18+
export { SeverityLevel } from '@sentry/utils';
19+
1920
export {
2021
addGlobalEventProcessor,
2122
addBreadcrumb,

packages/tracing/src/index.bundle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ export {
77
Exception,
88
Response,
99
Severity,
10-
SeverityLevel,
1110
StackFrame,
1211
Stacktrace,
1312
Thread,
1413
User,
1514
} from '@sentry/types';
1615

16+
export { SeverityLevel } from '@sentry/utils';
17+
1718
export {
1819
addGlobalEventProcessor,
1920
addBreadcrumb,

packages/types/src/severity.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ export enum Severity {
1818
Critical = 'critical',
1919
}
2020

21+
// TODO: in v7, these can disappear, because they now also exist in `@sentry/utils`. (Having them there rather than here
22+
// is nice because then it enforces the idea that only types are exported from `@sentry/types`.)
2123
export const SeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug', 'critical'] as const;
2224
export type SeverityLevel = typeof SeverityLevels[number];

packages/utils/src/enums.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const SeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug', 'critical'] as const;
2+
export type SeverityLevel = typeof SeverityLevels[number];

packages/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './async';
22
export * from './browser';
33
export * from './dsn';
4+
export * from './enums';
45
export * from './error';
56
export * from './global';
67
export * from './instrument';

packages/utils/src/severity.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Severity, SeverityLevel, SeverityLevels } from '@sentry/types';
1+
import { Severity } from '@sentry/types';
2+
3+
import { SeverityLevel, SeverityLevels } from './enums';
24

35
function isSupportedSeverity(level: string): level is Severity {
46
return SeverityLevels.indexOf(level as SeverityLevel) !== -1;

packages/utils/test/severity.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { SeverityLevels } from '@sentry/types';
2-
1+
import { SeverityLevels } from '../src/enums';
32
import { severityFromString } from '../src/severity';
43

54
describe('severityFromString()', () => {

packages/vue/src/index.bundle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ export {
66
EventStatus,
77
Exception,
88
Response,
9-
SeverityLevel,
109
StackFrame,
1110
Stacktrace,
1211
Thread,
1312
User,
1413
} from '@sentry/types';
1514

15+
export { SeverityLevel } from '@sentry/utils';
16+
1617
export {
1718
BrowserClient,
1819
BrowserOptions,

0 commit comments

Comments
 (0)