File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 3333import threading
3434import time
3535import uuid
36+ import warnings
3637from abc import ABC , abstractmethod
3738from collections import deque
3839
@@ -213,7 +214,6 @@ def __init__(
213214 ):
214215 # type: (...) -> None
215216 self .scheduler = _scheduler if scheduler is None else scheduler
216- self .hub = hub
217217
218218 self .event_id = uuid .uuid4 ().hex # type: str
219219
@@ -240,6 +240,16 @@ def __init__(
240240
241241 self .unique_samples = 0
242242
243+ # Backwards compatibility with the old hub property
244+ self ._hub = None # type: Optional[sentry_sdk.Hub]
245+ if hub is not None :
246+ self ._hub = hub
247+ warnings .warn (
248+ "The `hub` parameter is deprecated. Please do not use it." ,
249+ DeprecationWarning ,
250+ stacklevel = 2 ,
251+ )
252+
243253 def update_active_thread_id (self ):
244254 # type: () -> None
245255 self .active_thread_id = get_current_thread_meta ()[0 ]
@@ -506,6 +516,26 @@ def valid(self):
506516
507517 return True
508518
519+ @property
520+ def hub (self ):
521+ # type: () -> Optional[sentry_sdk.Hub]
522+ warnings .warn (
523+ "The `hub` attribute is deprecated. Please do not access it." ,
524+ DeprecationWarning ,
525+ stacklevel = 2 ,
526+ )
527+ return self ._hub
528+
529+ @hub .setter
530+ def hub (self , value ):
531+ # type: (Optional[sentry_sdk.Hub]) -> None
532+ warnings .warn (
533+ "The `hub` attribute is deprecated. Please do not set it." ,
534+ DeprecationWarning ,
535+ stacklevel = 2 ,
536+ )
537+ self ._hub = value
538+
509539
510540class Scheduler (ABC ):
511541 mode = "unknown" # type: ProfilerMode
Original file line number Diff line number Diff line change 11import inspect
22import os
3+ import sentry_sdk
34import sys
45import threading
56import time
7+ import warnings
68from collections import defaultdict
79from unittest import mock
810
@@ -813,3 +815,27 @@ def test_profile_processing(
813815 assert processed ["frames" ] == expected ["frames" ]
814816 assert processed ["stacks" ] == expected ["stacks" ]
815817 assert processed ["samples" ] == expected ["samples" ]
818+
819+
820+ def test_hub_backwards_compatibility ():
821+ hub = sentry_sdk .Hub ()
822+
823+ with pytest .warns (DeprecationWarning ):
824+ profile = Profile (True , 0 , hub = hub )
825+
826+ with pytest .warns (DeprecationWarning ):
827+ assert profile .hub is hub
828+
829+ new_hub = sentry_sdk .Hub ()
830+
831+ with pytest .warns (DeprecationWarning ):
832+ profile .hub = new_hub
833+
834+ with pytest .warns (DeprecationWarning ):
835+ assert profile .hub is new_hub
836+
837+
838+ def test_no_warning_without_hub ():
839+ with warnings .catch_warnings ():
840+ warnings .simplefilter ("error" )
841+ Profile (True , 0 )
You can’t perform that action at this time.
0 commit comments