Skip to content

Commit

Permalink
Merge branch 'r1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jhillacre committed Feb 19, 2020
2 parents 2d5321c + 989b7ff commit 7b635dd
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 134 deletions.
102 changes: 24 additions & 78 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ celerybeat.pid
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.env*
.venv*
env*/
venv*/
ENV*/
env*.bak/
venv*.bak/

# Spyder project settings
.spyderproject
Expand All @@ -128,77 +128,23 @@ dmypy.json
# Pyre type checker
.pyre/

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### custom JetBrains .gitignore rules.
### Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

## ignore all files
.idea/*

## except
!.idea/.gitignore

# know that there is a git repo in the root.
!.idea/vcs.xml

# enable the watcher task named "Black" by default.
!.idea/watcherTasks.xml

# have the "Black Scope" scope by default.
!.idea/scopes

### pretenders pids
*.pid
7 changes: 0 additions & 7 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/shy-sentry.iml

This file was deleted.

2 changes: 1 addition & 1 deletion shy_sentry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved
__version__ = "1.1.0"
__version__ = "1.1.1"

try:
from .shy_sentry import init, Guard
Expand Down
36 changes: 17 additions & 19 deletions shy_sentry/shy_sentry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved
import json
from contextlib import AbstractContextManager
from functools import wraps
from typing import ContextManager

from sentry_sdk import init as sentry_sdk_init
from sentry_sdk import Hub
from sentry_sdk import init as sentry_sdk_init
from sentry_sdk import serializer
from sentry_sdk._types import MYPY
from sentry_sdk.integrations.argv import ArgvIntegration
Expand All @@ -30,6 +30,19 @@ def patch_sentry():
serializer.MAX_DATABAG_DEPTH = 20


def get_our_default_integrations():
return [
LoggingIntegration(),
StdlibIntegration(),
ExcepthookIntegration(),
DedupeIntegration(),
AtexitIntegration(callback=default_callback),
ModulesIntegration(),
ArgvIntegration(),
ThreadingIntegration(),
]


def init(config_path=None, **kwargs):
if not config_path:
config_path = "./sentry_config.json"
Expand All @@ -44,32 +57,17 @@ def init(config_path=None, **kwargs):
# if you don't want to do stuff to default integrations, user our modified defaults that make things quiet
# otherwise, you are on your own to pass kwargs.
if "default_integrations" not in kwargs:
sentry_kwargs.update(
{
"default_integrations": False,
"integrations": [
LoggingIntegration(),
StdlibIntegration(),
ExcepthookIntegration(),
DedupeIntegration(),
AtexitIntegration(callback=default_callback),
ModulesIntegration(),
ArgvIntegration(),
ThreadingIntegration(),
],
}
)
sentry_kwargs.update({"default_integrations": False, "integrations": get_our_default_integrations()})
if "integrations" in kwargs:
sentry_kwargs["integrations"].extend(kwargs.pop("integrations"))
kwargs.pop("integrations")
sentry_kwargs.update(kwargs)

patch_sentry()

sentry_sdk_init(**sentry_kwargs)


class Guard(ContextManager):
class Guard(AbstractContextManager):
def __enter__(self):
pass

Expand Down
12 changes: 12 additions & 0 deletions tests/test_scripts/add_integrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved
import os
import sys

from sentry_sdk.integrations.redis import RedisIntegration

sys.path.append(os.getcwd())
import shy_sentry # noqa: E402


if __name__ == "__main__": # pragma: no branch
shy_sentry.init(integrations=[RedisIntegration()])
31 changes: 31 additions & 0 deletions tests/test_scripts/no_default_integrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved
import os
import sys

from sentry_sdk.integrations.argv import ArgvIntegration
from sentry_sdk.integrations.atexit import AtexitIntegration
from sentry_sdk.integrations.dedupe import DedupeIntegration
from sentry_sdk.integrations.excepthook import ExcepthookIntegration
from sentry_sdk.integrations.modules import ModulesIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.stdlib import StdlibIntegration
from sentry_sdk.integrations.threading import ThreadingIntegration

sys.path.append(os.getcwd())
import shy_sentry # noqa: E402


if __name__ == "__main__": # pragma: no branch
shy_sentry.init(
integrations=[
StdlibIntegration(),
ExcepthookIntegration(),
DedupeIntegration(),
AtexitIntegration(callback=shy_sentry.shy_sentry.default_callback),
ModulesIntegration(),
ArgvIntegration(),
ThreadingIntegration(),
RedisIntegration(),
],
default_integrations=False,
)
52 changes: 52 additions & 0 deletions tests/test_shy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved
import os
import subprocess
from contextlib import AbstractContextManager
from time import sleep
from unittest import TestCase
from unittest.mock import patch

import psutil
from pretenders.client.http import HTTPMock
Expand Down Expand Up @@ -109,3 +111,53 @@ def test_cwd_config(self):
self.do_test("./tests/test_scripts/cwd_config.py")
finally:
os.unlink("./sentry_config.json")


@patch("shy_sentry.shy_sentry.sentry_sdk_init")
class MockSentrySdkTestCase(TestCase):
def test_add_integrations(self, mocked_sentry_sdk_init):
from shy_sentry import init
from shy_sentry.shy_sentry import get_our_default_integrations
from sentry_sdk.integrations.redis import RedisIntegration

default_integrations = get_our_default_integrations()
integrations = [RedisIntegration()]
init(integrations=integrations, config_path="./tests/test_scripts/sentry_config.json")
mocked_sentry_sdk_init.assert_called_once()
self.assertEqual(len(mocked_sentry_sdk_init.call_args_list[0]), 2)
call_args, call_kwargs = mocked_sentry_sdk_init.call_args_list[0]
self.assertTupleEqual(call_args, ())
self.assertSetEqual(
{"default_integrations", "dsn", "environment", "integrations", "release"}, set(call_kwargs.keys()),
)
self.assertEqual(call_kwargs["default_integrations"], False)
self.assertEqual(call_kwargs["dsn"], "http://client_key@localhost:8888/mockhttp/mock_sentry/123456")
self.assertEqual(call_kwargs["environment"], "dev")
self.assertEqual(call_kwargs["release"], "project:branch@version")
self.assertSetEqual(
{x.__class__ for x in call_kwargs["integrations"]},
{x.__class__ for x in default_integrations + integrations},
)

def test_no_default_integrations(self, mocked_sentry_sdk_init):
from shy_sentry import init
from sentry_sdk.integrations.redis import RedisIntegration

integrations = [RedisIntegration()]
init(
default_integrations=False, integrations=integrations, config_path="./tests/test_scripts/sentry_config.json"
)
mocked_sentry_sdk_init.assert_called_once()
self.assertEqual(len(mocked_sentry_sdk_init.call_args_list[0]), 2)
call_args, call_kwargs = mocked_sentry_sdk_init.call_args_list[0]
self.assertTupleEqual(call_args, ())
self.assertSetEqual(
{"default_integrations", "dsn", "environment", "integrations", "release"}, set(call_kwargs.keys()),
)
self.assertEqual(call_kwargs["default_integrations"], False)
self.assertEqual(call_kwargs["dsn"], "http://client_key@localhost:8888/mockhttp/mock_sentry/123456")
self.assertEqual(call_kwargs["environment"], "dev")
self.assertEqual(call_kwargs["release"], "project:branch@version")
self.assertSetEqual(
{x.__class__ for x in call_kwargs["integrations"]}, {x.__class__ for x in integrations},
)

0 comments on commit 7b635dd

Please sign in to comment.