Skip to content

Commit e0418f1

Browse files
authored
Merge branch 'master' into dependabot/github_actions/codecov/codecov-action-5.1.1
2 parents 8cce644 + fe4b88b commit e0418f1

File tree

16 files changed

+563
-55
lines changed

16 files changed

+563
-55
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Automation: Notify issues for release"
2+
on:
3+
release:
4+
types:
5+
- published
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: Which version to notify issues for
10+
required: false
11+
12+
# This workflow is triggered when a release is published
13+
jobs:
14+
release-comment-issues:
15+
runs-on: ubuntu-20.04
16+
name: Notify issues
17+
steps:
18+
- name: Get version
19+
id: get_version
20+
run: echo "version=${{ github.event.inputs.version || github.event.release.tag_name }}" >> $GITHUB_OUTPUT
21+
22+
- name: Comment on linked issues that are mentioned in release
23+
if: |
24+
steps.get_version.outputs.version != ''
25+
&& !contains(steps.get_version.outputs.version, 'a')
26+
&& !contains(steps.get_version.outputs.version, 'b')
27+
&& !contains(steps.get_version.outputs.version, 'rc')
28+
uses: getsentry/release-comment-issues-gh-action@v1
29+
with:
30+
github_token: ${{ secrets.GITHUB_TOKEN }}
31+
version: ${{ steps.get_version.outputs.version }}

.github/workflows/release.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@ jobs:
1818
runs-on: ubuntu-latest
1919
name: "Release a new version"
2020
steps:
21+
- name: Get auth token
22+
id: token
23+
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
24+
with:
25+
app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }}
26+
private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }}
2127
- uses: actions/[email protected]
2228
with:
23-
token: ${{ secrets.GH_RELEASE_PAT }}
29+
token: ${{ steps.token.outputs.token }}
2430
fetch-depth: 0
2531
- name: Prepare release
2632
uses: getsentry/action-prepare-release@v1
2733
env:
28-
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_PAT }}
34+
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
2935
with:
3036
version: ${{ github.event.inputs.version }}
3137
force: ${{ github.event.inputs.force }}

.github/workflows/test-integrations-misc.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
python-version: ["3.6","3.8","3.12","3.13"]
30+
python-version: ["3.6","3.7","3.8","3.12","3.13"]
3131
# python3.6 reached EOL and is no longer being supported on
3232
# new versions of hosted runners on Github Actions
3333
# ubuntu-20.04 is the last version that supported python3.6
@@ -73,6 +73,10 @@ jobs:
7373
run: |
7474
set -x # print commands that are executed
7575
./scripts/runtox.sh "py${{ matrix.python-version }}-trytond-latest"
76+
- name: Test typer latest
77+
run: |
78+
set -x # print commands that are executed
79+
./scripts/runtox.sh "py${{ matrix.python-version }}-typer-latest"
7680
- name: Generate coverage XML (Python 3.6)
7781
if: ${{ !cancelled() && matrix.python-version == '3.6' }}
7882
run: |
@@ -153,6 +157,10 @@ jobs:
153157
run: |
154158
set -x # print commands that are executed
155159
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-trytond"
160+
- name: Test typer pinned
161+
run: |
162+
set -x # print commands that are executed
163+
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-typer"
156164
- name: Generate coverage XML (Python 3.6)
157165
if: ${{ !cancelled() && matrix.python-version == '3.6' }}
158166
run: |

requirements-linting.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ pre-commit # local linting
1717
httpcore
1818
openfeature-sdk
1919
launchdarkly-server-sdk
20+
typer

scripts/split-tox-gh-actions/split-tox-gh-actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"potel",
133133
"pure_eval",
134134
"trytond",
135+
"typer",
135136
],
136137
}
137138

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from sentry_sdk.flag_utils import flag_error_processor
2+
3+
import sentry_sdk
4+
from sentry_sdk.integrations import Integration
5+
6+
7+
class FeatureFlagsIntegration(Integration):
8+
"""
9+
Sentry integration for capturing feature flags on error events. To manually buffer flag data,
10+
call `integrations.featureflags.add_feature_flag`. We recommend you do this on each flag
11+
evaluation.
12+
13+
See the [feature flag documentation](https://develop.sentry.dev/sdk/expected-features/#feature-flags)
14+
for more information.
15+
16+
@example
17+
```
18+
import sentry_sdk
19+
from sentry_sdk.integrations.featureflags import FeatureFlagsIntegration, add_feature_flag
20+
21+
sentry_sdk.init(dsn="my_dsn", integrations=[FeatureFlagsIntegration()]);
22+
23+
add_feature_flag('my-flag', true);
24+
sentry_sdk.capture_exception(Exception('broke')); // 'my-flag' should be captured on this Sentry event.
25+
```
26+
"""
27+
28+
identifier = "featureflags"
29+
30+
@staticmethod
31+
def setup_once():
32+
# type: () -> None
33+
scope = sentry_sdk.get_current_scope()
34+
scope.add_error_processor(flag_error_processor)
35+
36+
37+
def add_feature_flag(flag, result):
38+
# type: (str, bool) -> None
39+
"""
40+
Records a flag and its value to be sent on subsequent error events by FeatureFlagsIntegration.
41+
We recommend you do this on flag evaluations. Flags are buffered per Sentry scope.
42+
"""
43+
flags = sentry_sdk.get_current_scope().flags
44+
flags.set(flag, result)

