Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry integration for service #458

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion files/install-deps-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@
name:
- git+https://github.com/packit-service/sandcastle.git
- persistentdict
- sentry-sdk==0.14.1
executable: pip3
2 changes: 2 additions & 0 deletions files/install-deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
- persistentdict
# temporary workaround for sake of marhsmallow
- git+https://github.com/packit-service/packit.git
- sentry-sdk==0.14.2
- sentry-sdk[flask]==0.14.2
executable: pip3
24 changes: 5 additions & 19 deletions packit_service/celerizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from celery import Celery
from os import getenv

from celery import Celery

def configure_sentry():
""" Optionally returns sentry client """
secret_key = getenv("SENTRY_SECRET")
if not secret_key:
return

# so that we don't have to have sentry sdk installed locally
import sentry_sdk

# https://docs.sentry.io/platforms/python/celery/
from sentry_sdk.integrations.celery import CeleryIntegration

sentry_sdk.init(
secret_key, integrations=[CeleryIntegration()], environment=getenv("DEPLOYMENT")
)
with sentry_sdk.configure_scope() as scope:
scope.set_tag("runner-type", "packit-worker")
from packit_service.sentry_integration import configure_sentry


class Celerizer:
Expand All @@ -64,4 +48,6 @@ def celery_app(self):

celerizer = Celerizer()
celery_app = celerizer.celery_app
configure_sentry()
configure_sentry(
runner_type="packit-worker", celery_integration=True, sqlalchemy_integration=True
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,47 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from contextlib import contextmanager
from os import getenv


def configure_sentry(
runner_type: str,
celery_integration: bool = False,
flask_integration: bool = False,
sqlalchemy_integration: bool = False,
) -> None:
secret_key = getenv("SENTRY_SECRET")
if not secret_key:
return

# so that we don't have to have sentry sdk installed locally
import sentry_sdk

integrations = []

if celery_integration:
# https://docs.sentry.io/platforms/python/celery/
Copy link
Contributor

@csomh csomh Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These URLs are very well placed. Thanks! 👨‍🎤

from sentry_sdk.integrations.celery import CeleryIntegration

integrations.append(CeleryIntegration())

if flask_integration:
# https://docs.sentry.io/platforms/python/flask/
from sentry_sdk.integrations.flask import FlaskIntegration

integrations.append(FlaskIntegration())

if sqlalchemy_integration:
# https://docs.sentry.io/platforms/python/sqlalchemy/
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration

integrations.append(SqlalchemyIntegration())

sentry_sdk.init(
secret_key, integrations=integrations, environment=getenv("DEPLOYMENT"),
)
with sentry_sdk.configure_scope() as scope:
scope.set_tag("runner-type", runner_type)


def send_to_sentry(ex):
Expand Down
8 changes: 8 additions & 0 deletions packit_service/service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@
from packit.utils import set_logging

from packit_service.config import ServiceConfig
from packit_service.sentry_integration import configure_sentry
from packit_service.service.api import blueprint
from packit_service.service.views import builds_blueprint

set_logging(logger_name="packit_service", level=logging.DEBUG)

configure_sentry(
runner_type="packit-service",
celery_integration=True,
sqlalchemy_integration=True,
flask_integration=True,
)

application = Flask(__name__)
application.register_blueprint(blueprint)
application.register_blueprint(builds_blueprint)
Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/build/copr_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
from packit_service.service.models import CoprBuild as RedisCoprBuild
from packit_service.service.urls import get_log_url, get_srpm_log_url
from packit_service.worker import sentry_integration
from packit_service import sentry_integration
from packit_service.worker.build.build_helper import BaseBuildJobHelper
from packit_service.worker.result import HandlerResults

Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/handlers/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from packit_service.config import ServiceConfig
from packit_service.service.events import Event
from packit_service.worker.result import HandlerResults
from packit_service.worker.sentry_integration import push_scope_to_sentry
from packit_service.sentry_integration import push_scope_to_sentry

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/handlers/github_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
PushGitHubEvent,
)
from packit_service.service.models import Installation
from packit_service.worker import sentry_integration
from packit_service import sentry_integration
from packit_service.worker.build import CoprBuildJobHelper
from packit_service.worker.handlers import (
CommentActionHandler,
Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/testing_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
from packit_service.worker.build import CoprBuildJobHelper
from packit_service.worker.result import HandlerResults
from packit_service.worker.sentry_integration import send_to_sentry
from packit_service.sentry_integration import send_to_sentry

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_release_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from packit_service.config import ServiceConfig
from packit_service.constants import SANDCASTLE_WORK_DIR
from packit_service.worker import sentry_integration
from packit_service import sentry_integration
from packit_service.worker.jobs import SteveJobs
from packit_service.worker.whitelist import Whitelist
from tests.spellbook import DATA_DIR
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_copr_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from packit_service.config import ServiceConfig
from packit_service.models import CoprBuild, SRPMBuild
from packit_service.service.models import CoprBuild as RedisCoprBuild
from packit_service.worker import sentry_integration
from packit_service import sentry_integration
from packit_service.worker.build.copr_build import CoprBuildJobHelper
from packit_service.worker.parser import Parser
from packit_service.worker.reporting import StatusReporter
Expand Down