aws-amplify / aws-amplify/amplify-hosting

Nextjs server-side calls to Rollbar not working

Open
#2,810 1 comment 0 reactions 0 assignees View on GitHub
bug ssr
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:
![Screen Shot 2022-06-15 at 2 45 12 PM](https://user-images.githubusercontent.com/53156002/173935686-a77239de-f509-41d2-aaf2-0fb541c528c9.png)

Error logged to console in Amplify deployment:
![Screen Shot 2022-06-15 at 2 52 44 PM](https://user-images.githubusercontent.com/53156002/173937087-53b4c7c4-9e39-406b-97d7-b7594a9bdabc.png)

Contributor guide

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.