@bugsnag/request-tracker-performance
Advanced tools
Comparing version 2.2.0 to 2.3.0-alpha.0
@@ -18,4 +18,6 @@ import { RequestTracker } from './request-tracker.js'; | ||
const startContext = createStartContext(clock.now(), input, init, global.document && global.document.baseURI); | ||
const onRequestEnd = requestTracker.start(startContext); | ||
return originalFetch.call(this, input, init).then(response => { | ||
const { onRequestEnd, extraRequestHeaders } = requestTracker.start(startContext); | ||
// Add the headers to the `init` received from the caller | ||
const patchedInit = mergeRequestHeaders(init, extraRequestHeaders); | ||
return originalFetch.call(this, input, patchedInit).then(response => { | ||
onRequestEnd({ status: response.status, endTime: clock.now(), state: 'success' }); | ||
@@ -30,3 +32,14 @@ return response; | ||
} | ||
function mergeRequestHeaders(init, extraRequestHeaders) { | ||
if (!extraRequestHeaders) | ||
return init; | ||
const extraHeaders = {}; | ||
for (const h of extraRequestHeaders) { | ||
for (const [name, value] of Object.entries(h)) { | ||
extraHeaders[name] = value; | ||
} | ||
} | ||
return Object.assign(Object.assign({}, init), { headers: Object.assign(Object.assign({}, extraHeaders), init === null || init === void 0 ? void 0 : init.headers) }); | ||
} | ||
export { createFetchRequestTracker as default }; |
@@ -23,3 +23,3 @@ import { RequestTracker } from './request-tracker.js'; | ||
this.removeEventListener('readystatechange', existingHandler); | ||
const onRequestEnd = requestTracker.start({ | ||
const { onRequestEnd, extraRequestHeaders } = requestTracker.start({ | ||
type: 'xmlhttprequest', | ||
@@ -30,2 +30,9 @@ method: requestData.method, | ||
}); | ||
if (extraRequestHeaders) { | ||
for (const extraHeaders of extraRequestHeaders) { | ||
for (const [name, value] of Object.entries(extraHeaders)) { | ||
this.setRequestHeader(name, value); | ||
} | ||
} | ||
} | ||
const onReadyStateChange = (evt) => { | ||
@@ -32,0 +39,0 @@ if (this.readyState === xhr.DONE && onRequestEnd) { |
@@ -9,16 +9,23 @@ class RequestTracker { | ||
start(context) { | ||
const endCallbacks = []; | ||
const results = []; | ||
for (const startCallback of this.callbacks) { | ||
const endCallback = startCallback(context); | ||
if (endCallback) | ||
endCallbacks.push(endCallback); | ||
const result = startCallback(context); | ||
if (result) | ||
results.push(result); | ||
} | ||
return (endContext) => { | ||
for (const endCallback of endCallbacks) { | ||
endCallback(endContext); | ||
} | ||
return { | ||
onRequestEnd: (endContext) => { | ||
var _a; | ||
for (const result of results) { | ||
(_a = result === null || result === void 0 ? void 0 : result.onRequestEnd) === null || _a === void 0 ? void 0 : _a.call(result, endContext); | ||
} | ||
}, | ||
extraRequestHeaders: results.map(result => result === null || result === void 0 ? void 0 : result.extraRequestHeaders).filter(isDefined) | ||
}; | ||
} | ||
} | ||
function isDefined(argument) { | ||
return argument !== undefined; | ||
} | ||
export { RequestTracker }; |
export interface NetworkRequestInfo { | ||
url: string; | ||
url: string | null; | ||
propagateTraceContext?: boolean; | ||
} | ||
@@ -4,0 +5,0 @@ export type NetworkRequestCallback<T extends NetworkRequestInfo> = (networkRequestInfo: T) => T | null; |
@@ -18,3 +18,6 @@ export interface RequestStartContext { | ||
export type RequestEndContext = RequestEndContextSuccess | RequestEndContextError; | ||
export type RequestStartCallback = (context: RequestStartContext) => RequestEndCallback | undefined; | ||
export type RequestStartCallback = (context: RequestStartContext) => { | ||
onRequestEnd?: RequestEndCallback; | ||
extraRequestHeaders?: Record<string, string>; | ||
} | undefined; | ||
export type RequestEndCallback = (context: RequestEndContext) => void; | ||
@@ -24,4 +27,7 @@ export declare class RequestTracker { | ||
onStart(startCallback: RequestStartCallback): void; | ||
start(context: RequestStartContext): (endContext: RequestEndContext) => void; | ||
start(context: RequestStartContext): { | ||
onRequestEnd: (endContext: RequestEndContext) => void; | ||
extraRequestHeaders: Record<string, string>[]; | ||
}; | ||
} | ||
//# sourceMappingURL=request-tracker.d.ts.map |
{ | ||
"name": "@bugsnag/request-tracker-performance", | ||
"version": "2.2.0", | ||
"version": "2.3.0-alpha.0", | ||
"description": "BugSnag performance request tracker for monitoring XHR and fetch requests", | ||
@@ -23,3 +23,3 @@ "homepage": "https://www.bugsnag.com/", | ||
"dependencies": { | ||
"@bugsnag/core-performance": "^2.2.0" | ||
"@bugsnag/core-performance": "^2.3.0-alpha.0" | ||
}, | ||
@@ -32,3 +32,3 @@ "type": "module", | ||
], | ||
"gitHead": "7b88c34595012a11948078bed7505a1ee0854e17" | ||
"gitHead": "fde1316da0f448bedbdad6a22f9732d14c07ce61" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
14107
206
1
1