@@ -25,7 +25,7 @@ class _TestInstrumentNonExistingFunctionOnModule(AbstractInstrumentedModule):
2525class _TestInstrumentNonExistingMethod (AbstractInstrumentedModule ):
2626 name = "test_non_existing_method_instrumentation"
2727 instrument_list = [
28- ("dict " , "non_existing_method" ),
28+ ("logging " , "Logger. non_existing_method" ),
2929 ]
3030
3131
@@ -47,36 +47,54 @@ def test_instrument_nonexisting_method_on_module():
4747 _TestInstrumentNonExistingFunctionOnModule ().instrument ()
4848
4949
50- def test_instrument_nonexisting_method ():
51- _TestInstrumentNonExistingMethod ().instrument ()
50+ def test_instrument_nonexisting_method (caplog ):
51+ with caplog .at_level (logging .DEBUG , 'elasticapm.instrument' ):
52+ _TestInstrumentNonExistingMethod ().instrument ()
53+ record = caplog .records [0 ]
54+ assert 'has no attribute' in record .message
5255
5356
5457@pytest .mark .skipif (compat .PY3 , reason = "different object model" )
55- def test_uninstrument_py2 ():
58+ def test_uninstrument_py2 (caplog ):
5659 assert isinstance (Dummy .dummy , types .MethodType )
5760 assert not isinstance (Dummy .dummy , wrapt .BoundFunctionWrapper )
5861
5962 instrumentation = _TestDummyInstrumentation ()
60- instrumentation .instrument ()
63+ with caplog .at_level (logging .DEBUG , 'elasticapm.instrument' ):
64+ instrumentation .instrument ()
65+ record = caplog .records [0 ]
66+ assert "Instrumented" in record .message
67+ assert record .args == ('test_dummy_instrument' , 'tests.instrumentation.base_tests.Dummy.dummy' )
6168 assert isinstance (Dummy .dummy , wrapt .BoundFunctionWrapper )
6269
63- instrumentation .uninstrument ()
70+ with caplog .at_level (logging .DEBUG , 'elasticapm.instrument' ):
71+ instrumentation .uninstrument ()
72+ record = caplog .records [1 ]
73+ assert "Uninstrumented" in record .message
74+ assert record .args == ('test_dummy_instrument' , 'tests.instrumentation.base_tests.Dummy.dummy' )
6475 assert isinstance (Dummy .dummy , types .MethodType )
6576 assert not isinstance (Dummy .dummy , wrapt .BoundFunctionWrapper )
6677
6778
6879@pytest .mark .skipif (compat .PY2 , reason = "different object model" )
69- def test_uninstrument_py3 ():
80+ def test_uninstrument_py3 (caplog ):
7081 original = Dummy .dummy
7182 assert not isinstance (Dummy .dummy , wrapt .BoundFunctionWrapper )
7283
7384 instrumentation = _TestDummyInstrumentation ()
74- instrumentation .instrument ()
75-
85+ with caplog .at_level (logging .DEBUG , 'elasticapm.instrument' ):
86+ instrumentation .instrument ()
87+ record = caplog .records [0 ]
88+ assert "Instrumented" in record .message
89+ assert record .args == ('test_dummy_instrument' , 'tests.instrumentation.base_tests.Dummy.dummy' )
7690 assert Dummy .dummy is not original
7791 assert isinstance (Dummy .dummy , wrapt .BoundFunctionWrapper )
7892
79- instrumentation .uninstrument ()
93+ with caplog .at_level (logging .DEBUG , 'elasticapm.instrument' ):
94+ instrumentation .uninstrument ()
95+ record = caplog .records [1 ]
96+ assert "Uninstrumented" in record .message
97+ assert record .args == ('test_dummy_instrument' , 'tests.instrumentation.base_tests.Dummy.dummy' )
8098 assert Dummy .dummy is original
8199 assert not isinstance (Dummy .dummy , wrapt .BoundFunctionWrapper )
82100
@@ -97,10 +115,13 @@ def test_module_method_args(elasticapm_client):
97115 assert call_args == ('tests.instrumentation.base_tests' , 'Dummy.dummy' )
98116
99117
100- def test_skip_instrument_env_var ():
118+ def test_skip_instrument_env_var (caplog ):
101119 instrumentation = _TestDummyInstrumentation ()
102- with mock .patch .dict ('os.environ' , {'SKIP_INSTRUMENT_TEST_DUMMY_INSTRUMENT' : 'foo' }):
120+ with mock .patch .dict ('os.environ' , {'SKIP_INSTRUMENT_TEST_DUMMY_INSTRUMENT' : 'foo' }),\
121+ caplog .at_level (logging .DEBUG , 'elasticapm.instrument' ):
103122 instrumentation .instrument ()
123+ record = caplog .records [0 ]
124+ assert 'Skipping' in record .message
104125 assert not instrumentation .instrumented
105126
106127
0 commit comments