@bugsnag/browser-performance
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -0,3 +1,21 @@ | ||
import { validateSpanOptions, isString, coreSpanOptionSchema } from '@bugsnag/core-performance'; | ||
import getAbsoluteUrl from '../request-tracker/url-helpers.js'; | ||
// exclude isFirstClass from the route change option schema | ||
const { startTime, parentContext, makeCurrentContext } = coreSpanOptionSchema; | ||
const routeChangeSpanOptionSchema = { | ||
startTime, | ||
parentContext, | ||
makeCurrentContext, | ||
route: { | ||
getDefaultValue: (value) => String(value), | ||
message: 'should be a string', | ||
validate: isString | ||
}, | ||
trigger: { | ||
getDefaultValue: (value) => String(value), | ||
message: 'should be a string', | ||
validate: isString | ||
} | ||
}; | ||
class RouteChangePlugin { | ||
@@ -14,6 +32,10 @@ constructor(spanFactory, location, document) { | ||
configuration.routingProvider.listenForRouteChanges((route, trigger, options) => { | ||
const span = this.spanFactory.startSpan(`[RouteChange]${route}`, { | ||
startTime: options ? options.startTime : undefined | ||
}); | ||
const url = getAbsoluteUrl(route, this.document.baseURI); | ||
// create internal options for validation | ||
const routeChangeSpanOptions = Object.assign(Object.assign({}, options), { route, | ||
trigger }); | ||
const cleanOptions = validateSpanOptions('[RouteChange]', routeChangeSpanOptions, routeChangeSpanOptionSchema, configuration.logger); | ||
// update the span name using the validated route | ||
cleanOptions.name += cleanOptions.options.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'); | ||
@@ -23,3 +45,3 @@ span.setAttribute('bugsnag.browser.page.route', route); | ||
span.setAttribute('bugsnag.browser.page.previous_route', previousRoute); | ||
span.setAttribute('bugsnag.browser.page.route_change.trigger', trigger); | ||
span.setAttribute('bugsnag.browser.page.route_change.trigger', cleanOptions.options.trigger); | ||
previousRoute = route; | ||
@@ -26,0 +48,0 @@ return { |
@@ -23,6 +23,6 @@ import { responseStateFromStatusCode } from '@bugsnag/core-performance'; | ||
}); | ||
return function browserDeliveryFactory(apiKey, endpoint) { | ||
return function browserDeliveryFactory(endpoint) { | ||
return { | ||
async send(payload) { | ||
const spanCount = payload.resourceSpans.reduce((count, resourceSpan) => count + resourceSpan.scopeSpans.length, 0); | ||
payload.headers['Bugsnag-Sent-At'] = (new Date()).toISOString(); | ||
try { | ||
@@ -32,9 +32,4 @@ const response = await fetch(endpoint, { | ||
keepalive, | ||
body: JSON.stringify(payload), | ||
headers: { | ||
'Bugsnag-Api-Key': apiKey, | ||
'Content-Type': 'application/json', | ||
'Bugsnag-Span-Sampling': `1.0:${spanCount}`, | ||
'Bugsnag-Sent-At': (new Date()).toISOString() | ||
} | ||
body: JSON.stringify(payload.body), | ||
headers: payload.headers | ||
}); | ||
@@ -41,0 +36,0 @@ return { |
@@ -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.1.1'); | ||
const attributes = new ResourceAttributes(config.releaseStage, config.appVersion, 'bugsnag.performance.browser', '0.2.0'); | ||
attributes.set('browser.user_agent', navigator.userAgent); | ||
@@ -11,0 +11,0 @@ // chromium only |
{ | ||
"name": "@bugsnag/browser-performance", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "BugSnag performance monitoring for browsers", | ||
@@ -24,3 +24,3 @@ "homepage": "https://www.bugsnag.com/", | ||
"dependencies": { | ||
"@bugsnag/core-performance": "^0.1.1", | ||
"@bugsnag/core-performance": "^0.2.0", | ||
"@bugsnag/cuid": "^3.0.2" | ||
@@ -34,3 +34,3 @@ }, | ||
], | ||
"gitHead": "1c7bc0b1e10b226d693273d37e81180b4b6c54cc" | ||
"gitHead": "01cf746ea73d61a88eb9351d68f70867cb2fbbef" | ||
} |
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
79220
1336
+ Added@bugsnag/core-performance@0.2.0(transitive)
- Removed@bugsnag/core-performance@0.1.1(transitive)