aws-amplify / aws-amplify/amplify-hosting
Nextjs server-side calls to Rollbar not working
- Dominant language
- Dockerfile
- Stars
- 481
- Forks
- 123
- PR merge metrics
- No merged PRs in 30d
Description
### Before opening, please confirm:
- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
### App Id
dfbnpz3ic6vce
### Region
us-east-1
### Amplify Hosting feature
Not applicable
### Describe the bug
Our Next.js application uses Rollbar for error monitoring. Errors/API calls originating from the browser work fine, but server-side errors triggered in `getServerSideProps` and API routes just never make it to Rollbar for some reason. I assume this is also the case for `getStaticProps`.
I have verified the environment variable used for the access token is there, and am able to log the same information to the console.
The exact same code works when run locally.
This is probably a separate issue, but errors thrown in `getServerSideProps` are also not passing the error through to `_error.js`, i.e. `ctx.err` is just empty.
### Expected behavior
Calls to Rollbar should work both client and server-side.
### Reproduction steps
1. Create Next.js app
2. `npm install rollbar`
3. Create API route that calls `rollbar.error()`
4. `npm run build`
5. `npm start`
6. Visit API route
7. Works
8. Deploy to Amplify
9. Visit same API route
10. Doesn't work
Example repo here: https://github.com/pjaws/amplify-next-rollbar
### Build Settings
_No response_
### Additional information
Error logged from local server in example repo:

Error logged to console in Amplify deployment:

Contributor guide
Research direction
Start with the linked example repository and reproduce the behavior using the API route, getServerSideProps, and the documented npm build/start deployment steps. Compare the local server logs with the Amplify deployment logs and verify whether server-side Rollbar calls reach Rollbar after deployment; also check the reported _error.js behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100