@@ -10,4 +10,64 @@ Experimental Python SDK
10
10
11
11
[ ![ Build Status] ( https://travis-ci.com/getsentry/sentry-python.svg?branch=master )] ( https://travis-ci.com/getsentry/sentry-python )
12
12
13
- Do not use me yet, use raven-python instead for now.
13
+ *** Sentry-Python is an experimental SDK for Sentry.*** For a stable one, use
14
+ [ raven] ( https://github.com/getsentry/raven-python ) .
15
+
16
+ # Getting started with the new Sentry SDK for Python
17
+
18
+ Install this package with `` pip install sentry-sdk `` . Then, in your code:
19
+
20
+ import sentry_sdk
21
+ sentry_sdk.init(dsn="https://[email protected] /123")
22
+
23
+ After initialization, you can capture exceptions like this:
24
+
25
+ sentry_sdk.capture_exception(ValueError())
26
+
27
+ try:
28
+ raise ValueError()
29
+ except Exception:
30
+ sentry_sdk.capture_exception()
31
+
32
+ ...or send messages:
33
+
34
+ sentry_sdk.capture_message("Hi Sentry!")
35
+
36
+ ## Scopes (contexts, tags)
37
+
38
+ You can create a scope to attach data to all events happening inside of it:
39
+
40
+ with sentry_sdk.get_current_hub().push_scope():
41
+ with sentry_sdk.configure_scope() as scope:
42
+ scope.transaction = "my_view_name"
43
+ scope.set_tag("key", "value")
44
+ scope.user = {"id": 123}
45
+
46
+ # ValueError event will have all that data attached
47
+ capture_exception(ValueError())
48
+
49
+ # This one not since it is outside of the context manager
50
+ capture_exception(ValueError())
51
+
52
+ Scopes can be nested. If you call `` push_scope `` inside of the
53
+ `` with `` -statement again, that scope will be pushed onto a stack. It will also
54
+ inherit all data from the outer scope.
55
+
56
+ ### Breadcrumbs
57
+
58
+ Breadcrumbs also live on the stack. By default any (non-debug) log message
59
+ anywhere in your system ends up as a breadcrumb, see [ the logging
60
+ docs] ( ./docs/logging.md ) for more information. You can, however, also create
61
+ breadcrumbs manually:
62
+
63
+ sentry_sdk.add_breadcrumb({
64
+ # "ty": "log",
65
+ # "level": "debug",
66
+ # "category": "myapp.models",
67
+ "message": "hi"
68
+ })
69
+
70
+ ## Integrations
71
+
72
+ Head over to [ the other pages] ( ./docs/ ) to check out integrations, which use
73
+ these low-level APIs so you don't have to.
0 commit comments