File tree 5 files changed +55
-0
lines changed
5 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 32
32
use Scoutapm \Logger \FilteredLogLevelDecorator ;
33
33
use Throwable ;
34
34
use function count ;
35
+ use function in_array ;
36
+ use function is_array ;
35
37
use function is_string ;
36
38
use function json_encode ;
37
39
use function sprintf ;
@@ -322,6 +324,16 @@ public function ignore() : void
322
324
$ this ->isIgnored = true ;
323
325
}
324
326
327
+ /** {@inheritDoc} */
328
+ public function shouldInstrument (string $ functionality ) : bool
329
+ {
330
+ $ disabledInstruments = $ this ->config ->get (ConfigKey::DISABLED_INSTRUMENTS );
331
+
332
+ return $ disabledInstruments === null
333
+ || ! is_array ($ disabledInstruments )
334
+ || ! in_array ($ functionality , $ disabledInstruments , true );
335
+ }
336
+
325
337
/** {@inheritDoc} */
326
338
public function changeRequestUri (string $ newRequestUri ) : void
327
339
{
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ public function __construct()
49
49
$ this ->coercions = [
50
50
ConfigKey::MONITORING_ENABLED => new CoerceBoolean (),
51
51
ConfigKey::IGNORED_ENDPOINTS => new CoerceJson (),
52
+ ConfigKey::DISABLED_INSTRUMENTS => new CoerceJson (),
52
53
];
53
54
}
54
55
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ abstract class ConfigKey
21
21
public const SCM_SUBDIRECTORY = 'scm_subdirectory ' ;
22
22
public const REVISION_SHA = 'revision_sha ' ;
23
23
public const HOSTNAME = 'hostname ' ;
24
+ public const DISABLED_INSTRUMENTS = 'disabled_instruments ' ;
24
25
public const CORE_AGENT_LOG_LEVEL = 'core_agent_log_level ' ;
25
26
public const CORE_AGENT_LOG_FILE = 'core_agent_log_file ' ;
26
27
public const CORE_AGENT_CONFIG_FILE = 'core_agent_config_file ' ;
@@ -52,6 +53,7 @@ public static function allConfigurationKeys() : array
52
53
self ::SCM_SUBDIRECTORY ,
53
54
self ::REVISION_SHA ,
54
55
self ::HOSTNAME ,
56
+ self ::DISABLED_INSTRUMENTS ,
55
57
self ::CORE_AGENT_LOG_LEVEL ,
56
58
self ::CORE_AGENT_LOG_FILE ,
57
59
self ::CORE_AGENT_CONFIG_FILE ,
Original file line number Diff line number Diff line change @@ -59,6 +59,14 @@ public function ignored(string $path) : bool;
59
59
*/
60
60
public function ignore () : void ;
61
61
62
+ /**
63
+ * Should the instrumentation be enabled for a particular functionality. This checks the `disabled_instruments`
64
+ * configuration - if an instrumentation is not explicitly disabled, this will return true.
65
+ *
66
+ * The list of functionality that can be disabled depends on the library binding being used.
67
+ */
68
+ public function shouldInstrument (string $ functionality ) : bool ;
69
+
62
70
/**
63
71
* If the automatically determined request URI is incorrect, please report an issue so we can investigate. You may
64
72
* override the automatic determination of the request URI by calling this method.
Original file line number Diff line number Diff line change @@ -345,6 +345,38 @@ public function testIgnoredEndpoints() : void
345
345
self ::assertFalse ($ agent ->ignored ('/bar ' ));
346
346
}
347
347
348
+ public function testInstrumentationIsNotDisabledWhenNoDisabledInstrumentsConfigured () : void
349
+ {
350
+ self ::assertTrue (
351
+ $ this ->agentFromConfigArray ([])
352
+ ->shouldInstrument ('some functionality ' )
353
+ );
354
+ }
355
+
356
+ public function testInstrumentationIsNotDisabledWhenDisabledInstrumentsConfigurationIsWrong () : void
357
+ {
358
+ self ::assertTrue (
359
+ $ this ->agentFromConfigArray ([ConfigKey::DISABLED_INSTRUMENTS => 'disabled functionality ' ])
360
+ ->shouldInstrument ('some functionality ' )
361
+ );
362
+ }
363
+
364
+ public function testInstrumentationIsNotDisabledWhenDisabledInstrumentsAreConfigured () : void
365
+ {
366
+ self ::assertTrue (
367
+ $ this ->agentFromConfigArray ([ConfigKey::DISABLED_INSTRUMENTS => '["disabled functionality"] ' ])
368
+ ->shouldInstrument ('some functionality ' )
369
+ );
370
+ }
371
+
372
+ public function testInstrumentationIsDisabledWhenDisabledInstrumentsAreConfigured () : void
373
+ {
374
+ self ::assertFalse (
375
+ $ this ->agentFromConfigArray ([ConfigKey::DISABLED_INSTRUMENTS => '["disabled functionality"] ' ])
376
+ ->shouldInstrument ('disabled functionality ' )
377
+ );
378
+ }
379
+
348
380
/** @throws Exception */
349
381
public function testMetadataExceptionsAreLogged () : void
350
382
{
You can’t perform that action at this time.
0 commit comments