⏱ Estimated Time To Completion: 10 minutes

Understand the basics

Before diving into advanced configurations, ensure you have completed the basic setup as outlined in the Quickstart guide. The advanced configurations build upon the initial setup.

Custom configuration is achieved by adjusting the Sentry init call in your project; options vary by language/framework. For a full list of options and more information, refer to the official Sentry documentation.

Below we provide some common examples and recommended configuration options.

Example: Customizing Sentry Initialization for NextJS

sentry.client.config.ts
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: process.env.DECIPHER_DSN, // Replace with your Decipher DSN.
  integrations: [
    // Capture session replay data.
    Sentry.replayIntegration({
      maskAllText: false,
      maskAllInputs: false,
      blockAllMedia: false,
    }),
    // Capture request bodies for failed HTTP requests.
    Sentry.httpClientIntegration()
  ],
  tracesSampleRate: 1.0, // Adjust based on your needs.
  replaysSessionSampleRate: 0.5, // Adjust session replay sample rate.
  replaysOnErrorSampleRate: 1.0, // Ensure all error sessions are captured.
  beforeSend(event) {
    // Modify or drop events before sending them to Decipher
    if (event.exception) {
      // For example, filter out non-production errors.
      // (You can also do this via the `enabled` param.)
      if (process.env.NODE_ENV !== 'production') {
        return null;
      }
    }
    return event;
  },
});

Example: Customizing Sentry Initialization for a Python/Flask project

app.py
import os
import logging
from flask import Flask
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

# Initialize the Flask app
app = Flask(__name__)

# Configure Sentry logging integration
sentry_logging = LoggingIntegration(
    level=logging.INFO,        # Capture info and above as breadcrumbs
    event_level=logging.ERROR  # Send errors as events
)

# Initialize Sentry
sentry_sdk.init(
    dsn=os.environ.get("DECIPHER_DSN"),  # Replace with your Decipher DSN.
    integrations=[FlaskIntegration(), sentry_logging],
    traces_sample_rate=float(os.getenv("TRACES_SAMPLE_RATE", 0.1)),  # Adjust sample rate.
    environment=os.getenv("FLASK_ENV", "development"),
    release=os.getenv("RELEASE_VERSION"),
    send_default_pii=True,  # Enable sending personally identifiable information (PII).
    debug=os.getenv("SENTRY_DEBUG", False)  # Enable debug mode based on environment variable.
)

@app.route('/')
def hello():
    return "Hello, World!"

@app.route('/error')
def trigger_error():
    division_by_zero = 1 / 0  # This will trigger an error and be captured by Sentry
    return "This won't be reached."

# ... other app initialization, routes, and code here

if __name__ == "__main__":
    app.run()