|
1 | 1 | from typing import Dict, Any, Tuple, Type, Optional, Union, List, Callable |
2 | 2 | import types |
3 | 3 | import sys |
| 4 | +import warnings |
4 | 5 |
|
5 | 6 | from bugsnag.breadcrumbs import BreadcrumbType, OnBreadcrumbCallback |
6 | 7 | from bugsnag.feature_flags import FeatureFlag |
|
13 | 14 | ExcInfoType = Tuple[Type, Exception, types.TracebackType] |
14 | 15 |
|
15 | 16 |
|
16 | | -__all__ = ('configure', 'configure_request', 'add_metadata_tab', |
17 | | - 'clear_request_config', 'notify', 'start_session', 'auto_notify', |
18 | | - 'auto_notify_exc_info', 'before_notify', 'leave_breadcrumb') |
| 17 | +__all__ = ( |
| 18 | + 'configure', |
| 19 | + 'configure_request', |
| 20 | + 'add_metadata_tab', |
| 21 | + 'clear_request_config', |
| 22 | + 'notify', |
| 23 | + 'start_session', |
| 24 | + 'auto_notify', |
| 25 | + 'auto_notify_exc_info', |
| 26 | + 'before_notify', |
| 27 | + 'leave_breadcrumb', |
| 28 | +) |
19 | 29 |
|
20 | 30 |
|
21 | 31 | def configure(**options): |
22 | 32 | """ |
23 | 33 | Configure the Bugsnag notifier application-wide settings. |
24 | 34 | """ |
25 | | - return configuration.configure(**options) |
| 35 | + # Synchronize legacy references to point at the live configuration |
| 36 | + # only `logger` is rebound in this scope |
| 37 | + global logger |
| 38 | + |
| 39 | + # Delegate to the module-local configuration instance so we update the |
| 40 | + # single source of truth without resolving package submodules that may |
| 41 | + # shadow the attribute name. |
| 42 | + result = configuration.configure(**options) |
| 43 | + try: |
| 44 | + default_client.configuration = configuration |
| 45 | + except (AttributeError, TypeError, ImportError) as exc: |
| 46 | + try: |
| 47 | + configuration.logger.debug( |
| 48 | + "legacy configuration sync failed: %s", exc |
| 49 | + ) |
| 50 | + except Exception: |
| 51 | + warnings.warn( |
| 52 | + f"legacy configuration sync failed: {exc}", stacklevel=2 |
| 53 | + ) |
| 54 | + |
| 55 | + logger = configuration.logger |
| 56 | + |
| 57 | + # Also update the `bugsnag` package attributes so other modules that |
| 58 | + # reference `bugsnag.configuration` / `bugsnag.logger` reflect the |
| 59 | + # live configuration object (keeps package-level attributes in sync). |
| 60 | + try: |
| 61 | + import bugsnag as _pkg |
| 62 | + setattr(_pkg, 'configuration', configuration) |
| 63 | + setattr(_pkg, 'logger', configuration.logger) |
| 64 | + except (ImportError, AttributeError, TypeError) as exc: |
| 65 | + try: |
| 66 | + configuration.logger.debug( |
| 67 | + "legacy package attr sync failed: %s", exc |
| 68 | + ) |
| 69 | + except Exception: |
| 70 | + warnings.warn( |
| 71 | + f"legacy package attr sync failed: {exc}", stacklevel=2 |
| 72 | + ) |
| 73 | + |
| 74 | + return result |
26 | 75 |
|
27 | 76 |
|
28 | 77 | def configure_request(**options): |
|
0 commit comments