Skip to content

Commit

Permalink
[#31] Use sentry-sdk client
Browse files Browse the repository at this point in the history
  • Loading branch information
Siecje committed Apr 9, 2019
1 parent 1bff3f2 commit d2f30d1
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 38 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Mauro De Giorgi (mdgart)
Julian Perelli (jperelli)
Peter Bittner (bittner)
Forest Gregg (fgregg)
Cody Scott (siecje)
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ v0.1.0, 07/25/2014 -- Fix syntax error in nginx parser (07/03/2013; released 1y
v0.2.0, 06/10/2016 -- Add --sentryconfig option, add static code analysis (flake8, pylint) and integration tests
v0.3.0, 07/14/2017 -- Use entry_point.console_scripts for script setup, use relative imports in script module
v0.4.0, 11/05/2018 -- Update interface for extended message, add real tests
v0.5.0, 04/05/2019 -- Use sentry-sdk client
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
raven = ">=3.3.2"
sentry-sdk = ">=0.7.9,<1.0.0"
tailhead = ">=1.0.2"

[dev-packages]
Expand Down
53 changes: 37 additions & 16 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
raven>=3.3.2
sentry-sdk>=0.7.9,<1.0.0
tailhead>=1.0.2
8 changes: 0 additions & 8 deletions sentrylogs/conf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +0,0 @@
"""
Configuration of Sentry Logs
"""
from raven import Client

from .settings import SENTRY_DSN

client = Client(dsn=SENTRY_DSN) # pylint: disable=invalid-name
5 changes: 5 additions & 0 deletions sentrylogs/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
"""
import os

import sentry_sdk


# absolute path to nginx error .log file
NGINX_ERROR_PATH = os.environ.get('NGINX_ERROR_PATH',
'/var/log/nginx/error.log')

SENTRY_DSN = os.environ.get('SENTRY_DSN', None)
if not SENTRY_DSN:
raise SystemExit('No Sentry DSN found!')

sentry_sdk.init(SENTRY_DSN)
16 changes: 6 additions & 10 deletions sentrylogs/helpers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
"""
Helper functions for Sentry Logs
"""
from .conf import client
from sentry_sdk import capture_message, configure_scope


def send_message(message, params, site, logger):
"""Send a message to the Sentry server"""
client.capture(
'Message',
message=message,
params=tuple(params),
data={
'site': site,
'logger': logger,
},
)
msg = message % params
with configure_scope() as scope:
scope.set_extra('site', site)
scope.set_extra('logger', logger)
capture_message(msg)
4 changes: 2 additions & 2 deletions sentrylogs/parsers/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def parse(self, line):
'Client: %s\n' \
'Host: %s\n' \
'Upstream: %s\n'
self.params = [
self.params = (
date_time_message[2],
date_time_message[0],
date_time_message[1],
Expand All @@ -59,5 +59,5 @@ def parse(self, line):
otherinfo.get("client", "-"),
otherinfo.get("host", "-"),
otherinfo.get("upstream", "-"),
]
)
self.site = otherinfo.get("referrer", "-")

0 comments on commit d2f30d1

Please sign in to comment.