Skip to content

fix: Remove beacon transport #1953

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 1 commit into from
Mar 22, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 4.6.5

- [browser] fix: Remove beacon transport.

## 4.6.4

- [utils] fix: Prevent decycling from referencing original objects
Expand Down
6 changes: 2 additions & 4 deletions packages/browser/src/backend.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BaseBackend, Options, SentryError } from '@sentry/core';
import { SentryEvent, SentryEventHint, Severity, Transport } from '@sentry/types';
import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is';
import { supportsBeacon, supportsFetch } from '@sentry/utils/supports';
import { supportsFetch } from '@sentry/utils/supports';
import { addExceptionTypeValue, eventFromPlainObject, eventFromStacktrace, prepareFramesForEvent } from './parsers';
import { computeStackTrace } from './tracekit';
import { BeaconTransport, FetchTransport, XHRTransport } from './transports';
import { FetchTransport, XHRTransport } from './transports';

/**
* Configuration options for the Sentry Browser SDK.
Expand Down Expand Up @@ -58,8 +58,6 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {

if (this.options.transport) {
return new this.options.transport(transportOptions);
} else if (supportsBeacon()) {
return new BeaconTransport(transportOptions);
} else if (supportsFetch()) {
return new FetchTransport(transportOptions);
}
Expand Down
57 changes: 1 addition & 56 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { logger } from '@sentry/utils/logger';
import { getEventDescription, getGlobalObject, parseUrl } from '@sentry/utils/misc';
import { deserialize, fill, safeNormalize } from '@sentry/utils/object';
import { includes, safeJoin } from '@sentry/utils/string';
import { supportsBeacon, supportsHistory, supportsNativeFetch } from '@sentry/utils/supports';
import { supportsHistory, supportsNativeFetch } from '@sentry/utils/supports';
import { BrowserClient } from '../client';
import { breadcrumbEventHandler, keypressEventHandler, wrap } from './helpers';

Expand All @@ -24,7 +24,6 @@ export interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {

/** JSDoc */
interface BreadcrumbIntegrations {
beacon?: boolean;
console?: boolean;
dom?: boolean;
fetch?: boolean;
Expand Down Expand Up @@ -53,7 +52,6 @@ export class Breadcrumbs implements Integration {
*/
public constructor(options?: BreadcrumbIntegrations) {
this.options = {
beacon: true,
console: true,
dom: true,
fetch: true,
Expand All @@ -64,56 +62,6 @@ export class Breadcrumbs implements Integration {
};
}

/** JSDoc */
private instrumentBeacon(): void {
if (!supportsBeacon()) {
return;
}

/** JSDoc */
function beaconReplacementFunction(originalBeaconFunction: () => void): () => void {
return function(this: History, ...args: any[]): void {
const url = args[0];
const data = args[1];
// If the browser successfully queues the request for delivery, the method returns "true" and returns "false" otherwise.
// https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API/Using_the_Beacon_API
const result = originalBeaconFunction.apply(this, args);

const client = getCurrentHub().getClient() as BrowserClient;
const dsn = client && client.getDsn();
if (dsn) {
const filterUrl = new API(dsn).getStoreEndpoint();
// if Sentry key appears in URL, don't capture it as a request
// but rather as our own 'sentry' type breadcrumb
if (filterUrl && includes(url, filterUrl)) {
addSentryBreadcrumb(data);
return result;
}
}

// What is wrong with you TypeScript...
const breadcrumbData = ({
category: 'beacon',
data,
type: 'http',
} as any) as { [key: string]: any };

if (!result) {
breadcrumbData.level = Severity.Error;
}

Breadcrumbs.addBreadcrumb(breadcrumbData, {
input: args,
result,
});

return result;
};
}

fill(global.navigator, 'sendBeacon', beaconReplacementFunction);
}

/** JSDoc */
private instrumentConsole(): void {
if (!('console' in global)) {
Expand Down Expand Up @@ -481,9 +429,6 @@ export class Breadcrumbs implements Integration {
if (this.options.fetch) {
this.instrumentFetch();
}
if (this.options.beacon) {
this.instrumentBeacon();
}
if (this.options.history) {
this.instrumentHistory();
}
Expand Down
21 changes: 0 additions & 21 deletions packages/browser/src/transports/beacon.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/browser/src/transports/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { BaseTransport } from './base';
export { FetchTransport } from './fetch';
export { XHRTransport } from './xhr';
export { BeaconTransport } from './beacon';
53 changes: 0 additions & 53 deletions packages/browser/test/transports/beacon.test.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/utils/src/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ export function supportsNativeFetch(): boolean {
return fetch.toString().indexOf('native') !== -1;
}

/**
* Tells whether current environment supports sendBeacon API
* {@link supportsBeacon}.
*
* @returns Answer to the given question.
*/
export function supportsBeacon(): boolean {
const global = getGlobalObject();
return 'navigator' in global && 'sendBeacon' in global.navigator;
}

/**
* Tells whether current environment supports ReportingObserver API
* {@link supportsReportingObserver}.
Expand Down
35 changes: 0 additions & 35 deletions packages/utils/test/supports.test.ts

This file was deleted.