File tree 3 files changed +27
-18
lines changed
ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask
opentelemetry-auto-instrumentation
src/opentelemetry/auto_instrumentation
3 files changed +27
-18
lines changed Original file line number Diff line number Diff line change @@ -160,9 +160,9 @@ def __init__(self):
160
160
super ().__init__ ()
161
161
self ._original_flask = None
162
162
163
- def _instrument (self ):
163
+ def _instrument (self , ** kwargs ):
164
164
self ._original_flask = flask .Flask
165
165
flask .Flask = _InstrumentedFlask
166
166
167
- def _uninstrument (self ):
167
+ def _uninstrument (self , ** kwargs ):
168
168
flask .Flask = self ._original_flask
Original file line number Diff line number Diff line change 26
26
class BaseInstrumentor (ABC ):
27
27
"""An ABC for instrumentors"""
28
28
29
- def __init__ (self ):
30
- self ._is_instrumented = False
29
+ _instance = None
30
+ _is_instrumented = False
31
+
32
+ def __new__ (cls ):
33
+
34
+ if cls ._instance is None :
35
+ cls ._instance = object .__new__ (cls )
36
+
37
+ return cls ._instance
31
38
32
39
@abstractmethod
33
- def _instrument (self ) -> None :
40
+ def _instrument (self , ** kwargs ) :
34
41
"""Instrument"""
35
42
36
43
@abstractmethod
37
- def _uninstrument (self ) -> None :
44
+ def _uninstrument (self , ** kwargs ) :
38
45
"""Uninstrument"""
39
46
40
- def instrument (self ) -> None :
47
+ def instrument (self , ** kwargs ) :
41
48
"""Instrument"""
42
49
43
50
if not self ._is_instrumented :
44
- result = self ._instrument ()
51
+ result = self ._instrument (** kwargs )
45
52
self ._is_instrumented = True
46
53
return result
47
54
48
55
_LOG .warning ("Attempting to instrument while already instrumented" )
49
56
50
57
return None
51
58
52
- def uninstrument (self ) -> None :
59
+ def uninstrument (self , ** kwargs ) :
53
60
"""Uninstrument"""
54
61
55
62
if self ._is_instrumented :
56
- result = self ._uninstrument ()
63
+ result = self ._uninstrument (** kwargs )
57
64
self ._is_instrumented = False
58
65
return result
59
66
Original file line number Diff line number Diff line change 20
20
21
21
22
22
class TestInstrumentor (TestCase ):
23
- def test_protect (self ):
24
- class Instrumentor (BaseInstrumentor ):
25
- def _instrument (self ):
26
- return "instrumented"
23
+ class Instrumentor (BaseInstrumentor ):
24
+ def _instrument (self , ** kwargs ):
25
+ return "instrumented"
27
26
28
- def _uninstrument (self ):
29
- return "uninstrumented"
27
+ def _uninstrument (self , ** kwargs ):
28
+ return "uninstrumented"
30
29
31
- instrumentor = Instrumentor ()
30
+ def test_protect (self ):
31
+ instrumentor = self .Instrumentor ()
32
32
33
33
with self .assertLogs (level = WARNING ):
34
34
self .assertIs (instrumentor .uninstrument (), None )
35
35
36
36
self .assertEqual (instrumentor .instrument (), "instrumented" )
37
-
38
37
with self .assertLogs (level = WARNING ):
39
38
self .assertIs (instrumentor .instrument (), None )
40
39
41
40
self .assertEqual (instrumentor .uninstrument (), "uninstrumented" )
42
41
43
42
with self .assertLogs (level = WARNING ):
44
43
self .assertIs (instrumentor .uninstrument (), None )
44
+
45
+ def test_singleton (self ):
46
+ self .assertIs (self .Instrumentor (), self .Instrumentor ())
You can’t perform that action at this time.
0 commit comments