Skip to content

Commit

Permalink
Do not trace health check endpoint
Browse files Browse the repository at this point in the history
Avoid cluttering trace logs by not tracking the health check endpoint.
  • Loading branch information
dhirving committed Nov 15, 2024
1 parent 928ff22 commit 632e7cd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/lsst/daf/butler/remote_butler/server/_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Any


def enable_telemetry() -> None:
"""Turn on upload of trace telemetry to Sentry, to allow performance
Expand All @@ -38,4 +40,14 @@ def enable_telemetry() -> None:
# 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)
sentry_sdk.init(enable_tracing=True, traces_sampler=_decide_whether_to_sample_trace)

Check warning on line 43 in python/lsst/daf/butler/remote_butler/server/_telemetry.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/remote_butler/server/_telemetry.py#L43

Added line #L43 was not covered by tests


def _decide_whether_to_sample_trace(context: dict[str, Any]) -> float:
asgi_scope = context.get("asgi_scope")

Check warning on line 47 in python/lsst/daf/butler/remote_butler/server/_telemetry.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/remote_butler/server/_telemetry.py#L47

Added line #L47 was not covered by tests
if asgi_scope is not None:
# Do not log health check endpoint.
if asgi_scope.get("path") == "/":
return 0

Check warning on line 51 in python/lsst/daf/butler/remote_butler/server/_telemetry.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/remote_butler/server/_telemetry.py#L51

Added line #L51 was not covered by tests

return 1

Check warning on line 53 in python/lsst/daf/butler/remote_butler/server/_telemetry.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/remote_butler/server/_telemetry.py#L53

Added line #L53 was not covered by tests

0 comments on commit 632e7cd

Please sign in to comment.