Sentry SDK

You can collect errors by integrating your Sentry SDK with Better Stack. This allows you to leverage your existing Sentry setup to send errors to our platform for centralized management and analysis.

Using Claude Code or similar agentic dev-tool?

The easiest way to integate is to use the Integrate with AI prompt.

To configure Sentry SDK integration:

  1. Navigate to Errors -> Applications.
  2. Select your application.
  3. Go to the Data ingestion tab.
  4. Copy Application token and Ingesting host to be used in Sentry SDK.

Using the Sentry SDK

To send errors to Better Stack, configure your Sentry SDK according to the Data ingestion tab for your application:

Sentry DSN configuration
https://$APPLICATION_TOKEN@$INGESTING_HOST/1

The project ID at the end of the DSN (/1) is required by Sentry SDKs but is ignored by our ingestion endpoint. You can use any number.

Here are a few examples for popular Sentry SDKs:

Python Node.js Browser (JS) Ruby PHP
import sentry_sdk

sentry_sdk.init(
    dsn="https://$APPLICATION_TOKEN@$INGESTING_HOST/1",
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    traces_sample_rate=1.0,
)

# Example of capturing an exception
try:
    1 / 0
except ZeroDivisionError as e:
    sentry_sdk.capture_exception(e)
const Sentry = require("@sentry/node");
// Or, for ES6+
// import * as Sentry from "@sentry/node";

Sentry.init({
  dsn: "https://$APPLICATION_TOKEN@$INGESTING_HOST/1",
  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for performance monitoring.
  tracesSampleRate: 1.0,
});

// Example of capturing an exception
try {
  throw new Error("This is a test error from Node.js!");
} catch (e) {
  Sentry.captureException(e);
}
import * as Sentry from "@sentry/browser";

Sentry.init({
  dsn: "https://$APPLICATION_TOKEN@$INGESTING_HOST/1",
  // To capture performance monitoring data,
  // you must set tracesSampleRate
  tracesSampleRate: 1.0,
});

// Example of capturing an exception
try {
  throw new Error("This is a test error from the browser!");
} catch (e) {
  Sentry.captureException(e);
}
require 'sentry-ruby'

Sentry.init do |config|
  config.dsn = 'https://$APPLICATION_TOKEN@$INGESTING_HOST/1'
  config.breadcrumbs_logger = [:active_support_logger, :http_logger]

  # To activate performance monitoring, set one of these options.
  # We recommend adjusting the value in production:
  config.traces_sample_rate = 1.0
end

# Example of capturing an exception
begin
  1 / 0
rescue ZeroDivisionError => exception
  Sentry.capture_exception(exception)
end
use function Sentry\init;
use function Sentry\captureException;

// Assumes you have the Sentry SDK installed via Composer
require 'vendor/autoload.php';

init(['dsn' => 'https://$APPLICATION_TOKEN@$INGESTING_HOST/1' ]);

// Example of capturing an exception
try {
    throw new \Exception("This is a test error from PHP!");
} catch (\Exception $e) {
    captureException($e);
}

See the error in Better Stack

After running the script, you should see your first report in Errors ๐Ÿš€

First error in Better stack