Rollbar can show additional lines of context for each entry in a traceback, saving your trouble of jumping to your source code to figure out where exactly an exception occurred.
This guide will walk you through the necessary steps to enable this feature.
Rollbar relies on retrieving data from your Git repository in order to show context around each stack frame. Each Rollbar project should be connected to a Git repository (typically a 1:1 mapping). To set up this integration, please see one of the following guides:
NOTE: the field referenced in this section is called
root in some libraries, but is referred to as
In order for Rollbar to retrieve data from your Git repository, it needs to know:
- What part of the stack frame path includes code from your source repository?
- What is the SHA of the version of the code where the exception occurred?
The first is specified by including a
server.root property in the JSON payload configuration which is sent back to Rollbar:
server.root value should match the file path reported by the items in Rollbar. In this case, we tell Rollbar that everything after
file:///Users/david/Documents/dev-stuff/js-demo/ is our code. This also matches the home directory for the github repo: in this case, https://github.com/dbw0011/js-demo/ is the home repo and it has
index.html as a file in the top-level folder. This is an example of a web page being opened from a local drive, so in most cases a web app will have a URL for the path.
By default, Rollbar will retrieve code from your main branch, but you can use the
server.branch property to tell Rollbar that the code lives in a different branch, or you can specify a different default branch for the project in Settings → Source Control.
Make sure to set the "Project Root" field when applicable. This field is used to point to folders within the specified repo where the code can be found.
The code version where the error occurred is also required. Add the Git SHA of the deployed version in your JSON payload:
With this configuration set properly, Rollbar knows to retrieve the code context from
aaaaaabbbbbbccccccddddddeeeeeeffffff/index.html within your repository.
code_version correctly will also ensure that the Git link in each stack frame points to the correct version of your code:
You should now be able to see a stacktrace like this:
This is likely because:
- Git integration is not properly configured in your project. Rollbar needs read to be able to read from your repository in order to grab context. You can tell if Rollbar is properly connected by checking for the name of a Github user whose credentials are used to access the repository. Also, make sure you've entered the correct repo name and default branch:
- Rollbar does not have access to your SCM repo - Check your SCM settings and make sure Rollbar has access. For example, in Github, check Settings → Applications
- or your JSON payloads don't contain
server.rootor you've set up an incorrect value for
- Update your credentials - Check user and/or project Source control credentials in User Settings and Project - Settings - Source Control Manager
Bad Request - Verify Source Control manager credentials are correct and you've set up the correct repo name in the Source control settings (as seen in the Project Settings - Integrations image above)
API Unavailable - Something is wrong with the external API (GitHub, GitLab or BitBucket). Check the direct link to the source code file.
Could not retrieve data from repository - Your repository is not accessible to Rollbar. Please check your repo settings in your Source control manager's settings.
Could not match line with provided code version or No data in file - We are likely gathering file contents from an outdated code version. Please send
code_versionin your item payload for the most accurate results.
If you're still experiencing issues setting up code context for your projects, please contact support!
Updated 3 months ago