Chalice

Learn about using Sentry with Chalice.

Install

Install sentry-sdk from PyPI with the chalice extra:

Copied
pip install "sentry-sdk[chalice]"

Configure

If you have the chalice package in your dependencies, the Chalice integration will be enabled automatically when you initialize the Sentry SDK.

Copied
import sentry_sdk

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    # ___PRODUCT_OPTION_END___ profiling
    # ___PRODUCT_OPTION_START___ logs

    # Enable logs to be sent to Sentry
    enable_logs=True,
    # ___PRODUCT_OPTION_END___ logs
)

Verify

Copied
from chalice import Chalice

sentry_sdk.init(...)  # as above

app = Chalice(app_name="helloworld")

@app.schedule(Rate(1, unit=Rate.MINUTES))
def every_minute(event):
    1 / 0  # raises an error

@app.route("/")
def index():
    1 / 0  # raises an error
    return {"hello": "world"}

When you enter the "/" route or the scheduled task is run, an error event will be sent to sentry.io.

Behavior

  • Request data is attached to all events: HTTP method, URL, headers, form data, JSON payloads. Sentry excludes raw bodies and multipart file uploads. Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set send_default_pii to True.

  • Each request has a separate scope. Changes to the scope within a view, for example setting a tag, will only apply to events sent as part of the request being handled.

Supported Versions

  • Chalice: 1.16.0+
  • Python: 3.6+
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").