---
title: "Falcon"
description: "Learn about using Sentry with Falcon."
url: https://docs.sentry.io/platforms/python/integrations/falcon/
---

# Falcon | Sentry for Python

The Falcon integration adds support for the [Falcon web framework](https://falconframework.org/). The integration has been confirmed to work with Falcon 1.4 and 2.0.

## [Install](https://docs.sentry.io/platforms/python/integrations/falcon.md#install)

Install `sentry-sdk` from PyPI:

```bash
pip install sentry-sdk
```

## [Configure](https://docs.sentry.io/platforms/python/integrations/falcon.md#configure)

If you have the `falcon` package in your dependencies, the Falcon integration will be enabled automatically when you initialize the Sentry SDK.

Error Monitoring\[ ]Tracing\[ ]Profiling\[ ]Logs

```python
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](https://docs.sentry.io/platforms/python/integrations/falcon.md#verify)

```python
import falcon

sentry_sdk.init(...)  # same as above

class HelloWorldResource:
    def on_get(self, req, resp):
        message = {
            'hello': "world",
        }
        1 / 0  # raises an error
        resp.media = message

app = falcon.App()
app.add_route('/', HelloWorldResource())
```

When you point your browser to <http://localhost:8000/> a transaction will be created in the Performance section of [sentry.io](https://sentry.io). Additionally, an error event will be sent to [sentry.io](https://sentry.io) and will be connected to the transaction.

It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).

## [Behavior](https://docs.sentry.io/platforms/python/integrations/falcon.md#behavior)

##### uWSGI and Sentry SDK

If you're using uWSGI, note that it doesn't support threads by default. This might lead to unexpected behavior when using the Sentry SDK, from features not working properly to uWSGI workers crashing.

To enable threading support in uWSGI, make sure you have both `--enable-threads` and `--py-call-uwsgi-fork-hooks` on.

Note that automatic tracing on file-like responses when `offloading` is configured is disabled (see [here](https://github.com/getsentry/sentry-python/pull/5556) for why). If you wish to enable tracing on these types of responses, you will need to manually instrument them.

* The Sentry Python SDK will install the Falcon integration for all of your apps. The integration hooks into the base `falcon.API` class via monkey patching.

* All exceptions leading to an Internal Server Error are reported.

* 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.

## [Options](https://docs.sentry.io/platforms/python/integrations/falcon.md#options)

By adding `FalconIntegration` to your `sentry_sdk.init()` call explicitly, you can set options for `FalconIntegration` to change its behavior:

```python
import sentry_sdk
from sentry_sdk.integrations.falcon import FalconIntegration

sentry_sdk.init(
    # same as above
    integrations=[
        FalconIntegration(
            transaction_style="path",
        ),
    ],
)
```

You can pass the following keyword arguments to `FalconIntegration()`:

* `transaction_style`:

  ```python
  class MessageResource:
      def on_get(self, req, resp, message_id):
          msg = database.get_message(message_id)
          resp.media = msg.as_json()

  app = falcon.API()
  app.add_route("/message/{message_id}", MessageResource())
  ```

  In the above code, you would set the transaction to:

  * `/myurl/b48a7686-ad8c-4c94-8c3b-412ec7f25db2123` if you set `transaction_style="path"`.
  * `/myurl/{message_id}` if you set `transaction_style="uri_template"`

  The default is `"uri_template"`.

## [Supported Versions](https://docs.sentry.io/platforms/python/integrations/falcon.md#supported-versions)

* Falcon: 1.4+
* Python: 3.6+

The versions above apply for the current major version of the Python SDK. If you're looking to use Sentry with older Python or framework versions, consider using an older major version of the SDK.
