|
| 1 | +export { Page } |
| 2 | + |
| 3 | +import { useState } from 'react' |
| 4 | + |
| 5 | +function Page() { |
| 6 | + const [count, setCount] = useState(0) |
| 7 | + |
| 8 | + const throwError = () => { |
| 9 | + throw new Error('This is a test error sent to Sentry!') |
| 10 | + } |
| 11 | + |
| 12 | + const throwAsyncError = async () => { |
| 13 | + await new Promise(resolve => setTimeout(resolve, 100)) |
| 14 | + throw new Error('This is an async error sent to Sentry!') |
| 15 | + } |
| 16 | + |
| 17 | + return ( |
| 18 | + <div style={{ padding: '20px', fontFamily: 'system-ui' }}> |
| 19 | + <h1>Vike + React + Sentry Example</h1> |
| 20 | + |
| 21 | + <p> |
| 22 | + This example demonstrates Sentry error tracking integration with Vike. |
| 23 | + </p> |
| 24 | + |
| 25 | + <div style={{ marginTop: '20px' }}> |
| 26 | + <h2>Counter: {count}</h2> |
| 27 | + <button onClick={() => setCount(count + 1)}> |
| 28 | + Increment |
| 29 | + </button> |
| 30 | + </div> |
| 31 | + |
| 32 | + <div style={{ marginTop: '20px' }}> |
| 33 | + <h2>Test Error Tracking</h2> |
| 34 | + <p>Click these buttons to send test errors to Sentry:</p> |
| 35 | + |
| 36 | + <div style={{ display: 'flex', gap: '10px', marginTop: '10px' }}> |
| 37 | + <button |
| 38 | + onClick={throwError} |
| 39 | + style={{ padding: '10px', backgroundColor: '#ff4444', color: 'white', border: 'none', borderRadius: '4px', cursor: 'pointer' }} |
| 40 | + > |
| 41 | + Throw Sync Error |
| 42 | + </button> |
| 43 | + |
| 44 | + <button |
| 45 | + onClick={throwAsyncError} |
| 46 | + style={{ padding: '10px', backgroundColor: '#ff8844', color: 'white', border: 'none', borderRadius: '4px', cursor: 'pointer' }} |
| 47 | + > |
| 48 | + Throw Async Error |
| 49 | + </button> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + |
| 53 | + <div style={{ marginTop: '40px', padding: '15px', backgroundColor: '#f0f0f0', borderRadius: '4px' }}> |
| 54 | + <h3>Configuration</h3> |
| 55 | + <p>Edit <code>pages/+config.ts</code> to configure your Sentry DSN and options.</p> |
| 56 | + <ul> |
| 57 | + <li>Client-side errors are automatically captured</li> |
| 58 | + <li>Server-side errors are automatically captured</li> |
| 59 | + <li>Distributed tracing connects server and client errors</li> |
| 60 | + </ul> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + ) |
| 64 | +} |
0 commit comments