Skip to content

Commit c81d6f0

Browse files
feat(python): Add Typer integration docs (#12174)
--------- Co-authored-by: Alex Krawiec <[email protected]>
1 parent b4c53e8 commit c81d6f0

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

docs/platforms/python/integrations/index.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
117117
| <LinkWithPlatformIcon platform="python.asyncio" label="asyncio" url="/platforms/python/integrations/asyncio" /> | |
118118
| <LinkWithPlatformIcon platform="python.pure_eval" label="Enhanced Locals" url="/platforms/python/integrations/pure_eval" /> | |
119119
| <LinkWithPlatformIcon platform="python.gnu_backtrace" label="GNU Backtrace" url="/platforms/python/integrations/gnu_backtrace" /> | |
120-
| <LinkWithPlatformIcon platform="python.rust_tracing" label="Rust Tracing" url="/platforms/python/integrations/rust_tracing" /> | |
120+
| <LinkWithPlatformIcon platform="python.rust_tracing" label="Rust Tracing" url="/platforms/python/integrations/rust_tracing" /> | |
121121
| <LinkWithPlatformIcon platform="python.socket" label="Socket" url="/platforms/python/integrations/socket" /> | |
122122
| <LinkWithPlatformIcon platform="python.sys_exit" label="sys.exit" url="/platforms/python/integrations/sys_exit" /> | |
123123
| <LinkWithPlatformIcon platform="python.tryton" label="Tryton" url="/platforms/python/integrations/tryton" /> | |
124+
| <LinkWithPlatformIcon platform="python.typer" label="Typer" url="/platforms/python/integrations/typer" /> | |
124125
| <LinkWithPlatformIcon platform="python.wsgi" label="WSGI" url="/platforms/python/integrations/wsgi" /> | |
125126

126127
### Default Integrations
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Typer
3+
description: Learn how to use Sentry to capture Typer exceptions.
4+
---
5+
6+
The `TyperIntegration` captures exceptions raised when using [Typer CLI](https://typer.tiangolo.com/) applications.
7+
8+
## Install
9+
10+
Install Typer and the Sentry Python SDK.
11+
12+
```bash
13+
pip install --upgrade "sentry-sdk" typer
14+
```
15+
16+
## Configure
17+
18+
To enable the `TyperIntegration`, add it to the `integrations` list of your `sentry_sdk.init`.
19+
20+
```python
21+
import sentry_sdk
22+
from sentry_sdk.integrations.typer import TyperIntegration
23+
24+
sentry_sdk.init(
25+
dsn="___PUBLIC_DSN___",
26+
integrations=[TyperIntegration()],
27+
)
28+
```
29+
30+
## Verify
31+
32+
Create a small CLI application:
33+
34+
```python
35+
import typer
36+
import sentry_sdk
37+
from sentry_sdk.integrations.typer import TyperIntegration
38+
39+
sentry_sdk.init(
40+
dsn="___PUBLIC_DSN___",
41+
integrations=[TyperIntegration()],
42+
)
43+
44+
def main():
45+
1 / 0
46+
47+
if __name__ == "__main__":
48+
typer.run(main)
49+
```
50+
51+
When you run this, Sentry will capture the `ZeroDivisionError` from the `main()`
52+
function and you'll be able to see it on [sentry.io](https://sentry.io).

0 commit comments

Comments
 (0)