Skip to content

Commit

Permalink
Add minimal Sentry configuration
Browse files Browse the repository at this point in the history
Set up trace telemetry for Butler server using Sentry, to allow debugging of performance issues in the deployed server.
  • Loading branch information
dhirving committed Nov 15, 2024
1 parent 90fca1a commit 3186277
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/lsst/daf/butler/remote_butler/server/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
from .._errors import serialize_butler_user_error
from ..server_models import CLIENT_REQUEST_ID_HEADER_NAME, ERROR_STATUS_CODE, ErrorResponseModel
from ._config import load_config
from ._telemetry import enable_telemetry
from .handlers._external import external_router
from .handlers._external_query import query_router
from .handlers._internal import internal_router

configure_logging(name="lsst.daf.butler.remote_butler.server")
configure_uvicorn_logging()
enable_telemetry()


def create_app() -> FastAPI:
Expand Down
38 changes: 38 additions & 0 deletions python/lsst/daf/butler/remote_butler/server/_telemetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is part of daf_butler.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (http://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This software is dual licensed under the GNU General Public License and also
# under a 3-clause BSD license. Recipients may choose which of these licenses
# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
# respectively. If you choose the GPL option then the following text applies
# (but note that there is still no warranty even if you opt for BSD instead):
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


def enable_telemetry() -> None:
try:
import sentry_sdk
except ImportError:
return

# Configuration will be pulled from SENTRY_* environment variables
# (see https://docs.sentry.io/platforms/python/configuration/options/).
# If SENTRY_DSN is not present, telemetry is disabled.
sentry_sdk.init(enable_tracing=True)
1 change: 1 addition & 0 deletions requirements/docker.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ lsst-daf-relation

# Server-only dependencies
uvicorn
sentry-sdk[fastapi, sqlalchemy]
8 changes: 8 additions & 0 deletions requirements/docker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ certifi==2024.8.30 \
# httpcore
# httpx
# requests
# sentry-sdk
cffi==1.17.1 \
--hash=sha256:045d61c734659cc045141be4bae381a41d89b741f795af1dd018bfb532fd0df8 \
--hash=sha256:0984a4925a435b1da406122d4d7968dd861c1385afe3b45ba82b750f229811e2 \
Expand Down Expand Up @@ -368,6 +369,7 @@ fastapi==0.115.5 \
# via
# -r ./main.in
# safir
# sentry-sdk
fastavro==1.9.7 \
--hash=sha256:0b2f9bafa167cb4d1c3dd17565cb5bf3d8c0759e42620280d1760f1e778e07fc \
--hash=sha256:13e11c6cb28626da85290933027cd419ce3f9ab8e45410ef24ce6b89d20a1f6c \
Expand Down Expand Up @@ -1031,6 +1033,10 @@ safir-logging==6.5.1 \
--hash=sha256:b056306de26627e29bd6a6d04b1144456a1319ec0e15a67ebbc12b43362a27cd \
--hash=sha256:ff591f0247fda10842835e714a6dbf601a894432d33d6d98e20fe035a5ad952c
# via safir
sentry-sdk[fastapi,sqlalchemy]==2.18.0 \
--hash=sha256:0dc21febd1ab35c648391c664df96f5f79fb0d92d7d4225cd9832e53a617cafd \
--hash=sha256:ee70e27d1bbe4cd52a38e1bd28a5fadb9b17bc29d91b5f2b97ae29c0a7610442
# via -r ./docker.in
six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
Expand Down Expand Up @@ -1102,6 +1108,7 @@ sqlalchemy==2.0.36 \
# via
# -r ./main.in
# lsst-daf-relation
# sentry-sdk
starlette==0.41.2 \
--hash=sha256:9834fd799d1a87fd346deb76158668cfa0b0d56f85caefe8268e2d97c3468b62 \
--hash=sha256:fbc189474b4731cf30fcef52f18a8d070e3f3b46c6a04c97579e85e6ffca942d
Expand Down Expand Up @@ -1140,6 +1147,7 @@ urllib3==2.2.3 \
# botocore
# lsst-resources
# requests
# sentry-sdk
uvicorn==0.32.0 \
--hash=sha256:60b8f3a5ac027dcd31448f411ced12b5ef452c646f76f02f8cc3f25d8d26fd82 \
--hash=sha256:f78b36b143c16f54ccdb8190d0a26b5f1901fe5a3c777e1ab29f26391af8551e
Expand Down
3 changes: 1 addition & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,8 @@ def test_auth_check(self):
# authentication headers is working. It doesn't test actual server
# functionality -- in a real deployment, the authentication headers are
# handled by GafaelfawrIngress, not our app.
with self.assertRaises(UnhandledServerError) as cm:
with self.assertRaises(UnhandledServerError):
self.client.get("/v1/dataset_type/int")
self.assertEqual(cm.exception.__cause__.status_code, 401)

def test_exception_logging(self):
app = create_app()
Expand Down

0 comments on commit 3186277

Please sign in to comment.