Skip to content

Commit

Permalink
fix: sentry client is None
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl0ven committed Feb 27, 2023
1 parent a2a8aa0 commit 2751b82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
- pyflakes==2.4.0

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
args: ["-m=VERTICAL_HANGING_INDENT", "--combine-as", "--profile=black"]
Expand Down
3 changes: 3 additions & 0 deletions sentry_dynamic_sampling_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def init_wrapper():
sentry_sdk: sentry_sdk_type = importlib.import_module("sentry_sdk")
client = sentry_sdk.Hub.current.client

if client is None:
return

if CONTROLLER_HOST:
app_key = build_app_key(client.options)
controller_endpoint = urljoin(CONTROLLER_HOST, CONTROLLER_PATH)
Expand Down
14 changes: 13 additions & 1 deletion tests/test_hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import Mock, patch
from unittest.mock import MagicMock, Mock, patch

import pytest

Expand Down Expand Up @@ -26,6 +26,18 @@ def test_init_wrapper_no_sentry(importlib_mock: Mock):
importlib_mock.import_module.assert_not_called()


@patch("sentry_dynamic_sampling_lib.importlib")
def test_init_wrapper_no_client(importlib_mock: Mock):
importlib_mock.util.find_spec.return_value = True
sentry_sdk = MagicMock()
sentry_sdk.Hub.current.client = None
importlib_mock.import_module.return_value = sentry_sdk

init_wrapper()
importlib_mock.util.find_spec.assert_called_once_with("sentry_sdk")
importlib_mock.import_module.assert_called_once_with("sentry_sdk")


@patch("sentry_dynamic_sampling_lib.TraceSampler")
@patch("sentry_dynamic_sampling_lib.importlib")
def test_init_wrapper_no_controller(importlib_mock: Mock, trace_sampler: Mock):
Expand Down

0 comments on commit 2751b82

Please sign in to comment.