### Get Project Details (Ruby)
Source: https://docs.rollbar.com/reference/get-a-project
Ruby example for retrieving project information. An Account Access Token with 'read' scope is necessary.
```ruby
require 'rollbar'
Rollbar.configure do |config|
config.access_token = 'YOUR_ACCESS_TOKEN'
# Other Rollbar options...
end
Rollbar.get_project(project_id) do |project|
if project
puts project.to_json
else
puts 'Error retrieving project'
end
end
```
--------------------------------
### Installation & Initialization
Source: https://docs.rollbar.com/docs/session-replay
Steps to install the Rollbar SDK and initialize it with the session replay option.
```APIDOC
## Installation & Enabling Session Replay in Rollbar
To use Rollbar's new session replay feature and privacy controls, follow these steps:
1. **Install or upgrade to the latest Rollbar SDK:**
```jsx
npm install rollbar@3.0.0
```
2. **Import and initialize Rollbar Replays with the replay option:**
**For existing Rollbar connected projects**
```jsx
//New Rollbar Imports
import Rollbar from "rollbar/replay";
//Your current Rollbar config
config = {
// ... your existing config
replay: {
enabled: true
}
}
```
For React users using the Rollbar Provider:
```jsx
const rollbar = new Rollbar(config);
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
);
```
**If loading the client from the CDN:**
```jsx
CDN_URL =
```
**For new Rollbar connected projects.**
Follow the Quick Start guide that matches your application at and add the above configuration
```
--------------------------------
### Get a Deploy by ID (Ruby)
Source: https://docs.rollbar.com/reference/get-a-deploy
Ruby example for retrieving deploy information. Remember to substitute the placeholder deploy ID and access token.
```ruby
require 'rollbar'
Rollbar.configure do |config|
config.access_token = 'YOUR_PROJECT_ACCESS_TOKEN'
end
Rollbar.get_deploy('{deploy_id}') do |deploy, err|
if err
puts err
else
puts deploy
end
end
```
--------------------------------
### Get Project Details (Node.js)
Source: https://docs.rollbar.com/reference/get-a-project
Example of fetching project details using Node.js. Requires an Account Access Token with 'read' scope.
```javascript
const Rollbar = require('rollbar');
const rollbar = new Rollbar({
accessToken: 'YOUR_ACCESS_TOKEN',
// Other Rollbar options...
});
rollbar.getProject(projectId, function (err, project) {
if (err) {
console.error(err);
return;
}
console.log(project);
});
```
--------------------------------
### Get a Deploy by ID (Python)
Source: https://docs.rollbar.com/reference/get-a-deploy
Python example for making an API request to get deploy information. Replace the placeholder token and ID.
```python
import rollbar
rollbar.init('YOUR_PROJECT_ACCESS_TOKEN')
response = rollbar.get_deploy('{deploy_id}')
if response.error:
print(response.error)
else:
print(response.result)
```
--------------------------------
### Trigger Example
Source: https://docs.rollbar.com/docs/session-replay
Example configuration showing how to set up different types of triggers.
```APIDOC
## Trigger Example
### Description
This example demonstrates how to configure various triggers for Rollbar Replays.
### Request Example
```jsx
replay: {
triggers: [
{
type: 'occurrence',
level: ['warning', 'error', 'critical', 'info'],
samplingRatio: 1.0
},
{
type: 'navigation',
pathMatch: /app/, // matches any valid regex (as shown, will also match paths containing 'app')
preDuration: 0,
postDuration: 600,
},
{
type: 'direct',
tags: ['blue', 'green'],
}
]
}
```
```
--------------------------------
### Install Rollbar SDK
Source: https://docs.rollbar.com/docs/python
Use pip to install the package.
```bash
pip install rollbar
```
--------------------------------
### Start Redis Server
Source: https://docs.rollbar.com/docs/sidekiq-integration
Before starting Sidekiq, ensure the Redis server is running.
```bash
$ redis-server
```
--------------------------------
### Install Dependencies with Bundler
Source: https://docs.rollbar.com/docs/logstash
Use this command to install all necessary dependencies for plugin development.
```bash
bundle install
```
--------------------------------
### Get a Deploy by ID (Node.js)
Source: https://docs.rollbar.com/reference/get-a-deploy
Example of fetching deploy details using Node.js. Replace placeholders with your actual deploy ID and access token.
```javascript
const Rollbar = require('rollbar');
const rollbar = new Rollbar({
accessToken: 'YOUR_PROJECT_ACCESS_TOKEN',
// Other Rollbar options
});
rollbar.getDeploy('{deploy_id}', function (err, deploy) {
if (err) {
console.error(err);
return;
}
console.log(deploy);
});
```
--------------------------------
### Install Rollbar with yarn
Source: https://docs.rollbar.com/docs/react-ts
Install the Rollbar SDK and its React integration using yarn.
```bash
yarn add rollbar @rollbar/react
```
--------------------------------
### JavaScript Example
Source: https://docs.rollbar.com/reference/update-a-deploy
A basic JavaScript example demonstrating an AJAX GET request. This is likely boilerplate or a placeholder and not directly related to the API update functionality.
```javascript
$.get('http://yoursite.com/test/' + id, function(data) {
console.log(data);
});
```
--------------------------------
### Install Rollbar with npm
Source: https://docs.rollbar.com/docs/react-ts
Install the Rollbar SDK and its React integration using npm.
```bash
npm install rollbar @rollbar/react
```
--------------------------------
### Start rollbar-agent service
Source: https://docs.rollbar.com/docs/rollbar-agent
Start the rollbar-agent service after it has been set up and configured.
```bash
service rollbar-agent start
```
--------------------------------
### Install rollbar-agent from source
Source: https://docs.rollbar.com/docs/rollbar-agent
After cloning or extracting the source, run this command to install the agent. A sudo may be required.
```bash
python setup.py install
```
--------------------------------
### Install Rollbar for Next.js
Source: https://docs.rollbar.com/docs/nextjs
Install the Rollbar SDK and the React integration package using npm, yarn, or pnpm.
```bash
# npm
> npm install rollbar @rollbar/react
```
```bash
# yarn
> yarn add rollbar @rollbar/react
```
```bash
# pnpm
> pnpm add rollbar @rollbar/react
```
--------------------------------
### Install Rollbar React SDK with npm
Source: https://docs.rollbar.com/docs/react
Install the Rollbar React SDK and the core rollbar.js library using npm.
```shell
npm install @rollbar/react rollbar
```
--------------------------------
### Install Rollbar via NuGet
Source: https://docs.rollbar.com/docs/asp-net-mvc
Command to install the Rollbar SDK using the Package Manager Console.
```shell
Install-Package Rollbar
```
--------------------------------
### Configure and Install Rollbar in Bottle
Source: https://docs.rollbar.com/docs/bottle
Initializes the Rollbar reporter and installs it globally to catch exceptions in a Bottle application.
```python
import bottle
from rollbar.contrib.bottle import RollbarBottleReporter
rbr = RollbarBottleReporter(access_token='POST_SERVER_ITEM_ACCESS_TOKEN', environment='production') #setup rollbar
bottle.install(rbr) #install globally
@bottle.get('/')
def raise_error():
'''
When navigating to /, we'll get a regular 500 page from bottle,
as well as have the error below listed on Rollbar.
'''
raise Exception('Hello, Rollbar!')
if __name__ == '__main__':
bottle.run(host='localhost', port=8080)
```
--------------------------------
### Install Rollbar React SDK with yarn
Source: https://docs.rollbar.com/docs/react
Install the Rollbar React SDK and the core rollbar.js library using yarn.
```shell
yarn add @rollbar/react rollbar
```
--------------------------------
### Configure and Start AUL Monitoring
Source: https://docs.rollbar.com/docs/sdk-module-rollbaraul
Initializes the Rollbar configuration with telemetry enabled and starts the AUL store monitor to capture application logs.
```swift
// Create proper RollbarConfig instance making sure
// the Telemetry and its log capture are enabled:
let config = RollbarConfig();
config.destination.accessToken = "";
config.destination.environment = "";
config.developerOptions.transmit = true;
config.telemetry.enabled = true;
config.telemetry.captureLog = true;
// Setup shared RollbarLogger with the config:
Rollbar.initWithConfiguration(config);
// Configure the AUL monitor with the logger:
RollbarAulStoreMonitor.sharedInstance().configureRollbarLogger(Rollbar.currentLogger());
// Optionally, configure the AUL monitoring options:
let aulOptions = RollbarAulStoreMonitorOptions();
aulOptions.addAulSubsystem("DataAccessLayer");
aulOptions.addAulSubsystem("Model");
aulOptions.addAulCategory("CompanyOrg");
RollbarAulStoreMonitor.sharedInstance().configure(with: aulOptions);
// Start the AUL monitoring:
RollbarAulStoreMonitor.sharedInstance().start();
```
```objectivec
// Create proper RollbarConfig instance making sure
// the Telemetry and its log capture are enabled:
RollbarConfig *rollbarConfig = [[RollbarConfig alloc] init];
rollbarConfig.destination.accessToken = @"";
rollbarConfig.destination.environment = @"";
rollbarConfig.developerOptions.transmit = YES;
rollbarConfig.telemetry.enabled = YES; // required for AUL capture
rollbarConfig.telemetry.captureLog = YES; // required for AUL capture
rollbarConfig.telemetry.maximumTelemetryData = 100;
// Setup shared RollbarLogger with the config:
[Rollbar initWithConfiguration:rollbarConfig];
// Configure the AUL monitor with the logger:
[RollbarAulStoreMonitor.sharedInstance configureRollbarLogger:Rollbar.currentLogger];
// Optionally, configure the AUL monitoring options:
RollbarAulStoreMonitorOptions *aulMonitorOptions =
[[RollbarAulStoreMonitorOptions alloc] init];
[aulMonitorOptions addAulSubsystem:@"DataAccessLayer"];
[aulMonitorOptions addAulSubsystem:@"Model"];
[aulMonitorOptions addAulCategory:@"CompanyOrg"];
[RollbarAulStoreMonitor.sharedInstance configureWithOptions:aulMonitorOptions];
// Start the AUL monitoring:
[RollbarAulStoreMonitor.sharedInstance start];
```
--------------------------------
### Install Twisted and Treq
Source: https://docs.rollbar.com/docs/twisted
Install the Twisted framework and the treq library, which are required for using pyrollbar with Twisted. Run these commands in your terminal.
```bash
pip install twisted
pip install treq
```
--------------------------------
### Create RQL Job cURL Example
Source: https://docs.rollbar.com/docs/rql
Example using cURL to create an RQL job with a specified query string. Requires an ACCOUNT_READ_TOKEN for authentication.
```curl
curl --location 'https://api.rollbar.com/api/1/rql/jobs/' \
--header 'X-Rollbar-Access-Token: ACCOUNT_READ_TOKEN' \
--form 'query_string=" SELECT *
FROM item_occurrence
WHERE item.counter = 1
ORDER BY timestamp DESC"'
```
--------------------------------
### Get Project Details (Python)
Source: https://docs.rollbar.com/reference/get-a-project
Python code to get project details. Requires an Account Access Token with 'read' scope.
```python
import rollbar
rollbar.init(
'YOUR_ACCESS_TOKEN',
# Other Rollbar options...
)
project = rollbar.get_project(project_id)
if project:
print(project)
else:
print('Error retrieving project')
```
--------------------------------
### Initialize and Report Errors
Source: https://docs.rollbar.com/docs/python
Initialize the SDK with your access token and environment, then use try-except blocks to report exceptions.
```python
import rollbar
# access_token, environment, code_version
rollbar.init('POST_SERVER_ITEM_ACCESS_TOKEN', 'production', code_version='COMMIT_SHA')
try:
main_app_loop()
except IOError:
rollbar.report_message('Got an IOError in the main loop', 'warning')
except:
# catch-all
rollbar.report_exc_info()
# equivalent to rollbar.report_exc_info(sys.exc_info())
```
--------------------------------
### View CLI Help
Source: https://docs.rollbar.com/docs/python
Display available command-line options.
```bash
$ rollbar --help
Usage: rollbar [options]
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-t ACCESS_TOKEN, --access_token=ACCESS_TOKEN
You project's access token from rollbar.com.
-e ENVIRONMENT, --environment=ENVIRONMENT
The environment to report errors and messages to.
-u ENDPOINT_URL, --url=ENDPOINT_URL
The Rollbar API endpoint url to send data to.
-m HANDLER, --handler=HANDLER
The method in which to report errors.
-v, --verbose Print verbose output.
```
--------------------------------
### Initialize LaunchDarkly Client with Context
Source: https://docs.rollbar.com/docs/launchdarkly
Set up the LaunchDarkly client with user and organization context. Ensure 'YOUR_LD_TOKEN' is replaced with your actual LaunchDarkly client-side ID.
```javascript
//Create Org and User Context to be used
const context = {
kind: "multi",
user: {
key: "User X_ID",
name: "User X",
email: "UserX@company.com"
},
organization: {
key: "Company X_ID",
name: "Company X",
address: {
street: "Some Street",
city: "Some City"
}
}
}
// Set clientSideID to your LaunchDarkly client-side ID
const clientSideID = 'YOUR_LD_TOKEN';
//Initialize Client
const ldclient = LDClient.initialize(clientSideID, context);
```
--------------------------------
### Initializing Rollbar with New API (Recommended)
Source: https://docs.rollbar.com/docs/upgrading-from-v054-or-earlier-to-v100
This example shows the recommended way to initialize the Rollbar SDK using the new API, which involves configuring the Rollbar instance with a Config object built using the builder pattern.
```java
import com.rollbar.notifier.Rollbar;
public class MainClass {
public static final Rollbar rollbar = new Rollbar(
withAccessToken("ACCESS_TOKEN")
.environment("production")
.handleUncaughtErrors(true)
.build());
public int main(String[] args) {
OtherClass.runProgram();
return 0;
}
}
```
--------------------------------
### Make init.d script executable and symlink
Source: https://docs.rollbar.com/docs/rollbar-agent
Make the init.d script executable and then symlink it to the system's init.d directory. Ensure VIRTUALENV is set correctly in the script.
```bash
chmod +x /path/to/virtualenv/rollbar-agent-init.sh
ln -s /path/to/virtualenv/rollbar-agent-init.sh /etc/init.d/rollbar-agent
```
--------------------------------
### Add Rake to Gemfile
Source: https://docs.rollbar.com/docs/using-with-zeus
If the Zeus server fails to start after installing the rollbar gem, explicitly add 'gem "rake"' to your Gemfile to resolve potential conflicts.
```ruby
gem "rake"
```
--------------------------------
### Initialize and use Rollbar in Go
Source: https://docs.rollbar.com/docs/go
Configure the Rollbar client with your project token and environment, then use it to report messages or wrap functions to capture panics.
```go
package main
import (
"github.com/rollbar/rollbar-go"
"time"
)
func main() {
rollbar.SetToken("MY_TOKEN")
rollbar.SetEnvironment("production") // defaults to "development"
rollbar.SetCodeVersion("v2") // optional Git hash/branch/tag (required for GitHub integration)
rollbar.SetServerHost("web.1") // optional override; defaults to hostname
rollbar.SetServerRoot("github.com/heroku/myproject") // path of project (required for GitHub integration and non-project stacktrace collapsing) - where repo is set up for the project, the server.root has to be "/"
rollbar.Info("Message body goes here")
rollbar.WrapAndWait(doSomething)
rollbar.Close() // call before your application closes to send any final events
}
func doSomething() {
var timer *time.Timer = nil
timer.Reset(10) // this will panic
}
```
--------------------------------
### cURL Request to Get Activated Item Counts
Source: https://docs.rollbar.com/reference/get-activated-item-counts
Example cURL request to fetch activated item counts. The `buckets` query parameter specifies the number of buckets to return, defaulting to 60.
```shell
curl --request GET \
--url 'https://api.rollbar.com/api/1/reports/activated_counts?buckets=60'
```
--------------------------------
### Rollbar SDK Configuration Example
Source: https://docs.rollbar.com/docs/rollbarjs-configuration-reference
Illustrates how to configure the Rollbar SDK with various options. Ensure you replace 'YOUR_POST_SERVER_ITEM_ACCESS_TOKEN' with your actual access token.
```javascript
Rollbar.init({
accessToken: 'YOUR_POST_SERVER_ITEM_ACCESS_TOKEN',
captureUncaught: true,
captureUnhandledRejections: true,
payload: {
environment: 'production',
server: {