Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ github:
owner: getsentry
repo: sentry-python
targets:
- name: github
- name: pypi
- name: github
- name: gh-pages
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pip-log.txt
.idea
.eggs
venv
.venv
.vscode/tags
.pytest_cache
.hypothesis
Expand Down
18 changes: 12 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ matrix:
- python: "3.8-dev"
dist: xenial
sudo: true
- python: "3.6"

- name: Linting
python: "3.6"
install:
- pip install tox
script: tox -e linters
- python: "3.6"
env: DIST=1
script: make dist
after_success:
- npm install -g @zeus-ci/cli
- zeus upload -t "application/zip+wheel" dist/*
name: Distribution packages
install: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of optimization: I don't think we need Rust and tox for this job.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

script: make travis-upload-dist
- python: "3.6"
name: Build documentation
install: false
script: make travis-upload-docs

install:
- curl https://sh.rustup.rs -sSf | sh -s -- -y
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@ apidocs:
@pip install pdoc pygments
@pdoc --overwrite --html --html-dir build/apidocs sentry_sdk
.PHONY: apidocs

install-zeus-cli:
npm install -g @zeus-ci/cli
.PHONY: install-zeus-cli

travis-upload-docs:
@pip install --editable .
$(MAKE) apidocs
cd build/apidocs && zip -r gh-pages ./sentry_sdk
$(MAKE) install-zeus-cli
zeus upload -t "application/zip+docs" build/apidocs/gh-pages.zip
.PHONY: travis-upload-docs

travis-upload-dist: dist
$(MAKE) install-zeus-cli
zeus upload -t "application/zip+wheel" dist/*
.PHONY: travis-upload-dist
96 changes: 58 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,46 @@

Install this package with ``pip install sentry-sdk``. Then, in your code:

import sentry_sdk
sentry_sdk.init(dsn="https://foo@sentry.io/123")
```python
import sentry_sdk
sentry_sdk.init(dsn="https://foo@sentry.io/123")
```

After initialization, you can capture exceptions like this:

sentry_sdk.capture_exception(ValueError())
```python
sentry_sdk.capture_exception(ValueError())

try:
raise ValueError()
except Exception:
sentry_sdk.capture_exception()
try:
raise ValueError()
except Exception:
sentry_sdk.capture_exception()
```

...or send messages:

sentry_sdk.capture_message("Hi Sentry!")
```python
sentry_sdk.capture_message("Hi Sentry!")
```

## Scopes (contexts, tags)

You can create a scope to attach data to all events happening inside of it:

with sentry_sdk.Hub.current.push_scope():
with sentry_sdk.configure_scope() as scope:
scope.transaction = "my_view_name"
scope.set_tag("key", "value")
scope.user = {"id": 123}

# ValueError event will have all that data attached
capture_exception(ValueError())
```python
with sentry_sdk.Hub.current.push_scope():
with sentry_sdk.configure_scope() as scope:
scope.transaction = "my_view_name"
scope.set_tag("key", "value")
scope.user = {"id": 123}

# This one not since it is outside of the context manager
# ValueError event will have all that data attached
capture_exception(ValueError())

# This one not since it is outside of the context manager
capture_exception(ValueError())
```

Scopes can be nested. If you call ``push_scope`` inside of the
``with``-statement again, that scope will be pushed onto a stack. It will also
inherit all data from the outer scope.
Expand All @@ -56,23 +64,29 @@ inherit all data from the outer scope.
If you never call ``init``, no data will ever get sent to any server. In such
situations, code like this is essentially deadweight:

with sentry_sdk.configure_scope() as scope:
scope.user = _get_user_data()
```python
with sentry_sdk.configure_scope() as scope:
scope.user = _get_user_data()
```

Sentry-Python supports an alternative syntax for configuring a scope that
solves this problem:

@sentry_sdk.configure_scope
def _(scope):
scope.user = _get_user_data()
```python
@sentry_sdk.configure_scope
def _(scope):
scope.user = _get_user_data()
```

Your function will just not be executed if there is no client configured.

In your testing and development environment you still might want to run that
code without sending any events. In that case, simply call ``init`` without a
DSN:

sentry_sdk.init()
```python
sentry_sdk.init()
```

### Breadcrumbs

Expand All @@ -81,23 +95,27 @@ anywhere in your system ends up as a breadcrumb, see [the logging
docs](./docs/logging.md) for more information. You can, however, also create
breadcrumbs manually:

sentry_sdk.add_breadcrumb(
timestamp=datetime.datetime.now(),
type="log",
level="debug",
# message="hi",
# category="myapp.models",
})
```python
sentry_sdk.add_breadcrumb(
timestamp=datetime.datetime.now(),
type="log",
level="debug",
# message="hi",
# category="myapp.models",
})
```

You can also pass a callback to `add_breadcrumb` like so:

sentry_sdk.add_breadcrumb(lambda: {
"timestamp": datetime.datetime.now(),
"type": "log",
"level": "debug",
# "message": "hi",
# "category": "myapp.models",
})
```python
sentry_sdk.add_breadcrumb(lambda: {
"timestamp": datetime.datetime.now(),
"type": "log",
"level": "debug",
# "message": "hi",
# "category": "myapp.models",
})
```

The callback will only be called if a sentry client is configured.

Expand All @@ -118,7 +136,9 @@ Currently Sentry-Python does not send any personally-identifiable user data
with events by default. You need to explicitly enable this behavior with the
``send_default_pii`` option passed to ``init``:

init(..., send_default_pii=True)
```python
init(..., send_default_pii=True)
```

## Integrations

Expand Down