Integrating using an AI prompt

The Integrate with AI section shows you a ready-made prompt for a simple integration of Better Stack error tracking into your app using Claude Code or Cursor.

  1. Navigate to Errors -> Applications -> Your application -> Data ingestion.
  2. Scroll to Integrate with AI and click on the prompt to copy it.
  3. Use it in Claude Code or similar tool to automatically integrate Better Stack into your application.

Integrate with AI

Not using Claude Code or similar agentic dev-tool?

You can integrate your app manually using Sentry SDK.

Examples

Even if you use an AI agent, it's helpful to see what the final integration code looks like. Here are a few examples of how to use the Sentry SDK:

JavaScript Python Ruby
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);
}
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)
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

Couldn't find example for your application?

Read the official Sentry SDK documentation for more languages. Make sure to change the DSN to send the data to Better Stack.

See the error in Better Stack

After running the prompt and triggering and error, you should see your first report in Errors 🚀

First error in Better stack