@bugsnag/browser-performance
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -6,3 +6,3 @@ class NetworkRequestPlugin { | ||
this.xhrTracker = xhrTracker; | ||
this.ignoredUrls = []; | ||
this.configEndpoint = ''; | ||
this.trackRequest = (startContext) => { | ||
@@ -25,3 +25,3 @@ if (!this.shouldTrackRequest(startContext)) | ||
if (configuration.autoInstrumentNetworkRequests) { | ||
this.ignoredUrls = configuration.networkInstrumentationIgnoreUrls.map((url) => typeof url === 'string' ? RegExp(url) : url).concat(RegExp(configuration.endpoint)); | ||
this.configEndpoint = configuration.endpoint; | ||
this.xhrTracker.onStart(this.trackRequest); | ||
@@ -32,3 +32,3 @@ this.fetchTracker.onStart(this.trackRequest); | ||
shouldTrackRequest(startContext) { | ||
return !this.ignoredUrls.some(url => url.test(startContext.url)); | ||
return startContext.url !== this.configEndpoint; | ||
} | ||
@@ -35,0 +35,0 @@ } |
function getHttpVersion(protocol) { | ||
switch (protocol) { | ||
case '': | ||
return undefined; | ||
case 'http/1.0': | ||
@@ -52,3 +54,6 @@ return '1.0'; | ||
span.setAttribute('http.url', entry.name); | ||
span.setAttribute('http.flavor', getHttpVersion(entry.nextHopProtocol)); | ||
const httpFlavor = getHttpVersion(entry.nextHopProtocol); | ||
if (httpFlavor) { | ||
span.setAttribute('http.flavor', httpFlavor); | ||
} | ||
if (entry.encodedBodySize && entry.decodedBodySize) { | ||
@@ -55,0 +60,0 @@ span.setAttribute('http.response_content_length', entry.encodedBodySize); |
import { validateSpanOptions, isString, coreSpanOptionSchema } from '@bugsnag/core-performance'; | ||
import getAbsoluteUrl from '../request-tracker/url-helpers.js'; | ||
@@ -10,7 +9,2 @@ // exclude isFirstClass from the route change option schema | ||
makeCurrentContext, | ||
route: { | ||
getDefaultValue: (value) => String(value), | ||
message: 'should be a string', | ||
validate: isString | ||
}, | ||
trigger: { | ||
@@ -32,14 +26,32 @@ getDefaultValue: (value) => String(value), | ||
let previousRoute = configuration.routingProvider.resolveRoute(new URL(this.location.href)); | ||
configuration.routingProvider.listenForRouteChanges((route, trigger, options) => { | ||
configuration.routingProvider.listenForRouteChanges((url, trigger, options) => { | ||
let absoluteUrl; | ||
if (url instanceof URL) { | ||
absoluteUrl = url; | ||
} | ||
else { | ||
try { | ||
const stringUrl = String(url); | ||
absoluteUrl = new URL(stringUrl); | ||
} | ||
catch (err) { | ||
configuration.logger.warn('Invalid span options\n - url should be a URL'); | ||
return { | ||
id: '', | ||
traceId: '', | ||
isValid: () => false, | ||
end: () => { } | ||
}; | ||
} | ||
} | ||
// create internal options for validation | ||
const routeChangeSpanOptions = Object.assign(Object.assign({}, options), { route, | ||
trigger }); | ||
const routeChangeSpanOptions = Object.assign(Object.assign({}, options), { trigger }); | ||
const cleanOptions = validateSpanOptions('[RouteChange]', routeChangeSpanOptions, routeChangeSpanOptionSchema, configuration.logger); | ||
const route = configuration.routingProvider.resolveRoute(absoluteUrl); | ||
// update the span name using the validated route | ||
cleanOptions.name += cleanOptions.options.route; | ||
cleanOptions.name += route; | ||
const span = this.spanFactory.startSpan(cleanOptions.name, cleanOptions.options); | ||
const url = getAbsoluteUrl(cleanOptions.options.route, this.document.baseURI); | ||
span.setAttribute('bugsnag.span.category', 'route_change'); | ||
span.setAttribute('bugsnag.browser.page.route', route); | ||
span.setAttribute('bugsnag.browser.page.url', url); | ||
span.setAttribute('bugsnag.browser.page.url', url.toString()); | ||
span.setAttribute('bugsnag.browser.page.previous_route', previousRoute); | ||
@@ -46,0 +58,0 @@ span.setAttribute('bugsnag.browser.page.route_change.trigger', cleanOptions.options.trigger); |
@@ -35,3 +35,3 @@ import { createClient } from '@bugsnag/core-performance'; | ||
spanAttributesSource, | ||
deliveryFactory: createBrowserDeliveryFactory(window.fetch, backgroundingListener), | ||
deliveryFactory: createBrowserDeliveryFactory(window.fetch, backgroundingListener, clock), | ||
idGenerator, | ||
@@ -38,0 +38,0 @@ schema: createSchema(window.location.hostname, new DefaultRoutingProvider()), |
@@ -21,2 +21,3 @@ import { millisecondsToNanoseconds } from '@bugsnag/core-performance'; | ||
now: () => performance.now(), | ||
date: () => new Date(calculatedTimeOrigin + performance.now()), | ||
convert: (date) => date.getTime() - calculatedTimeOrigin, | ||
@@ -23,0 +24,0 @@ // convert milliseconds since timeOrigin to full timestamp |
@@ -29,6 +29,2 @@ import { schema, isBoolean, isStringOrRegExpArray } from '@bugsnag/core-performance'; | ||
validate: isStringOrRegExpArray | ||
}, networkInstrumentationIgnoreUrls: { | ||
defaultValue: [], | ||
message: 'should be an array of string|RegExp', | ||
validate: isStringOrRegExpArray | ||
} }); | ||
@@ -35,0 +31,0 @@ } |
@@ -10,6 +10,5 @@ import getAbsoluteUrl from './request-tracker/url-helpers.js'; | ||
listenForRouteChanges(startRouteChangeSpan) { | ||
addEventListener('popstate', () => { | ||
addEventListener('popstate', (ev) => { | ||
const url = new URL(location.href); | ||
const route = this.resolveRoute(url); | ||
const span = startRouteChangeSpan(route, 'popstate'); | ||
const span = startRouteChangeSpan(url, 'popstate'); | ||
onSettle((endTime) => { | ||
@@ -19,3 +18,2 @@ span.end(endTime); | ||
}); | ||
const resolveRoute = this.resolveRoute; | ||
const originalPushState = history.pushState; | ||
@@ -26,4 +24,3 @@ history.pushState = function (...args) { | ||
const absoluteURL = new URL(getAbsoluteUrl(url.toString(), document.baseURI)); | ||
const route = resolveRoute(absoluteURL); | ||
const span = startRouteChangeSpan(route, 'pushState'); | ||
const span = startRouteChangeSpan(absoluteURL, 'pushState'); | ||
onSettle((endTime) => { | ||
@@ -30,0 +27,0 @@ span.end(endTime); |
@@ -14,3 +14,3 @@ import { responseStateFromStatusCode } from '@bugsnag/core-performance'; | ||
} | ||
function createBrowserDeliveryFactory(fetch, backgroundingListener) { | ||
function createBrowserDeliveryFactory(fetch, backgroundingListener, clock) { | ||
// we set fetch's 'keepalive' flag if the app is backgrounded/terminated so | ||
@@ -27,3 +27,3 @@ // that we can flush the last batch - without 'keepalive' the browser can | ||
async send(payload) { | ||
payload.headers['Bugsnag-Sent-At'] = (new Date()).toISOString(); | ||
payload.headers['Bugsnag-Sent-At'] = clock.date().toISOString(); | ||
try { | ||
@@ -30,0 +30,0 @@ const response = await fetch(endpoint, { |
@@ -8,3 +8,3 @@ import cuid from '@bugsnag/cuid'; | ||
return function resourceAttributesSource(config) { | ||
const attributes = new ResourceAttributes(config.releaseStage, config.appVersion, 'bugsnag.performance.browser', '0.2.0'); | ||
const attributes = new ResourceAttributes(config.releaseStage, config.appVersion, 'bugsnag.performance.browser', '0.3.0'); | ||
attributes.set('browser.user_agent', navigator.userAgent); | ||
@@ -11,0 +11,0 @@ // chromium only |
@@ -8,3 +8,3 @@ import { type RequestTracker } from '../request-tracker/request-tracker'; | ||
private xhrTracker; | ||
private ignoredUrls; | ||
private configEndpoint; | ||
constructor(spanFactory: SpanFactory, fetchTracker: RequestTracker, xhrTracker: RequestTracker); | ||
@@ -11,0 +11,0 @@ configure(configuration: InternalConfiguration<BrowserConfiguration>): void; |
import { type SpanContextStorage, type InternalConfiguration, type Plugin, type SpanFactory } from '@bugsnag/core-performance'; | ||
import { type BrowserConfiguration } from '../config'; | ||
export declare function getHttpVersion(protocol: string): string; | ||
export declare function getHttpVersion(protocol: string): string | undefined; | ||
export declare class ResourceLoadPlugin implements Plugin<BrowserConfiguration> { | ||
@@ -5,0 +5,0 @@ private readonly spanFactory; |
@@ -10,3 +10,2 @@ import { type ConfigOption, type Configuration, type CoreSchema } from '@bugsnag/core-performance'; | ||
settleIgnoreUrls: ConfigOption<Array<string | RegExp>>; | ||
networkInstrumentationIgnoreUrls: ConfigOption<Array<string | RegExp>>; | ||
} | ||
@@ -20,5 +19,4 @@ export interface BrowserConfiguration extends Configuration { | ||
settleIgnoreUrls?: Array<string | RegExp>; | ||
networkInstrumentationIgnoreUrls?: Array<string | RegExp>; | ||
} | ||
export declare function createSchema(hostname: string, defaultRoutingProvider: RoutingProvider): BrowserSchema; | ||
//# sourceMappingURL=config.d.ts.map |
@@ -1,5 +0,5 @@ | ||
import { type BackgroundingListener, type DeliveryFactory } from '@bugsnag/core-performance'; | ||
import { type BackgroundingListener, type Clock, type DeliveryFactory } from '@bugsnag/core-performance'; | ||
export type Fetch = typeof fetch; | ||
declare function createBrowserDeliveryFactory(fetch: Fetch, backgroundingListener: BackgroundingListener): DeliveryFactory; | ||
declare function createBrowserDeliveryFactory(fetch: Fetch, backgroundingListener: BackgroundingListener, clock: Clock): DeliveryFactory; | ||
export default createBrowserDeliveryFactory; | ||
//# sourceMappingURL=delivery.d.ts.map |
import { type Span, type SpanOptions } from '@bugsnag/core-performance'; | ||
export type RouteChangeSpanOptions = Omit<SpanOptions, 'isFirstClass'>; | ||
export type StartRouteChangeCallback = (route: string, trigger: string, options?: RouteChangeSpanOptions) => Span; | ||
export type StartRouteChangeCallback = (url: URL | string, trigger: string, options?: RouteChangeSpanOptions) => Span; | ||
export interface RoutingProvider { | ||
@@ -5,0 +5,0 @@ resolveRoute: (url: URL) => string; |
{ | ||
"name": "@bugsnag/browser-performance", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "BugSnag performance monitoring for browsers", | ||
@@ -24,3 +24,3 @@ "homepage": "https://www.bugsnag.com/", | ||
"dependencies": { | ||
"@bugsnag/core-performance": "^0.2.0", | ||
"@bugsnag/core-performance": "^0.3.0", | ||
"@bugsnag/cuid": "^3.0.2" | ||
@@ -34,3 +34,3 @@ }, | ||
], | ||
"gitHead": "01cf746ea73d61a88eb9351d68f70867cb2fbbef" | ||
"gitHead": "076d6311e6534e8ed2bdacb82cd3bcfeb2033ffd" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79223
1345
+ Added@bugsnag/core-performance@0.3.0(transitive)
- Removed@bugsnag/core-performance@0.2.0(transitive)