mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #26390 from zircote/feature/add-tags-to-sentry-log-handler
Provides tagging of Sentry LogHandler events.
This commit is contained in:
commit
65a29e60d6
1 changed files with 17 additions and 4 deletions
|
@ -13,7 +13,8 @@
|
|||
logging handler to be available.
|
||||
|
||||
Configuring the python `Sentry`_ client, `Raven`_, should be done under the
|
||||
``sentry_handler`` configuration key.
|
||||
``sentry_handler`` configuration key. Additional `context` may be provided
|
||||
for coresponding grain item(s).
|
||||
At the bare minimum, you need to define the `DSN`_. As an example:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
@ -33,7 +34,12 @@
|
|||
project: app-id
|
||||
public_key: deadbeefdeadbeefdeadbeefdeadbeef
|
||||
secret_key: beefdeadbeefdeadbeefdeadbeefdead
|
||||
|
||||
context:
|
||||
- os
|
||||
- master
|
||||
- saltversion
|
||||
- cpuarch
|
||||
- ec2.tags.environment
|
||||
|
||||
All the client configuration keys are supported, please see the
|
||||
`Raven client documentation`_.
|
||||
|
@ -101,7 +107,6 @@ def setup_handlers():
|
|||
if 'sentry_handler' not in __opts__:
|
||||
log.debug('No \'sentry_handler\' key was found in the configuration')
|
||||
return False
|
||||
|
||||
options = {}
|
||||
dsn = get_config_value('dsn')
|
||||
if dsn is not None:
|
||||
|
@ -178,7 +183,15 @@ def setup_handlers():
|
|||
})
|
||||
|
||||
client = raven.Client(**options)
|
||||
|
||||
context = get_config_value('context')
|
||||
context_dict = {}
|
||||
if context is not None:
|
||||
for tag in context:
|
||||
tag_value = __salt__['grains.get'](tag)
|
||||
if len(tag_value) > 0:
|
||||
context_dict[tag] = tag_value
|
||||
if len(context_dict) > 0:
|
||||
client.context.merge({'tags': context_dict})
|
||||
try:
|
||||
handler = SentryHandler(client)
|
||||
handler.setLevel(LOG_LEVELS[get_config_value('log_level', 'error')])
|
||||
|
|
Loading…
Add table
Reference in a new issue