From 0b42e8d26238410dd5a860b81dd815700f8b2e78 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 21 Sep 2023 08:43:28 +0200 Subject: [PATCH] Python: Getting Started falcon (#7885) * Python: Getting Started falcon * style(lint): Auto commit lint changes * Apply suggestions from code review Co-authored-by: Shana Matthews --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: Shana Matthews --- src/platforms/python/guides/falcon/index.mdx | 58 +++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/src/platforms/python/guides/falcon/index.mdx b/src/platforms/python/guides/falcon/index.mdx index e393aabbdcc4d..7d05607999bb0 100644 --- a/src/platforms/python/guides/falcon/index.mdx +++ b/src/platforms/python/guides/falcon/index.mdx @@ -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. ```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. @@ -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`: @@ -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+)