Skip to content

[WIP] ref: Move public interfaces to types package #1889

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 8 commits into from
Feb 18, 2019
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ since we removed some methods from the public API and removed some classes from

- **breaking** [node] fix: Events created from exception shouldn't have top-level message attribute
- [utils] ref: Update wrap method to hide internal sentry flags
- [utils] fix: Make internal Sentry flags non-enumerable in fill util
- [utils] fix: Make internal Sentry flags non-enumerable in fill utils
- [utils] ref: Move `SentryError` + `PromiseBuffer` to utils
- **breaking** [core] ref: Use `SyncPromise` internally, this reduces memory pressure by a lot.
- **breaking** [browser] ref: Removed `BrowserBackend` from default export.
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default [
interop: false,
sourcemap: true,
},
external: ['@sentry/core', '@sentry/hub', '@sentry/minimal'],
external: ['@sentry/core', '@sentry/hub', '@sentry/minimal', 'tslib'],
plugins: [
typescript({
tsconfig: 'tsconfig.build.json',
Expand Down
18 changes: 7 additions & 11 deletions packages/browser/src/backend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseBackend, Options } from '@sentry/core';
import { SentryEvent, SentryEventHint, Severity, Transport } from '@sentry/types';
import { BaseBackend } from '@sentry/core';
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is';
import { supportsBeacon, supportsFetch } from '@sentry/utils/supports';
import { SyncPromise } from '@sentry/utils/syncpromise';
Expand Down Expand Up @@ -56,8 +56,8 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
/**
* @inheritDoc
*/
public eventFromException(exception: any, hint?: SentryEventHint): SyncPromise<SentryEvent> {
let event: SentryEvent;
public eventFromException(exception: any, hint?: EventHint): SyncPromise<Event> {
let event: Event;

if (isErrorEvent(exception as ErrorEvent) && (exception as ErrorEvent).error) {
// If it is an ErrorEvent with `error` property, extract it to get actual Error
Expand Down Expand Up @@ -108,7 +108,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
/**
* This is an internal helper function that creates an event.
*/
private buildEvent(event: SentryEvent, hint?: SentryEventHint): SentryEvent {
private buildEvent(event: Event, hint?: EventHint): Event {
return {
...event,
event_id: hint && hint.event_id,
Expand All @@ -125,12 +125,8 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
/**
* @inheritDoc
*/
public eventFromMessage(
message: string,
level: Severity = Severity.Info,
hint?: SentryEventHint,
): SyncPromise<SentryEvent> {
const event: SentryEvent = {
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): SyncPromise<Event> {
const event: Event = {
event_id: hint && hint.event_id,
level,
message,
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { API, BaseClient, Scope } from '@sentry/core';
import { DsnLike, SentryEvent, SentryEventHint } from '@sentry/types';
import { DsnLike, Event, EventHint } from '@sentry/types';
import { SentryError } from '@sentry/utils/error';
import { getGlobalObject } from '@sentry/utils/misc';
import { SyncPromise } from '@sentry/utils/syncpromise';
Expand Down Expand Up @@ -50,7 +50,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
/**
* @inheritDoc
*/
protected prepareEvent(event: SentryEvent, scope?: Scope, hint?: SentryEventHint): SyncPromise<SentryEvent | null> {
protected prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {
event.platform = event.platform || 'javascript';
event.sdk = {
...event.sdk,
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export {
Breadcrumb,
Request,
SdkInfo,
SentryEvent,
SentryException,
SentryResponse,
Event,
Exception,
Response,
Severity,
StackFrame,
Stacktrace,
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { API, getCurrentHub } from '@sentry/core';
import { Breadcrumb, Integration, SentryBreadcrumbHint, Severity } from '@sentry/types';
import { Breadcrumb, BreadcrumbHint, Integration, Severity } from '@sentry/types';
import { isFunction, isString } from '@sentry/utils/is';
import { logger } from '@sentry/utils/logger';
import { getEventDescription, getGlobalObject, parseUrl } from '@sentry/utils/misc';
Expand Down Expand Up @@ -454,9 +454,9 @@ export class Breadcrumbs implements Integration {
/**
* Helper that checks if integration is enabled on the client.
* @param breadcrumb Breadcrumb
* @param hint SentryBreadcrumbHint
* @param hint BreadcrumbHint
*/
public static addBreadcrumb(breadcrumb: Breadcrumb, hint?: SentryBreadcrumbHint): void {
public static addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void {
if (getCurrentHub().getIntegration(Breadcrumbs)) {
getCurrentHub().addBreadcrumb(breadcrumb, hint);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentHub } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { Event, Integration } from '@sentry/types';
import { logger } from '@sentry/utils/logger';
import { safeNormalize, serialize } from '@sentry/utils/object';
import { truncate } from '@sentry/utils/string';
Expand Down Expand Up @@ -83,11 +83,11 @@ export class GlobalHandlers implements Integration {
}

/**
* This function creates an SentryEvent from an TraceKitStackTrace.
* This function creates an Event from an TraceKitStackTrace.
*
* @param stacktrace TraceKitStackTrace to be converted to an SentryEvent.
* @param stacktrace TraceKitStackTrace to be converted to an Event.
*/
private eventFromGlobalHandler(stacktrace: TraceKitStackTrace): SentryEvent {
private eventFromGlobalHandler(stacktrace: TraceKitStackTrace): Event {
const event = eventFromStacktrace(stacktrace);

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

const newEvent: SentryEvent = {
const newEvent: Event = {
...event,
exception: {
...event.exception,
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/src/integrations/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { captureException, getCurrentHub, withScope } from '@sentry/core';
import { Mechanism, SentryEvent, SentryWrappedFunction } from '@sentry/types';
import { Event as SentryEvent, Mechanism, WrappedFunction } from '@sentry/types';
import { isFunction } from '@sentry/utils/is';
import { htmlTreeAsString } from '@sentry/utils/misc';
import { serializeObject } from '@sentry/utils/object';
Expand Down Expand Up @@ -36,11 +36,11 @@ export function ignoreNextOnError(): void {
* @hidden
*/
export function wrap(
fn: SentryWrappedFunction,
fn: WrappedFunction,
options: {
mechanism?: Mechanism;
} = {},
before?: SentryWrappedFunction,
before?: WrappedFunction,
): any {
if (!isFunction(fn)) {
return fn;
Expand All @@ -63,7 +63,7 @@ export function wrap(
return fn;
}

const sentryWrapped: SentryWrappedFunction = function(this: any): void {
const sentryWrapped: WrappedFunction = function(this: any): void {
if (before && isFunction(before)) {
before.apply(this, arguments);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
import { Integration, SentryEvent, SentryEventHint, SentryException } from '@sentry/types';
import { Event, EventHint, Exception, Integration } from '@sentry/types';
import { exceptionFromStacktrace } from '../parsers';
import { computeStackTrace } from '../tracekit';

Expand Down Expand Up @@ -47,7 +47,7 @@ export class LinkedErrors implements Integration {
* @inheritDoc
*/
public setupOnce(): void {
addGlobalEventProcessor((event: SentryEvent, hint?: SentryEventHint) => {
addGlobalEventProcessor((event: Event, hint?: EventHint) => {
const self = getCurrentHub().getIntegration(LinkedErrors);
if (self) {
return self.handler(event, hint);
Expand All @@ -59,7 +59,7 @@ export class LinkedErrors implements Integration {
/**
* @inheritDoc
*/
public handler(event: SentryEvent, hint?: SentryEventHint): SentryEvent | null {
public handler(event: Event, hint?: EventHint): Event | null {
if (!event.exception || !event.exception.values || !hint || !(hint.originalException instanceof Error)) {
return event;
}
Expand All @@ -71,7 +71,7 @@ export class LinkedErrors implements Integration {
/**
* @inheritDoc
*/
public walkErrorTree(error: ExtendedError, key: string, stack: SentryException[] = []): SentryException[] {
public walkErrorTree(error: ExtendedError, key: string, stack: Exception[] = []): Exception[] {
if (!(error[key] instanceof Error) || stack.length + 1 >= this.limit) {
return stack;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/pluggable/ember.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { captureException, captureMessage, getCurrentHub, Scope, withScope } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { Event, Integration } from '@sentry/types';
import { logger } from '@sentry/utils/logger';
import { getGlobalObject } from '@sentry/utils/misc';

Expand Down Expand Up @@ -81,7 +81,7 @@ export class Ember implements Integration {
* @param scope The scope currently used.
*/
private addIntegrationToSdkInfo(scope: Scope): void {
scope.addEventProcessor((event: SentryEvent) => {
scope.addEventProcessor((event: Event) => {
if (event.sdk) {
const integrations = event.sdk.integrations || [];
event.sdk = {
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/pluggable/vue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { captureException, getCurrentHub, withScope } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { Event, Integration } from '@sentry/types';
import { isPlainObject, isUndefined } from '@sentry/utils/is';
import { logger } from '@sentry/utils/logger';
import { getGlobalObject } from '@sentry/utils/misc';
Expand Down Expand Up @@ -92,7 +92,7 @@ export class Vue implements Integration {
scope.setExtra(key, metadata[key]);
});

scope.addEventProcessor((event: SentryEvent) => {
scope.addEventProcessor((event: Event) => {
if (event.sdk) {
const integrations = event.sdk.integrations || [];
event.sdk = {
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/integrations/trycatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Integration, SentryWrappedFunction } from '@sentry/types';
import { Integration, WrappedFunction } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils/misc';
import { fill } from '@sentry/utils/object';
import { breadcrumbEventHandler, keypressEventHandler, wrap } from './helpers';
Expand Down Expand Up @@ -124,7 +124,7 @@ export class TryCatch implements Integration {
this,
eventName,
wrap(
(fn as any) as SentryWrappedFunction,
(fn as any) as WrappedFunction,
{
mechanism: {
data: {
Expand Down Expand Up @@ -152,7 +152,7 @@ export class TryCatch implements Integration {
fn: EventListenerObject,
options?: boolean | EventListenerOptions,
): () => void {
let callback = (fn as any) as SentryWrappedFunction;
let callback = (fn as any) as WrappedFunction;
try {
callback = callback && (callback.__sentry_wrapped__ || callback);
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/useragent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { Event, Integration } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils/misc';

const global = getGlobalObject() as Window;
Expand All @@ -20,7 +20,7 @@ export class UserAgent implements Integration {
* @inheritDoc
*/
public setupOnce(): void {
addGlobalEventProcessor((event: SentryEvent) => {
addGlobalEventProcessor((event: Event) => {
if (getCurrentHub().getIntegration(UserAgent)) {
if (!global.navigator || !global.location) {
return event;
Expand Down
14 changes: 7 additions & 7 deletions packages/browser/src/parsers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SentryEvent, SentryException, StackFrame } from '@sentry/types';
import { Event, Exception, StackFrame } from '@sentry/types';
import { limitObjectDepthToSize, serializeKeysToEventMessage } from '@sentry/utils/object';
import { includes } from '@sentry/utils/string';
import { md5 } from './md5';
Expand All @@ -11,10 +11,10 @@ const STACKTRACE_LIMIT = 50;
* @param stacktrace TraceKitStackTrace that will be converted to an exception
* @hidden
*/
export function exceptionFromStacktrace(stacktrace: TraceKitStackTrace): SentryException {
export function exceptionFromStacktrace(stacktrace: TraceKitStackTrace): Exception {
const frames = prepareFramesForEvent(stacktrace.stack);

const exception: SentryException = {
const exception: Exception = {
type: stacktrace.name,
value: stacktrace.message,
};
Expand All @@ -34,9 +34,9 @@ export function exceptionFromStacktrace(stacktrace: TraceKitStackTrace): SentryE
/**
* @hidden
*/
export function eventFromPlainObject(exception: {}, syntheticException: Error | null): SentryEvent {
export function eventFromPlainObject(exception: {}, syntheticException: Error | null): Event {
const exceptionKeys = Object.keys(exception).sort();
const event: SentryEvent = {
const event: Event = {
extra: {
__serialized__: limitObjectDepthToSize(exception),
},
Expand All @@ -58,7 +58,7 @@ export function eventFromPlainObject(exception: {}, syntheticException: Error |
/**
* @hidden
*/
export function eventFromStacktrace(stacktrace: TraceKitStackTrace): SentryEvent {
export function eventFromStacktrace(stacktrace: TraceKitStackTrace): Event {
const exception = exceptionFromStacktrace(stacktrace);

return {
Expand Down Expand Up @@ -113,7 +113,7 @@ export function prepareFramesForEvent(stack: TraceKitStackFrame[]): StackFrame[]
* @param type Type of the exception.
* @hidden
*/
export function addExceptionTypeValue(event: SentryEvent, value?: string, type?: string): void {
export function addExceptionTypeValue(event: Event, value?: string, type?: string): void {
event.exception = event.exception || {};
event.exception.values = event.exception.values || [];
event.exception.values[0] = event.exception.values[0] || {};
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/transports/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { API } from '@sentry/core';
import { SentryResponse, Transport, TransportOptions } from '@sentry/types';
import { Response, Transport, TransportOptions } from '@sentry/types';
import { SentryError } from '@sentry/utils/error';
import { PromiseBuffer } from '@sentry/utils/promisebuffer';

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/transports/beacon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SentryResponse, Status } from '@sentry/types';
import { Response, Status } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils/misc';
import { BaseTransport } from './base';

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

return this.buffer.add(
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/transports/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SentryResponse, Status } from '@sentry/types';
import { Response, Status } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils/misc';
import { supportsReferrerPolicy } from '@sentry/utils/supports';
import { BaseTransport } from './base';
Expand All @@ -10,7 +10,7 @@ export class FetchTransport extends BaseTransport {
/**
* @inheritDoc
*/
public async sendEvent(body: string): Promise<SentryResponse> {
public async sendEvent(body: string): Promise<Response> {
const defaultOptions: RequestInit = {
body,
method: 'POST',
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/transports/xhr.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SentryResponse, Status } from '@sentry/types';
import { Response, Status } from '@sentry/types';
import { BaseTransport } from './base';

/** `XHR` based transport */
export class XHRTransport extends BaseTransport {
/**
* @inheritDoc
*/
public async sendEvent(body: string): Promise<SentryResponse> {
public async sendEvent(body: string): Promise<Response> {
return this.buffer.add(
new Promise<SentryResponse>((resolve, reject) => {
new Promise<Response>((resolve, reject) => {
const request = new XMLHttpRequest();

request.onreadystatechange = () => {
Expand Down
Loading