sentry_sdk/integrations/typer.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import sentry_sdk
2+
from sentry_sdk.utils import (
3+
capture_internal_exceptions,
4+
event_from_exception,
5+
)
6+
from sentry_sdk.integrations import Integration, DidNotEnable
7+
8+
from typing import TYPE_CHECKING
9+
10+
if TYPE_CHECKING:
11+
from typing import Callable
12+
from typing import Any
13+
from typing import Type
14+
from typing import Optional
15+
16+
from types import TracebackType
17+
18+
Excepthook = Callable[
19+
[Type[BaseException], BaseException, Optional[TracebackType]],
20+
Any,
21+
]
22+
23+
try:
24+
import typer
25+
except ImportError:
26+
raise DidNotEnable("Typer not installed")
27+
28+
29+
class TyperIntegration(Integration):
30+
identifier = "typer"
31+
32+
@staticmethod
33+
def setup_once():
34+
# type: () -> None
35+
typer.main.except_hook = _make_excepthook(typer.main.except_hook) # type: ignore
36+
37+
38+
def _make_excepthook(old_excepthook):
39+
# type: (Excepthook) -> Excepthook
40+
def sentry_sdk_excepthook(type_, value, traceback):
41+
# type: (Type[BaseException], BaseException, Optional[TracebackType]) -> None
42+
integration = sentry_sdk.get_client().get_integration(TyperIntegration)
43+
44+
# Note: If we replace this with ensure_integration_enabled then
45+
# we break the exceptiongroup backport;
46+
# See: https://github.com/getsentry/sentry-python/issues/3097
47+
if integration is None:
48+
return old_excepthook(type_, value, traceback)
49+
50+
with capture_internal_exceptions():
51+
event, hint = event_from_exception(
52+
(type_, value, traceback),
53+
client_options=sentry_sdk.get_client().options,
54+
mechanism={"type": "typer", "handled": False},
55+
)
56+
sentry_sdk.capture_event(event, hint=hint)
57+
58+
return old_excepthook(type_, value, traceback)
59+
60+
return sentry_sdk_excepthook

sentry_sdk/spotlight.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def capture_envelope(self, envelope):
6666

6767
SPOTLIGHT_JS_ENTRY_PATH = "/assets/main.js"
6868
SPOTLIGHT_JS_SNIPPET_PATTERN = (
69-
'<script type="module" crossorigin src="{}"></script>'
69+
"<script>window.__spotlight = {{ initOptions: {{ sidecarUrl: '{spotlight_url}', fullPage: false }} }};</script>\n"
70+
'<script type="module" crossorigin src="{spotlight_js_url}"></script>\n'
7071
)
7172
SPOTLIGHT_ERROR_PAGE_SNIPPET = (
7273
'<html><base href="{spotlight_url}">\n'
@@ -113,7 +114,8 @@ def spotlight_script(self):
113114
)
114115
urllib.request.urlopen(req)
115116
self._spotlight_script = SPOTLIGHT_JS_SNIPPET_PATTERN.format(
116-
spotlight_js_url
117+
spotlight_url=self._spotlight_url,
118+
spotlight_js_url=spotlight_js_url,
117119
)
118120
except urllib.error.URLError as err:
119121
sentry_logger.debug(
@@ -210,13 +212,13 @@ def setup_spotlight(options):
210212
if not isinstance(url, str):
211213
return None
212214

213-
if (
214-
settings is not None
215-
and settings.DEBUG
216-
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_ON_ERROR", "1"))
217-
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_MIDDLEWARE", "1"))
218-
):
219-
with capture_internal_exceptions():
215+
with capture_internal_exceptions():
216+
if (
217+
settings is not None
218+
and settings.DEBUG
219+
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_ON_ERROR", "1"))
220+
and env_to_bool(os.environ.get("SENTRY_SPOTLIGHT_MIDDLEWARE", "1"))
221+
):
220222
middleware = settings.MIDDLEWARE
221223
if DJANGO_SPOTLIGHT_MIDDLEWARE_PATH not in middleware:
222224
settings.MIDDLEWARE = type(middleware)(

tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ def reset_integrations():
184184
_installed_integrations.clear()
185185

186186

187+
@pytest.fixture
188+
def uninstall_integration():
189+
"""Use to force the next call to sentry_init to re-install/setup an integration."""
190+
191+
def inner(identifier):
192+
_processed_integrations.discard(identifier)
193+
_installed_integrations.discard(identifier)
194+
195+
return inner
196+
197+
187198
@pytest.fixture
188199
def sentry_init(request):
189200
def inner(*a, **kw):

tests/integrations/featureflags/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)