diff --git a/.craft.yml b/.craft.yml index 69c3aeac38..4e9f4b9f44 100644 --- a/.craft.yml +++ b/.craft.yml @@ -3,5 +3,6 @@ github: owner: getsentry repo: sentry-python targets: - - name: github - name: pypi + - name: github + - name: gh-pages diff --git a/.gitignore b/.gitignore index 98b9276183..2f5460f8d5 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ pip-log.txt .idea .eggs venv +.venv .vscode/tags .pytest_cache .hypothesis diff --git a/.travis.yml b/.travis.yml index e46f934bf0..d74faac832 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 + 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 diff --git a/Makefile b/Makefile index 5d1dec52e2..815752ea8b 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index fe9f3aee5b..0e12d97cd5 100644 --- a/README.md +++ b/README.md @@ -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. @@ -56,15 +64,19 @@ 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. @@ -72,7 +84,9 @@ 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 @@ -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. @@ -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