@bugsnag/browser-performance
Advanced tools
Comparing version 0.0.1-alpha.0 to 0.0.2-alpha.0
@@ -0,1 +1,3 @@ | ||
import { timeToNumber } from '@bugsnag/core-performance'; | ||
class RouteChangePlugin { | ||
@@ -9,11 +11,17 @@ constructor(spanFactory, onSettle, clock) { | ||
// if (!configuration.autoInstrumentRouteChanges) return | ||
configuration.routingProvider.onRouteChange((currentRoute, previousRoute, startTime) => { | ||
const span = this.spanFactory.startSpan(`[RouteChange]${currentRoute}`, startTime); | ||
let previousRoute = ''; | ||
const startRouteChangeSpan = (route, options) => { | ||
const startTime = (options === null || options === void 0 ? void 0 : options.startTime) ? timeToNumber(this.clock, options.startTime) : this.clock.now(); | ||
const span = this.spanFactory.startSpan(`[RouteChange]${route}`, startTime); | ||
span.setAttribute('bugsnag.span.category', 'route_change'); | ||
span.setAttribute('bugsnag.browser.page.route', currentRoute); | ||
span.setAttribute('bugsnag.browser.page.previous_route', previousRoute); | ||
this.onSettle((endTime) => { | ||
this.spanFactory.endSpan(span, endTime); | ||
}); | ||
}, this.clock); | ||
span.setAttribute('bugsnag.browser.page.route', route); | ||
span.setAttribute('bugsnag.browser.page.previous_route', (options === null || options === void 0 ? void 0 : options.previousRoute) || previousRoute); | ||
previousRoute = route; | ||
const end = (endTime) => { | ||
const safeTime = timeToNumber(this.clock, endTime); | ||
this.spanFactory.endSpan(span, safeTime); | ||
}; | ||
return { end }; | ||
}; | ||
configuration.routingProvider.configure(startRouteChangeSpan, this.onSettle); | ||
} | ||
@@ -20,0 +28,0 @@ } |
import { createClient } from '@bugsnag/core-performance'; | ||
import { FullPageLoadPlugin } from './auto-instrumentation/full-page-load-plugin.js'; | ||
import { NetworkRequestPlugin } from './auto-instrumentation/network-request-plugin.js'; | ||
import { RouteChangePlugin } from './auto-instrumentation/route-change-plugin.js'; | ||
import createBrowserBackgroundingListener from './backgrounding-listener.js'; | ||
@@ -9,7 +11,6 @@ import createClock from './clock.js'; | ||
import createOnSettle from './on-settle/index.js'; | ||
import createFetchRequestTracker from './request-tracker/request-tracker-fetch.js'; | ||
import createXmlHttpRequestTracker from './request-tracker/request-tracker-xhr.js'; | ||
import createResourceAttributesSource from './resource-attributes-source.js'; | ||
import createSpanAttributesSource from './span-attributes-source.js'; | ||
import createFetchRequestTracker from './request-tracker/request-tracker-fetch.js'; | ||
import createXmlHttpRequestTracker from './request-tracker/request-tracker-xhr.js'; | ||
import { NetworkRequestPlugin } from './auto-instrumentation/network-request-plugin.js'; | ||
import { WebVitals } from './web-vitals.js'; | ||
@@ -36,3 +37,4 @@ | ||
new FullPageLoadPlugin(document, window.location, spanFactory, webVitals, onSettle, backgroundingListener), | ||
new NetworkRequestPlugin(spanFactory, fetchRequestTracker, xhrRequestTracker) | ||
new NetworkRequestPlugin(spanFactory, fetchRequestTracker, xhrRequestTracker), | ||
new RouteChangePlugin(spanFactory, onSettle, clock) | ||
] | ||
@@ -39,0 +41,0 @@ }); |
@@ -5,3 +5,3 @@ import { ResourceAttributes } from '@bugsnag/core-performance'; | ||
return function resourceAttributesSource(config) { | ||
const attributes = new ResourceAttributes(config.releaseStage, config.appVersion, 'bugsnag.performance.browser', '0.0.0'); | ||
const attributes = new ResourceAttributes(config.releaseStage, config.appVersion, 'bugsnag.performance.browser', '0.0.1-alpha.0'); | ||
attributes.set('browser.user_agent', navigator.userAgent); | ||
@@ -8,0 +8,0 @@ // chromium only |
import { isObject } from '@bugsnag/core-performance'; | ||
import getAbsoluteUrl from './request-tracker/url-helpers.js'; | ||
const defaultRouteResolver = (url) => url.pathname; | ||
const defaultRouteResolver = (url) => url instanceof URL ? url.pathname : url; | ||
class DefaultRoutingProvider { | ||
@@ -8,6 +9,35 @@ constructor(resolveRoute = defaultRouteResolver) { | ||
} | ||
configure(startRouteChangeSpan, onSettle) { | ||
let initialRoute = this.resolveRoute(new URL(window.location.href)); | ||
addEventListener('popstate', () => { | ||
const route = this.resolveRoute(window.location.href); | ||
const span = startRouteChangeSpan(route, { previousRoute: initialRoute }); | ||
// clear initial route | ||
initialRoute = undefined; | ||
onSettle((endTime) => { | ||
span.end(endTime); | ||
}); | ||
}); | ||
const resolveRoute = this.resolveRoute; | ||
const originalPushState = history.pushState; | ||
history.pushState = function (...args) { | ||
const url = args[2]; | ||
if (url) { | ||
const absoluteUrl = getAbsoluteUrl(url.toString(), window.location.hostname); | ||
const route = resolveRoute(new URL(absoluteUrl)); | ||
console.log({ absoluteUrl, route }); | ||
const span = startRouteChangeSpan(route, { previousRoute: initialRoute }); | ||
// clear initial route | ||
initialRoute = undefined; | ||
onSettle((endTime) => { | ||
span.end(endTime); | ||
}); | ||
} | ||
originalPushState.apply(this, args); | ||
}; | ||
} | ||
} | ||
const isRoutingProvider = (value) => isObject(value) && | ||
typeof value.resolveRoute === 'function'; | ||
typeof value.configure === 'function'; | ||
export { DefaultRoutingProvider, isRoutingProvider }; |
@@ -1,4 +0,9 @@ | ||
import { type Clock, type InternalConfiguration, type Plugin, type SpanFactory } from '@bugsnag/js-performance-core'; | ||
import { type Span, type Clock, type InternalConfiguration, type Plugin, type SpanFactory, type Time } from '@bugsnag/core-performance'; | ||
import { type BrowserConfiguration } from '../config'; | ||
import { type OnSettle } from '../on-settle'; | ||
interface StartRouteOptions { | ||
startTime?: Time; | ||
previousRoute?: string; | ||
} | ||
export type StartRouteChangeSpan = (route: string, options?: StartRouteOptions) => Span; | ||
export declare class RouteChangePlugin implements Plugin<BrowserConfiguration> { | ||
@@ -11,2 +16,3 @@ private spanFactory; | ||
} | ||
export {}; | ||
//# sourceMappingURL=route-change-plugin.d.ts.map |
@@ -0,10 +1,14 @@ | ||
import { type OnSettle } from './on-settle'; | ||
import { type StartRouteChangeSpan } from './auto-instrumentation'; | ||
export interface RoutingProvider { | ||
resolveRoute: RouteResolver; | ||
configure: (startRouteChangeSpan: StartRouteChangeSpan, onSettle: OnSettle) => void; | ||
} | ||
export type RouteResolver = (url: URL) => string; | ||
export type RouteResolver = (url: URL | string) => string; | ||
export declare class DefaultRoutingProvider implements RoutingProvider { | ||
resolveRoute: RouteResolver; | ||
constructor(resolveRoute?: RouteResolver); | ||
configure(startRouteChangeSpan: StartRouteChangeSpan, onSettle: OnSettle): void; | ||
} | ||
export declare const isRoutingProvider: (value: unknown) => value is RoutingProvider; | ||
//# sourceMappingURL=routing-provider.d.ts.map |
{ | ||
"name": "@bugsnag/browser-performance", | ||
"version": "0.0.1-alpha.0", | ||
"description": "BugsnagPerformance notifier for browsers", | ||
"author": "Ben Wilson <ben.wilson@smartbear.com>", | ||
"homepage": "https://github.com/bugsnag/bugsnag-js-performance#readme", | ||
"version": "0.0.2-alpha.0", | ||
"description": "BugSnag performance monitoring for browsers", | ||
"homepage": "https://www.bugsnag.com/", | ||
"license": "MIT", | ||
@@ -23,3 +22,3 @@ "repository": { | ||
"dependencies": { | ||
"@bugsnag/core-performance": "^0.0.1-alpha.0" | ||
"@bugsnag/core-performance": "^0.0.2-alpha.0" | ||
}, | ||
@@ -32,3 +31,3 @@ "type": "module", | ||
], | ||
"gitHead": "efd6ffc403c0ba340ace1099bf1e208a0aca8a0f" | ||
"gitHead": "2aa5bcdee77e371df60593c6047f6b5e7256b591" | ||
} |
@@ -1,11 +0,40 @@ | ||
# `browser` | ||
<div align="center"> | ||
<a href="https://www.bugsnag.com/platforms/javascript"> | ||
<picture> | ||
<source media="(prefers-color-scheme: dark)" srcset="https://assets.smartbear.com/m/3dab7e6cf880aa2b/original/BugSnag-Repository-Header-Dark.svg"> | ||
<img alt="SmartBear BugSnag logo" src="https://assets.smartbear.com/m/3945e02cdc983893/original/BugSnag-Repository-Header-Light.svg"> | ||
</picture> | ||
</a> | ||
<h1>Performance monitoring for browsers</h1> | ||
</div> | ||
> TODO: description | ||
[![Documentation](https://img.shields.io/badge/documentation-latest-blue.svg)](https://docs.bugsnag.com/performance/browser-js/) | ||
[![Build status](https://badge.buildkite.com/a1ed35adfab0cd5f2c0030cc54961209cb720aa5ed2284cb73.svg?branch=main)](https://buildkite.com/bugsnag/bugsnag-js-performance) | ||
[![Node CI](https://github.com/bugsnag/bugsnag-js-performance/actions/workflows/node-ci.yml/badge.svg)](https://github.com/bugsnag/bugsnag-js-performance/actions/workflows/node-ci.yml) | ||
## Usage | ||
Monitor the page load speed, capture [WebVitals](https://web.dev/vitals/) and take other measurements in your web app and see the results in your [BugSnag](https://www.bugsnag.com) dashboard. | ||
``` | ||
const browser = require('browser'); | ||
## Features | ||
// TODO: DEMONSTRATE API | ||
``` | ||
- Reporting of page loads with WebVital metrics | ||
- Automatic measurement of fetch and XHR request times | ||
- Start and end your own spans to record custom parts of your code | ||
## Getting started | ||
_This functionality is currently in its preview phase – please [contact us](mailto:support@bugsnag.com) for more information._ | ||
For integration instructions, see our online docs: [docs.bugsnag.com/performance/browser-js](https://docs.bugsnag.com/performance/browser-js) | ||
## Pre-releases | ||
We are currently publishing pre-1.0 releases. These releases may contain breaking changes, which are documented in the [CHANGELOG.md](./CHANGELOG.md). | ||
## Support | ||
* [Read the integration guide](https://docs.bugsnag.com/performance/browser-js/) | ||
* [Search open and closed issues](https://github.com/bugsnag/bugsnag-js-performance/issues?utf8=✓&q=is%3Aissue) for similar problems | ||
* [Report a bug or request a feature](https://github.com/bugsnag/bugsnag-js-performance/issues/new) | ||
## License | ||
The BugSnag JavaScript Performance SDK is free software released under the MIT License. See the [LICENSE](https://github.com/bugsnag/bugsnag-js-performance/blob/master/LICENSE) for details. |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
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
71926
1184
40
1
+ Added@bugsnag/core-performance@0.0.2(transitive)
- Removed@bugsnag/core-performance@0.0.1-alpha.0(transitive)