Skip to content

Commit

Permalink
Python: Getting Started falcon (#7885)
Browse files Browse the repository at this point in the history
* Python: Getting Started falcon

* style(lint): Auto commit lint changes

* Apply suggestions from code review

Co-authored-by: Shana Matthews <[email protected]>

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Co-authored-by: Shana Matthews <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2023
1 parent 6585e5d commit 0b42e8d
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions src/platforms/python/guides/falcon/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,53 @@ The integration has been confirmed to work with Falcon 1.4 and 2.0.
Install `sentry-sdk` from PyPI with the `falcon` extra:

```bash
pip install --upgrade 'sentry-sdk[falcon]==0.16.2'
pip install --upgrade 'sentry-sdk[falcon]'
```

## Configure

To configure the SDK, initialize it with the integration before your app has been initialized:
If you have the `falcon` package in your dependencies, the Falcon integration will be enabled automatically when you initialize the Sentry SDK.

<SignInNote />

```python
import falcon

import sentry_sdk
from sentry_sdk.integrations.falcon import FalconIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
integrations=[
FalconIntegration(),
],

# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production,
traces_sample_rate=1.0,
)

api = falcon.API()
```

## 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/](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

- 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.
Expand All @@ -54,6 +72,25 @@ api = falcon.API()

## 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(
dsn="___PUBLIC_DSN___",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
integrations = [
FalconIntegration(
transaction_style="path",
),
],
)
```

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

- `transaction_style`:
Expand All @@ -74,3 +111,8 @@ You can pass the following keyword arguments to `FalconIntegration()`:
- `/myurl/{message_id}` if you set `transaction_style="uri_template"`

The default is `"uri_template"`.

## Supported Versions

- Falcon: 1.4+
- Python: 2.7+ (Falcon 1.4+), 3.5+ (Falcon 3.0+)

1 comment on commit 0b42e8d

@vercel
Copy link

@vercel vercel bot commented on 0b42e8d Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sentry-docs – ./

sentry-docs.sentry.dev
sentry-docs-git-master.sentry.dev
docs.sentry.io

Please sign in to comment.