Skip to content

Commit 2d49b74

Browse files
Allow new integration setup on the instance with config options (#5047)
### Description Currently `setup_once` is called without any arguments so cannot access either the SDK init `options` or the integration specific init arguments on the instance. This PR enables a separate backwards compat optional `setup_once_with_options` as an **instance** method. Note that we we will use this rarely but I need it to unblock the OTLPIntegration since I need the DSN there. #### Example before ```python sentry_sdk.init(dsn="") class FooIntegration(Integration): def __init__(self, bar=42): self.bar = bar @staticmethod def setup_once(): self.bar # Not available options.dsn # Not available ``` after ```python def setup_once_with_options(self, options=None): self.bar options.dsn ``` --------- Co-authored-by: Ivana Kellyer <[email protected]>
1 parent 3e86962 commit 2d49b74

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pip-wheel-metadata
2929
.mypy_cache
3030
.vscode/
3131
.claude/
32+
.tool-versions
3233

3334
# for running AWS Lambda tests using AWS SAM
3435
sam.template.yaml

sentry_sdk/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def _capture_envelope(envelope):
409409
"auto_enabling_integrations"
410410
],
411411
disabled_integrations=self.options["disabled_integrations"],
412+
options=self.options,
412413
)
413414

414415
spotlight_config = self.options.get("spotlight")

sentry_sdk/integrations/__init__.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import Set
1616
from typing import Type
1717
from typing import Union
18+
from typing import Any
1819

1920

2021
_DEFAULT_FAILED_REQUEST_STATUS_CODES = frozenset(range(500, 600))
@@ -171,12 +172,13 @@ def iter_default_integrations(with_auto_enabling_integrations):
171172

172173

173174
def setup_integrations(
174-
integrations,
175-
with_defaults=True,
176-
with_auto_enabling_integrations=False,
177-
disabled_integrations=None,
175+
integrations, # type: Sequence[Integration]
176+
with_defaults=True, # type: bool
177+
with_auto_enabling_integrations=False, # type: bool
178+
disabled_integrations=None, # type: Optional[Sequence[Union[type[Integration], Integration]]]
179+
options=None, # type: Optional[Dict[str, Any]]
178180
):
179-
# type: (Sequence[Integration], bool, bool, Optional[Sequence[Union[type[Integration], Integration]]]) -> Dict[str, Integration]
181+
# type: (...) -> Dict[str, Integration]
180182
"""
181183
Given a list of integration instances, this installs them all.
182184
@@ -221,6 +223,7 @@ def setup_integrations(
221223
)
222224
try:
223225
type(integration).setup_once()
226+
integration.setup_once_with_options(options)
224227
except DidNotEnable as e:
225228
if identifier not in used_as_default_integration:
226229
raise
@@ -300,3 +303,10 @@ def setup_once():
300303
instance again.
301304
"""
302305
pass
306+
307+
def setup_once_with_options(self, options=None):
308+
# type: (Optional[Dict[str, Any]]) -> None
309+
"""
310+
Called after setup_once in rare cases on the instance and with options since we don't have those available above.
311+
"""
312+
pass

0 commit comments

Comments
 (0)