File tree 2 files changed +57
-1
lines changed
2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 33
33
import threading
34
34
import time
35
35
import uuid
36
+ import warnings
36
37
from abc import ABC , abstractmethod
37
38
from collections import deque
38
39
@@ -213,7 +214,6 @@ def __init__(
213
214
):
214
215
# type: (...) -> None
215
216
self .scheduler = _scheduler if scheduler is None else scheduler
216
- self .hub = hub
217
217
218
218
self .event_id = uuid .uuid4 ().hex # type: str
219
219
@@ -240,6 +240,16 @@ def __init__(
240
240
241
241
self .unique_samples = 0
242
242
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
+
243
253
def update_active_thread_id (self ):
244
254
# type: () -> None
245
255
self .active_thread_id = get_current_thread_meta ()[0 ]
@@ -506,6 +516,26 @@ def valid(self):
506
516
507
517
return True
508
518
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
+
509
539
510
540
class Scheduler (ABC ):
511
541
mode = "unknown" # type: ProfilerMode
Original file line number Diff line number Diff line change 1
1
import inspect
2
2
import os
3
+ import sentry_sdk
3
4
import sys
4
5
import threading
5
6
import time
7
+ import warnings
6
8
from collections import defaultdict
7
9
from unittest import mock
8
10
@@ -813,3 +815,27 @@ def test_profile_processing(
813
815
assert processed ["frames" ] == expected ["frames" ]
814
816
assert processed ["stacks" ] == expected ["stacks" ]
815
817
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