diff options
| author | David Cramer <dcramer@gmail.com> | 2016-11-10 12:16:29 +0900 |
|---|---|---|
| committer | David Cramer <dcramer@gmail.com> | 2016-11-10 16:11:42 +0900 |
| commit | 2b2c45bc53a22be3c728bf5b5d5856bcc4a94d22 (patch) | |
| tree | 77d08f75019ac210694274e56b7e7b44dceab6db | |
| parent | 1b8792bcf3fe4a25a51093459e591618a628f50c (diff) | |
| download | raven-feature/repos.tar.gz | |
Add repos configurationfeature/repos
| -rw-r--r-- | docs/advanced.rst | 19 | ||||
| -rw-r--r-- | raven/base.py | 13 | ||||
| -rw-r--r-- | raven/utils/conf.py | 1 | ||||
| -rw-r--r-- | tests/base/tests.py | 18 |
4 files changed, 51 insertions, 0 deletions
diff --git a/docs/advanced.rst b/docs/advanced.rst index 47656f3..88c0e10 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -111,6 +111,25 @@ The following are valid arguments which may be passed to the Raven client: environment = 'staging' +.. describe:: repos + + This describes local repositories that are reflected in your source code:: + + repos = { + 'raven': { + # the name of the repository as registered in Sentry + 'name': 'getsentry/raven-python', + # the prefix where the local source code is found in the repo + 'prefix': 'src', + } + } + + The repository key can either be a module name or the absolute path. When + a module name is given it will be automatically converted to its absolute path. + + For more information, see the :doc:`repos interface <../../../interfaces/repos>` + docs. + .. describe:: exclude_paths Extending this allow you to ignore module prefixes when we attempt to diff --git a/raven/base.py b/raven/base.py index 7809823..2c0d877 100644 --- a/raven/base.py +++ b/raven/base.py @@ -187,6 +187,7 @@ class Client(object): self.tags = o.get('tags') or {} self.environment = o.get('environment') or None self.release = o.get('release') or os.environ.get('HEROKU_SLUG_COMMIT') + self.repos = self._format_repos(o.get('repos')) self.transaction = TransactionStack() self.ignore_exceptions = set(o.get('ignore_exceptions') or ()) @@ -217,6 +218,17 @@ class Client(object): self.hook_libraries(hook_libraries) + def _format_repos(self, value): + if not value: + return {} + result = {} + for path, config in iteritems(value): + if path[0] != '/': + # assume its a module + path = os.path.abspath(__import__(path).__file__) + result[path] = config + return result + def set_dsn(self, dsn=None, transport=None): if not dsn and os.environ.get('SENTRY_DSN'): msg = "Configuring Raven from environment variable 'SENTRY_DSN'" @@ -465,6 +477,7 @@ class Client(object): data.setdefault('event_id', event_id) data.setdefault('platform', PLATFORM_NAME) data.setdefault('sdk', SDK_VALUE) + data.setdefault('repos', self.repos) # insert breadcrumbs if self.enable_breadcrumbs: diff --git a/raven/utils/conf.py b/raven/utils/conf.py index 4cf8c0d..ff1a21f 100644 --- a/raven/utils/conf.py +++ b/raven/utils/conf.py @@ -50,6 +50,7 @@ def convert_options(settings, defaults=None): options.setdefault('context', getopt('context')) options.setdefault('tags', getopt('tags')) options.setdefault('release', getopt('release')) + options.setdefault('repos', getopt('repos')) options.setdefault('environment', getopt('environment')) options.setdefault('ignore_exceptions', getopt('ignore_exceptions')) diff --git a/tests/base/tests.py b/tests/base/tests.py index cb988da..092c0ae 100644 --- a/tests/base/tests.py +++ b/tests/base/tests.py @@ -568,3 +568,21 @@ class ClientTest(TestCase): assert not frames[1]['in_app'] assert not frames[2]['in_app'] assert frames[3]['in_app'] + + def test_repos_configuration(self): + client = Client(repos={ + '/foo/bar': { + 'name': 'repo', + }, + 'raven': { + 'name': 'getsentry/raven-python', + }, + }) + assert client.repos == { + '/foo/bar': { + 'name': 'repo', + }, + os.path.abspath(raven.__file__): { + 'name': 'getsentry/raven-python', + }, + } |
