Skip to content

Commit 36ef8cb

Browse files
committed
Take _installed_integrations into account, sometimes
1 parent c447df0 commit 36ef8cb

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

sentry_sdk/integrations/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,21 @@ def _enable_integration(integration: "Integration") -> None:
292292
logger.debug("Integration already enabled: %s", identifier)
293293
return
294294

295-
logger.debug("Setting up integration %s", identifier)
296-
_processed_integrations.add(identifier)
297-
try:
298-
type(integration).setup_once()
299-
integration.setup_once_with_options(client.options)
300-
except DidNotEnable as e:
301-
logger.debug("Did not enable integration %s: %s", identifier, e)
302-
return
295+
if identifier not in _installed_integrations or identifier == "asyncio":
296+
# Asyncio is special because it patches the currently running event
297+
# loop. _installed_integrations, on the other hand, prevents
298+
# re-patching on the process level.
299+
logger.debug("Setting up integration %s", identifier)
300+
_processed_integrations.add(identifier)
301+
try:
302+
type(integration).setup_once()
303+
integration.setup_once_with_options(client.options)
304+
except DidNotEnable as e:
305+
logger.debug("Did not enable integration %s: %s", identifier, e)
306+
return
307+
308+
_installed_integrations.add(identifier)
303309

304-
_installed_integrations.add(identifier)
305310
client.integrations[integration.identifier] = integration
306311

307312

sentry_sdk/integrations/asyncio.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def enable_asyncio_integration(*args: "Any", **kwargs: "Any") -> None:
147147
This is useful in scenarios where Sentry needs to be initialized before
148148
an event loop is set up, but you still want to instrument asyncio once there
149149
is an event loop. In that case, you can sentry_sdk.init() early on without
150-
the AsyncioIntegration and then, once the event loop has been set up, execute
150+
the AsyncioIntegration and then, once the event loop has been set up,
151+
execute:
151152
152153
```python
153154
from sentry_sdk.integrations.asyncio import enable_asyncio_integration
@@ -158,8 +159,9 @@ async def async_entrypoint():
158159
159160
Any arguments provided will be passed to AsyncioIntegration() as is.
160161
161-
If AsyncioIntegration is already enabled (e.g. because it was provided in
162-
sentry_sdk.init(integrations=[...])), this function won't have any effect.
162+
If AsyncioIntegration is already enabled on the current client (e.g. because
163+
it was provided in sentry_sdk.init(integrations=[...])), this function won't
164+
have any effect.
163165
164166
If AsyncioIntegration was provided in
165167
sentry_sdk.init(disabled_integrations=[...]), this function will ignore that

0 commit comments

Comments
 (0)