Collect and monitor errors from your frontend and backend applications.
Clienwork's error tracking helps you:
Run the setup wizard to automatically configure your project:
npm install @clienwork/errors
npx @clienwork/errors init
The wizard will:
1. Install
npm install @clienwork/errors
2. Set environment variable
# .env.local
NEXT_PUBLIC_CLIENWORK_ERROR_TOKEN=clw_err_xxx
3. Add to next.config.js
const { withClienworkErrors } = require('@clienwork/errors/nextjs')
module.exports = withClienworkErrors({
// your existing config
})
Done! Errors are now automatically collected.
1. Install
npm install @clienwork/errors
2. Set environment variable
# .env or .env.local
NEXT_PUBLIC_CLIENWORK_ERROR_TOKEN=clw_err_xxx
3. Import once at app startup
// Add to your main entry file (e.g., main.ts, index.ts)
import '@clienwork/errors/auto'
Done! Errors are now automatically collected.
import { report } from '@clienwork/errors'
try {
// Risky operation
} catch (error) {
report(error, { context: 'checkout' })
}
Track which user encountered each error:
import { setUser, clearUser } from '@clienwork/errors'
// After user login
setUser('user-123') // or user email, UUID, etc.
// After user logout
clearUser()
When a user reports an issue, you can look up all errors for that specific user.
Wrap your app with the error boundary component:
import { ClienworkErrorBoundary } from '@clienwork/errors/react'
function App() {
return (
<ClienworkErrorBoundary fallback={<ErrorPage />}>
<MyApp />
</ClienworkErrorBoundary>
)
}
For full control over initialization:
import { init } from '@clienwork/errors'
init({
apiToken: process.env.NEXT_PUBLIC_CLIENWORK_ERROR_TOKEN!,
source: 'frontend',
release: process.env.NEXT_PUBLIC_APP_VERSION,
enabled: process.env.NODE_ENV === 'production',
beforeSend: (error) => {
// Return null to filter out this error
return error
},
})
import { createBackendReporter } from '@clienwork/errors'
const errorReporter = createBackendReporter({
apiToken: process.env.CLIENWORK_ERROR_TOKEN!,
})
try {
// your code
} catch (error) {
await errorReporter.report(error, { endpoint: '/api/users' })
throw error
}
import { createBackendReporter, expressErrorHandler } from '@clienwork/errors'
const errorReporter = createBackendReporter({
apiToken: process.env.CLIENWORK_ERROR_TOKEN!,
})
// Add as error middleware
app.use(expressErrorHandler(errorReporter))
Show original source code in stack traces instead of minified code.
# .env.local
NEXT_PUBLIC_APP_VERSION=v1.0.0
{
"scripts": {
"build": "next build",
"postbuild": "clienwork-upload-sourcemaps --release $NEXT_PUBLIC_APP_VERSION"
}
}
Or manually:
npx clienwork-upload-sourcemaps \
--release v1.0.0 \
--include ".next/**/*.map"
Get notified when new errors occur:
Access error logs from:
If you prefer not to use the npm package:
window.onerror = function(message, source, lineno, colno, error) {
fetch('https://app.clienwork.com/api/errors', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${ERROR_TOKEN}`
},
body: JSON.stringify({
message: message,
stack: error?.stack,
url: window.location.href,
userAgent: navigator.userAgent,
source: 'frontend'
})
}).catch(() => {})
}
async function reportError(error, context = {}) {
await fetch('https://app.clienwork.com/api/errors', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.CLIENWORK_ERROR_TOKEN}`
},
body: JSON.stringify({
message: error.message,
stack: error.stack,
source: 'backend',
metadata: context
})
}).catch(() => {})
}