Skip to content

Commit 9e862ab

Browse files
committed
ref: Move public interfaces to @sentry/types package (#1889)
* fix: Events created from exception shouldnt have top-level message attribute (#1831) * Use SyncPromise internally & Remove deprecated API & Trim Public API (#1858) * ref: Move PromiseBuffer and Error to utils package * ref: Remove all async api * ref: Remove invokeClientAsync function * feat: Finish Node SDK * feat: SyncPromise implementation * fix: Browser SDK * fix: beforeSend callback * fix: Core tests * fix: linting and tests * fix: browser npm package + add error for manual tests * meta: Remove deprecations * fix: Typedocs and public exposed functions * meta: Changelog * Apply suggestions from code review * ref: Move public interfaces to types package * fix: Tests * fix: Small type issues * ref: Remove scope listeners * fix: Add flush to interface * ref: Remove interfaces from core
1 parent 2dab59e commit 9e862ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1038
-1180
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ since we removed some methods from the public API and removed some classes from
1010

1111
- **breaking** [node] fix: Events created from exception shouldn't have top-level message attribute
1212
- [utils] ref: Update wrap method to hide internal sentry flags
13-
- [utils] fix: Make internal Sentry flags non-enumerable in fill util
13+
- [utils] fix: Make internal Sentry flags non-enumerable in fill utils
1414
- [utils] ref: Move `SentryError` + `PromiseBuffer` to utils
1515
- **breaking** [core] ref: Use `SyncPromise` internally, this reduces memory pressure by a lot.
1616
- **breaking** [browser] ref: Removed `BrowserBackend` from default export.

packages/browser/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default [
6666
interop: false,
6767
sourcemap: true,
6868
},
69-
external: ['@sentry/core', '@sentry/hub', '@sentry/minimal'],
69+
external: ['@sentry/core', '@sentry/hub', '@sentry/minimal', 'tslib'],
7070
plugins: [
7171
typescript({
7272
tsconfig: 'tsconfig.build.json',

packages/browser/src/backend.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { BaseBackend, Options } from '@sentry/core';
2-
import { SentryEvent, SentryEventHint, Severity, Transport } from '@sentry/types';
1+
import { BaseBackend } from '@sentry/core';
2+
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
33
import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is';
44
import { supportsBeacon, supportsFetch } from '@sentry/utils/supports';
55
import { SyncPromise } from '@sentry/utils/syncpromise';
@@ -56,8 +56,8 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
5656
/**
5757
* @inheritDoc
5858
*/
59-
public eventFromException(exception: any, hint?: SentryEventHint): SyncPromise<SentryEvent> {
60-
let event: SentryEvent;
59+
public eventFromException(exception: any, hint?: EventHint): SyncPromise<Event> {
60+
let event: Event;
6161

6262
if (isErrorEvent(exception as ErrorEvent) && (exception as ErrorEvent).error) {
6363
// If it is an ErrorEvent with `error` property, extract it to get actual Error
@@ -108,7 +108,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
108108
/**
109109
* This is an internal helper function that creates an event.
110110
*/
111-
private buildEvent(event: SentryEvent, hint?: SentryEventHint): SentryEvent {
111+
private buildEvent(event: Event, hint?: EventHint): Event {
112112
return {
113113
...event,
114114
event_id: hint && hint.event_id,
@@ -125,12 +125,8 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
125125
/**
126126
* @inheritDoc
127127
*/
128-
public eventFromMessage(
129-
message: string,
130-
level: Severity = Severity.Info,
131-
hint?: SentryEventHint,
132-
): SyncPromise<SentryEvent> {
133-
const event: SentryEvent = {
128+
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): SyncPromise<Event> {
129+
const event: Event = {
134130
event_id: hint && hint.event_id,
135131
level,
136132
message,

packages/browser/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { API, BaseClient, Scope } from '@sentry/core';
2-
import { DsnLike, SentryEvent, SentryEventHint } from '@sentry/types';
2+
import { DsnLike, Event, EventHint } from '@sentry/types';
33
import { logger } from '@sentry/utils/logger';
44
import { getGlobalObject } from '@sentry/utils/misc';
55
import { SyncPromise } from '@sentry/utils/syncpromise';
@@ -50,7 +50,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
5050
/**
5151
* @inheritDoc
5252
*/
53-
protected prepareEvent(event: SentryEvent, scope?: Scope, hint?: SentryEventHint): SyncPromise<SentryEvent | null> {
53+
protected prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {
5454
event.platform = event.platform || 'javascript';
5555
event.sdk = {
5656
...event.sdk,

packages/browser/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ export {
22
Breadcrumb,
33
Request,
44
SdkInfo,
5-
SentryEvent,
6-
SentryException,
7-
SentryResponse,
5+
Event,
6+
Exception,
7+
Response,
88
Severity,
99
StackFrame,
1010
Stacktrace,

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { API, getCurrentHub } from '@sentry/core';
2-
import { Breadcrumb, Integration, SentryBreadcrumbHint, Severity } from '@sentry/types';
2+
import { Breadcrumb, BreadcrumbHint, Integration, Severity } from '@sentry/types';
33
import { isFunction, isString } from '@sentry/utils/is';
44
import { logger } from '@sentry/utils/logger';
55
import { getEventDescription, getGlobalObject, parseUrl } from '@sentry/utils/misc';
@@ -454,9 +454,9 @@ export class Breadcrumbs implements Integration {
454454
/**
455455
* Helper that checks if integration is enabled on the client.
456456
* @param breadcrumb Breadcrumb
457-
* @param hint SentryBreadcrumbHint
457+
* @param hint BreadcrumbHint
458458
*/
459-
public static addBreadcrumb(breadcrumb: Breadcrumb, hint?: SentryBreadcrumbHint): void {
459+
public static addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void {
460460
if (getCurrentHub().getIntegration(Breadcrumbs)) {
461461
getCurrentHub().addBreadcrumb(breadcrumb, hint);
462462
}

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getCurrentHub } from '@sentry/core';
2-
import { Integration, SentryEvent } from '@sentry/types';
2+
import { Event, Integration } from '@sentry/types';
33
import { logger } from '@sentry/utils/logger';
44
import { safeNormalize, serialize } from '@sentry/utils/object';
55
import { truncate } from '@sentry/utils/string';
@@ -83,11 +83,11 @@ export class GlobalHandlers implements Integration {
8383
}
8484

8585
/**
86-
* This function creates an SentryEvent from an TraceKitStackTrace.
86+
* This function creates an Event from an TraceKitStackTrace.
8787
*
88-
* @param stacktrace TraceKitStackTrace to be converted to an SentryEvent.
88+
* @param stacktrace TraceKitStackTrace to be converted to an Event.
8989
*/
90-
private eventFromGlobalHandler(stacktrace: TraceKitStackTrace): SentryEvent {
90+
private eventFromGlobalHandler(stacktrace: TraceKitStackTrace): Event {
9191
const event = eventFromStacktrace(stacktrace);
9292

9393
const data: { [key: string]: string } = {
@@ -102,7 +102,7 @@ export class GlobalHandlers implements Integration {
102102
data.name = stacktrace.name;
103103
}
104104

105-
const newEvent: SentryEvent = {
105+
const newEvent: Event = {
106106
...event,
107107
exception: {
108108
...event.exception,

packages/browser/src/integrations/helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { captureException, getCurrentHub, withScope } from '@sentry/core';
2-
import { Mechanism, SentryEvent, SentryWrappedFunction } from '@sentry/types';
2+
import { Event as SentryEvent, Mechanism, WrappedFunction } from '@sentry/types';
33
import { isFunction } from '@sentry/utils/is';
44
import { htmlTreeAsString } from '@sentry/utils/misc';
55
import { safeNormalize } from '@sentry/utils/object';
@@ -36,11 +36,11 @@ export function ignoreNextOnError(): void {
3636
* @hidden
3737
*/
3838
export function wrap(
39-
fn: SentryWrappedFunction,
39+
fn: WrappedFunction,
4040
options: {
4141
mechanism?: Mechanism;
4242
} = {},
43-
before?: SentryWrappedFunction,
43+
before?: WrappedFunction,
4444
): any {
4545
if (!isFunction(fn)) {
4646
return fn;
@@ -63,7 +63,7 @@ export function wrap(
6363
return fn;
6464
}
6565

66-
const sentryWrapped: SentryWrappedFunction = function(this: any): void {
66+
const sentryWrapped: WrappedFunction = function(this: any): void {
6767
if (before && isFunction(before)) {
6868
before.apply(this, arguments);
6969
}

packages/browser/src/integrations/linkederrors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
2-
import { Integration, SentryEvent, SentryEventHint, SentryException } from '@sentry/types';
2+
import { Event, EventHint, Exception, Integration } from '@sentry/types';
33
import { exceptionFromStacktrace } from '../parsers';
44
import { computeStackTrace } from '../tracekit';
55

@@ -47,7 +47,7 @@ export class LinkedErrors implements Integration {
4747
* @inheritDoc
4848
*/
4949
public setupOnce(): void {
50-
addGlobalEventProcessor((event: SentryEvent, hint?: SentryEventHint) => {
50+
addGlobalEventProcessor((event: Event, hint?: EventHint) => {
5151
const self = getCurrentHub().getIntegration(LinkedErrors);
5252
if (self) {
5353
return self.handler(event, hint);
@@ -59,7 +59,7 @@ export class LinkedErrors implements Integration {
5959
/**
6060
* @inheritDoc
6161
*/
62-
public handler(event: SentryEvent, hint?: SentryEventHint): SentryEvent | null {
62+
public handler(event: Event, hint?: EventHint): Event | null {
6363
if (!event.exception || !event.exception.values || !hint || !(hint.originalException instanceof Error)) {
6464
return event;
6565
}
@@ -71,7 +71,7 @@ export class LinkedErrors implements Integration {
7171
/**
7272
* @inheritDoc
7373
*/
74-
public walkErrorTree(error: ExtendedError, key: string, stack: SentryException[] = []): SentryException[] {
74+
public walkErrorTree(error: ExtendedError, key: string, stack: Exception[] = []): Exception[] {
7575
if (!(error[key] instanceof Error) || stack.length + 1 >= this.limit) {
7676
return stack;
7777
}

packages/browser/src/integrations/pluggable/ember.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { captureException, captureMessage, getCurrentHub, Scope, withScope } from '@sentry/core';
2-
import { Integration, SentryEvent } from '@sentry/types';
2+
import { Event, Integration } from '@sentry/types';
33
import { logger } from '@sentry/utils/logger';
44
import { getGlobalObject } from '@sentry/utils/misc';
55

@@ -81,7 +81,7 @@ export class Ember implements Integration {
8181
* @param scope The scope currently used.
8282
*/
8383
private addIntegrationToSdkInfo(scope: Scope): void {
84-
scope.addEventProcessor((event: SentryEvent) => {
84+
scope.addEventProcessor((event: Event) => {
8585
if (event.sdk) {
8686
const integrations = event.sdk.integrations || [];
8787
event.sdk = {

packages/browser/src/integrations/pluggable/vue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { captureException, getCurrentHub, withScope } from '@sentry/core';
2-
import { Integration, SentryEvent } from '@sentry/types';
2+
import { Event, Integration } from '@sentry/types';
33
import { isPlainObject, isUndefined } from '@sentry/utils/is';
44
import { logger } from '@sentry/utils/logger';
55
import { getGlobalObject } from '@sentry/utils/misc';
@@ -92,7 +92,7 @@ export class Vue implements Integration {
9292
scope.setExtra(key, metadata[key]);
9393
});
9494

95-
scope.addEventProcessor((event: SentryEvent) => {
95+
scope.addEventProcessor((event: Event) => {
9696
if (event.sdk) {
9797
const integrations = event.sdk.integrations || [];
9898
event.sdk = {

packages/browser/src/integrations/trycatch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Integration, SentryWrappedFunction } from '@sentry/types';
1+
import { Integration, WrappedFunction } from '@sentry/types';
22
import { getGlobalObject } from '@sentry/utils/misc';
33
import { fill } from '@sentry/utils/object';
44
import { breadcrumbEventHandler, keypressEventHandler, wrap } from './helpers';
@@ -124,7 +124,7 @@ export class TryCatch implements Integration {
124124
this,
125125
eventName,
126126
wrap(
127-
(fn as any) as SentryWrappedFunction,
127+
(fn as any) as WrappedFunction,
128128
{
129129
mechanism: {
130130
data: {
@@ -152,7 +152,7 @@ export class TryCatch implements Integration {
152152
fn: EventListenerObject,
153153
options?: boolean | EventListenerOptions,
154154
): () => void {
155-
let callback = (fn as any) as SentryWrappedFunction;
155+
let callback = (fn as any) as WrappedFunction;
156156
try {
157157
callback = callback && (callback.__sentry_wrapped__ || callback);
158158
} catch (e) {

packages/browser/src/integrations/useragent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
2-
import { Integration, SentryEvent } from '@sentry/types';
2+
import { Event, Integration } from '@sentry/types';
33
import { getGlobalObject } from '@sentry/utils/misc';
44

55
const global = getGlobalObject() as Window;
@@ -20,7 +20,7 @@ export class UserAgent implements Integration {
2020
* @inheritDoc
2121
*/
2222
public setupOnce(): void {
23-
addGlobalEventProcessor((event: SentryEvent) => {
23+
addGlobalEventProcessor((event: Event) => {
2424
if (getCurrentHub().getIntegration(UserAgent)) {
2525
if (!global.navigator || !global.location) {
2626
return event;

packages/browser/src/parsers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SentryEvent, SentryException, StackFrame } from '@sentry/types';
1+
import { Event, Exception, StackFrame } from '@sentry/types';
22
import { limitObjectDepthToSize, serializeKeysToEventMessage } from '@sentry/utils/object';
33
import { includes } from '@sentry/utils/string';
44
import { md5 } from './md5';
@@ -11,10 +11,10 @@ const STACKTRACE_LIMIT = 50;
1111
* @param stacktrace TraceKitStackTrace that will be converted to an exception
1212
* @hidden
1313
*/
14-
export function exceptionFromStacktrace(stacktrace: TraceKitStackTrace): SentryException {
14+
export function exceptionFromStacktrace(stacktrace: TraceKitStackTrace): Exception {
1515
const frames = prepareFramesForEvent(stacktrace.stack);
1616

17-
const exception: SentryException = {
17+
const exception: Exception = {
1818
type: stacktrace.name,
1919
value: stacktrace.message,
2020
};
@@ -34,9 +34,9 @@ export function exceptionFromStacktrace(stacktrace: TraceKitStackTrace): SentryE
3434
/**
3535
* @hidden
3636
*/
37-
export function eventFromPlainObject(exception: {}, syntheticException: Error | null): SentryEvent {
37+
export function eventFromPlainObject(exception: {}, syntheticException: Error | null): Event {
3838
const exceptionKeys = Object.keys(exception).sort();
39-
const event: SentryEvent = {
39+
const event: Event = {
4040
extra: {
4141
__serialized__: limitObjectDepthToSize(exception),
4242
},
@@ -58,7 +58,7 @@ export function eventFromPlainObject(exception: {}, syntheticException: Error |
5858
/**
5959
* @hidden
6060
*/
61-
export function eventFromStacktrace(stacktrace: TraceKitStackTrace): SentryEvent {
61+
export function eventFromStacktrace(stacktrace: TraceKitStackTrace): Event {
6262
const exception = exceptionFromStacktrace(stacktrace);
6363

6464
return {
@@ -113,7 +113,7 @@ export function prepareFramesForEvent(stack: TraceKitStackFrame[]): StackFrame[]
113113
* @param type Type of the exception.
114114
* @hidden
115115
*/
116-
export function addExceptionTypeValue(event: SentryEvent, value?: string, type?: string): void {
116+
export function addExceptionTypeValue(event: Event, value?: string, type?: string): void {
117117
event.exception = event.exception || {};
118118
event.exception.values = event.exception.values || [];
119119
event.exception.values[0] = event.exception.values[0] || {};

packages/browser/src/transports/base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { API } from '@sentry/core';
2-
import { SentryResponse, Transport, TransportOptions } from '@sentry/types';
2+
import { Response, Transport, TransportOptions } from '@sentry/types';
33
import { SentryError } from '@sentry/utils/error';
44
import { PromiseBuffer } from '@sentry/utils/promisebuffer';
55

@@ -11,7 +11,7 @@ export abstract class BaseTransport implements Transport {
1111
public url: string;
1212

1313
/** A simple buffer holding all requests. */
14-
protected readonly buffer: PromiseBuffer<SentryResponse> = new PromiseBuffer(30);
14+
protected readonly buffer: PromiseBuffer<Response> = new PromiseBuffer(30);
1515

1616
public constructor(public options: TransportOptions) {
1717
this.url = new API(this.options.dsn).getStoreEndpointWithUrlEncodedAuth();
@@ -20,7 +20,7 @@ export abstract class BaseTransport implements Transport {
2020
/**
2121
* @inheritDoc
2222
*/
23-
public async sendEvent(_: string): Promise<SentryResponse> {
23+
public async sendEvent(_: string): Promise<Response> {
2424
throw new SentryError('Transport Class has to implement `sendEvent` method');
2525
}
2626

packages/browser/src/transports/beacon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SentryResponse, Status } from '@sentry/types';
1+
import { Response, Status } from '@sentry/types';
22
import { getGlobalObject } from '@sentry/utils/misc';
33
import { BaseTransport } from './base';
44

@@ -9,7 +9,7 @@ export class BeaconTransport extends BaseTransport {
99
/**
1010
* @inheritDoc
1111
*/
12-
public async sendEvent(body: string): Promise<SentryResponse> {
12+
public async sendEvent(body: string): Promise<Response> {
1313
const result = global.navigator.sendBeacon(this.url, body);
1414

1515
return this.buffer.add(

packages/browser/src/transports/fetch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SentryResponse, Status } from '@sentry/types';
1+
import { Response, Status } from '@sentry/types';
22
import { getGlobalObject } from '@sentry/utils/misc';
33
import { supportsReferrerPolicy } from '@sentry/utils/supports';
44
import { BaseTransport } from './base';
@@ -10,7 +10,7 @@ export class FetchTransport extends BaseTransport {
1010
/**
1111
* @inheritDoc
1212
*/
13-
public async sendEvent(body: string): Promise<SentryResponse> {
13+
public async sendEvent(body: string): Promise<Response> {
1414
const defaultOptions: RequestInit = {
1515
body,
1616
method: 'POST',

packages/browser/src/transports/xhr.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { SentryResponse, Status } from '@sentry/types';
1+
import { Response, Status } from '@sentry/types';
22
import { BaseTransport } from './base';
33

44
/** `XHR` based transport */
55
export class XHRTransport extends BaseTransport {
66
/**
77
* @inheritDoc
88
*/
9-
public async sendEvent(body: string): Promise<SentryResponse> {
9+
public async sendEvent(body: string): Promise<Response> {
1010
return this.buffer.add(
11-
new Promise<SentryResponse>((resolve, reject) => {
11+
new Promise<Response>((resolve, reject) => {
1212
const request = new XMLHttpRequest();
1313

1414
request.onreadystatechange = () => {

0 commit comments

Comments
 (0)