this repo has no description
1import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core'; 2import { WINDOW } from '../helpers.js'; 3 4/** HttpContext integration collects information about HTTP request headers */ 5class HttpContext {constructor() { HttpContext.prototype.__init.call(this); } 6 /** 7 * @inheritDoc 8 */ 9 static __initStatic() {this.id = 'HttpContext';} 10 11 /** 12 * @inheritDoc 13 */ 14 __init() {this.name = HttpContext.id;} 15 16 /** 17 * @inheritDoc 18 */ 19 setupOnce() { 20 addGlobalEventProcessor((event) => { 21 if (getCurrentHub().getIntegration(HttpContext)) { 22 // if none of the information we want exists, don't bother 23 if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) { 24 return event; 25 } 26 27 // grab as much info as exists and add it to the event 28 const url = (event.request && event.request.url) || (WINDOW.location && WINDOW.location.href); 29 const { referrer } = WINDOW.document || {}; 30 const { userAgent } = WINDOW.navigator || {}; 31 32 const headers = { 33 ...(event.request && event.request.headers), 34 ...(referrer && { Referer: referrer }), 35 ...(userAgent && { 'User-Agent': userAgent }), 36 }; 37 const request = { ...event.request, ...(url && { url }), headers }; 38 39 return { ...event, request }; 40 } 41 return event; 42 }); 43 } 44} HttpContext.__initStatic(); 45 46export { HttpContext }; 47//# sourceMappingURL=httpcontext.js.map