sentry-example-page.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!--
  2. This is just a very simple page with a button to throw an example error.
  3. Feel free to delete this file.
  4. -->
  5. <script setup>
  6. import * as Sentry from '@sentry/nuxt'
  7. class SentryExampleFrontendError extends Error {
  8. constructor(message) {
  9. super(message)
  10. this.name = 'SentryExampleFrontendError'
  11. }
  12. }
  13. const hasSentError = ref(false)
  14. const isConnected = ref(true)
  15. onMounted(async () => {
  16. try {
  17. const result = await Sentry.diagnoseSdkConnectivity()
  18. isConnected.value = result !== 'sentry-unreachable'
  19. }
  20. catch (error) {
  21. isConnected.value = false
  22. }
  23. })
  24. async function getSentryData() {
  25. await Sentry.startSpan(
  26. {
  27. name: 'Example Frontend Span',
  28. op: 'test',
  29. },
  30. async () => {
  31. const res = await $fetch('/api/sentry-example-api', {
  32. method: 'GET',
  33. ignoreResponseError: true,
  34. }).catch(() => null)
  35. if (!res) {
  36. hasSentError.value = true
  37. }
  38. },
  39. )
  40. throw new SentryExampleFrontendError('This error is raised on the frontend of the example page.')
  41. }
  42. </script>
  43. <template>
  44. <title>Sentry Onboarding</title>
  45. <div>
  46. <main>
  47. <div class="flex-spacer" />
  48. <svg
  49. height="40"
  50. width="40"
  51. fill="none"
  52. xmlns="http://www.w3.org/2000/svg"
  53. >
  54. <path
  55. d="M21.85 2.995a3.698 3.698 0 0 1 1.353 1.354l16.303 28.278a3.703 3.703 0 0 1-1.354 5.053 3.694 3.694 0 0 1-1.848.496h-3.828a31.149 31.149 0 0 0 0-3.09h3.815a.61.61 0 0 0 .537-.917L20.523 5.893a.61.61 0 0 0-1.057 0l-3.739 6.494a28.948 28.948 0 0 1 9.63 10.453 28.988 28.988 0 0 1 3.499 13.78v1.542h-9.852v-1.544a19.106 19.106 0 0 0-2.182-8.85 19.08 19.08 0 0 0-6.032-6.829l-1.85 3.208a15.377 15.377 0 0 1 6.382 12.484v1.542H3.696A3.694 3.694 0 0 1 0 34.473c0-.648.17-1.286.494-1.849l2.33-4.074a8.562 8.562 0 0 1 2.689 1.536L3.158 34.17a.611.611 0 0 0 .538.917h8.448a12.481 12.481 0 0 0-6.037-9.09l-1.344-.772 4.908-8.545 1.344.77a22.16 22.16 0 0 1 7.705 7.444 22.193 22.193 0 0 1 3.316 10.193h3.699a25.892 25.892 0 0 0-3.811-12.033 25.856 25.856 0 0 0-9.046-8.796l-1.344-.772 5.269-9.136a3.698 3.698 0 0 1 3.2-1.849c.648 0 1.285.17 1.847.495Z"
  56. fill="currentcolor"
  57. />
  58. </svg>
  59. <h1>
  60. sentry-example-page
  61. </h1>
  62. <p class="description">
  63. Click the button below, and view the sample error on the Sentry <a
  64. target="_blank"
  65. href="https://gamivip.sentry.io/issues/?project=4510503931346944"
  66. >Issues Page</a>.
  67. For more details about setting up Sentry, <a
  68. target="_blank"
  69. href="https://docs.sentry.io/platforms/javascript/guides/nuxt/"
  70. >read our docs</a>.
  71. </p>
  72. <button
  73. type="button"
  74. :disabled="!isConnected"
  75. @click="getSentryData"
  76. >
  77. <span>
  78. Throw Sample Error
  79. </span>
  80. </button>
  81. <p
  82. v-if="hasSentError"
  83. class="success"
  84. >
  85. Sample error was sent to Sentry.
  86. </p>
  87. <div
  88. v-else-if="!isConnected"
  89. class="connectivity-error"
  90. >
  91. <p>It looks like network requests to Sentry are being blocked, which will prevent errors from being captured. Try disabling your ad-blocker to complete the test.</p>
  92. </div>
  93. <div
  94. v-else
  95. class="success_placeholder"
  96. />
  97. <div class="flex-spacer" />
  98. </main>
  99. </div>
  100. </template>
  101. <style scoped>
  102. :global(body) {
  103. margin: 0;
  104. @media (prefers-color-scheme: dark) {
  105. color: #ededed;
  106. background-color: #0a0a0a;
  107. }
  108. }
  109. main {
  110. display: flex;
  111. min-height: 100vh;
  112. box-sizing: border-box;
  113. flex-direction: column;
  114. justify-content: center;
  115. align-items: center;
  116. gap: 16px;
  117. padding: 16px;
  118. font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  119. }
  120. h1 {
  121. padding: 0px 4px;
  122. margin: 0;
  123. border-radius: 4px;
  124. background-color: rgba(24, 20, 35, 0.03);
  125. font-family: monospace;
  126. font-size: 20px;
  127. line-height: 1.2;
  128. }
  129. p {
  130. margin: 0;
  131. font-size: 20px;
  132. }
  133. a {
  134. color: #6341F0;
  135. text-decoration: underline;
  136. cursor: pointer;
  137. @media (prefers-color-scheme: dark) {
  138. color: #B3A1FF;
  139. }
  140. }
  141. button {
  142. border-radius: 8px;
  143. color: white;
  144. cursor: pointer;
  145. background-color: #553DB8;
  146. border: none;
  147. padding: 0;
  148. margin-top: 4px;
  149. & > span {
  150. display: inline-block;
  151. padding: 12px 16px;
  152. border-radius: inherit;
  153. font-size: 20px;
  154. font-weight: bold;
  155. line-height: 1;
  156. background-color: #7553FF;
  157. border: 1px solid #553DB8;
  158. transform: translateY(-4px);
  159. }
  160. &:hover > span {
  161. transform: translateY(-8px);
  162. }
  163. &:active > span {
  164. transform: translateY(0);
  165. }
  166. &:disabled {
  167. cursor: not-allowed;
  168. opacity: 0.6;
  169. & > span {
  170. transform: translateY(0);
  171. border: none;
  172. }
  173. }
  174. }
  175. .description {
  176. text-align: center;
  177. color: #6E6C75;
  178. max-width: 500px;
  179. line-height: 1.5;
  180. font-size: 20px;
  181. @media (prefers-color-scheme: dark) {
  182. color: #A49FB5;
  183. }
  184. }
  185. .flex-spacer {
  186. flex: 1;
  187. }
  188. .success {
  189. padding: 12px 16px;
  190. border-radius: 8px;
  191. font-size: 20px;
  192. line-height: 1;
  193. background-color: #00F261;
  194. border: 1px solid #00BF4D;
  195. color: #181423;
  196. }
  197. .success_placeholder {
  198. height: 46px;
  199. }
  200. .connectivity-error {
  201. padding: 12px 16px;
  202. background-color: #E50045;
  203. border-radius: 8px;
  204. width: 500px;
  205. color: #FFFFFF;
  206. border: 1px solid #A80033;
  207. text-align: center;
  208. margin: 0;
  209. }
  210. .connectivity-error a {
  211. color: #FFFFFF;
  212. text-decoration: underline;
  213. }
  214. </style>