Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Getting Started falcon #7885

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. There is nothing to do for you except initializing the Sentry SDK.
antonpirker marked this conversation as resolved.
Show resolved Hide resolved

<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 in the Performance section of [sentry.io](https://sentry.io) will be created. Additionally an error event will be sent to [sentry.io](https://sentry.io) and will be connected to the transaction.
antonpirker marked this conversation as resolved.
Show resolved Hide resolved

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` explicitly to your `sentry_sdk.init()` call you can set options for `FalconIntegration` to change its behavior:
antonpirker marked this conversation as resolved.
Show resolved Hide resolved

```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+)
Loading