httpcontext.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { defineIntegration, convertIntegrationFnToClass } from '@sentry/core';
  2. import { WINDOW } from '../helpers.js';
  3. const INTEGRATION_NAME = 'HttpContext';
  4. const _httpContextIntegration = (() => {
  5. return {
  6. name: INTEGRATION_NAME,
  7. // TODO v8: Remove this
  8. setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
  9. preprocessEvent(event) {
  10. // if none of the information we want exists, don't bother
  11. if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
  12. return;
  13. }
  14. // grab as much info as exists and add it to the event
  15. const url = (event.request && event.request.url) || (WINDOW.location && WINDOW.location.href);
  16. const { referrer } = WINDOW.document || {};
  17. const { userAgent } = WINDOW.navigator || {};
  18. const headers = {
  19. ...(event.request && event.request.headers),
  20. ...(referrer && { Referer: referrer }),
  21. ...(userAgent && { 'User-Agent': userAgent }),
  22. };
  23. const request = { ...event.request, ...(url && { url }), headers };
  24. event.request = request;
  25. },
  26. };
  27. }) ;
  28. const httpContextIntegration = defineIntegration(_httpContextIntegration);
  29. /**
  30. * HttpContext integration collects information about HTTP request headers.
  31. * @deprecated Use `httpContextIntegration()` instead.
  32. */
  33. // eslint-disable-next-line deprecation/deprecation
  34. const HttpContext = convertIntegrationFnToClass(INTEGRATION_NAME, httpContextIntegration)
  35. ;
  36. export { HttpContext, httpContextIntegration };
  37. //# sourceMappingURL=httpcontext.js.map