Skip to content

Commit

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

* Apply suggestions from code review

Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com>

---------

Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com>
  • Loading branch information
antonpirker and shanamatthews committed Sep 20, 2023
1 parent 68c37ce commit 33454f5
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/platforms/python/guides/sanic/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,14 @@ redirect_from:
description: "Learn about using Sentry with Sanic."
---

The Sanic integration adds support for the [Sanic Web Framework](https://sanicframework.org). We support the following versions, which are known to work with the SDK:

- `0.8`
- `18.12 LTS`
- `19.12 LTS`
- `21.3`, `21.6`, `21.9`, `21.12 LTS`
- `22.6

_\* Starting with Sanic v21, `sentry-sdk` v1.3.0 or higher is required_

The SDK will support any Sanic version of the form `x.12` (LTS versions). If the latest version of Sanic is not explicitly listed here, it _might_ not be supported.

A Python version of 3.6 or greater is also required.
The Sanic integration adds support for the [Sanic Web Framework](https://sanic.dev/).

## Install

Install `sentry-sdk` from PyPI:
Install `sentry-sdk` from PyPI with the `sanic` extra:

```bash
pip install --upgrade sentry-sdk
pip install --upgrade sentry-sdk[sanic]
```

If you're on Python 3.6, you also need the `aiocontextvars` package:
Expand All @@ -35,30 +23,42 @@ pip install --upgrade aiocontextvars

## Configure

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

<SignInNote />

```python
import sentry_sdk
from sentry_sdk.integrations.sanic import SanicIntegration
from sanic import Sanic
import sentry_sdk

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

# 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,
)

app = Sanic(__name__)
```

## Verify

```python
from sanic import Sanic
from sanic.response import text

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

app = Sanic(__name__)

@app.get("/")
async def hello_world(request):
1 / 0 # raises an error
return text("Hello, world.")`
```

When you point your browser to [http://localhost:8000/](http://localhost:8000/) an error event will be sent to [sentry.io](https://sentry.io).

## Behavior

- The Sentry Python SDK will install the Sanic integration for all of your apps.
Expand All @@ -72,3 +72,8 @@ app = Sanic(__name__)
- Logging with any logger will create breadcrumbs when
the [Logging](/platforms/python/guides/logging/)
integration is enabled (done by default).

## Supported Versions

- Sanic: 0.8+
- Python: 3.6+ (Sanic 0.8+), 3.7+ (Sanic 21.0+)

0 comments on commit 33454f5

Please sign in to comment.