Skip to content

Commit b947b7c

Browse files
xvilopdelewski
andauthored
Enable or disabled auto instrumentation (#137)
* Enable or disabled auto instrumentation This is done through the OpenTelemetry\SDK\Sdk::isInstrumentationDisabled method * Add NAME public constant to instrumentation classes * Implement class_exist * Introduce warning * Remove unrelated changes * Remove balnk line * Suppress psalm warnings * Add configuration documentation --------- Co-authored-by: Przemyslaw Delewski <[email protected]>
1 parent 3432ae4 commit b947b7c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,14 @@ From Symfony subdirectory:
4949
$ composer install
5050
$ ./vendor/bin/phpunit tests
5151
```
52+
53+
## Configuration
54+
55+
Parts of this auto-instrumentation library can be configured, more options are available throught the
56+
[General SDK Configuration](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#general-sdk-configuration):
57+
58+
| Name | Default value | Values | Example | Description |
59+
|-------------------------------------|---------------|-------------------------|---------|---------------------------------------------------------------------------------|
60+
| OTEL_PHP_DISABLED_INSTRUMENTATIONS | [] | Instrumentation name(s) | symfony | Disable one or more installed auto-instrumentations, names are comma seperated. |
61+
62+
Configurations can be provided as environment variables, or via `php.ini` (or a file included by `php.ini`)

_register.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
use OpenTelemetry\Contrib\Instrumentation\Symfony\HttpClientInstrumentation;
66
use OpenTelemetry\Contrib\Instrumentation\Symfony\SymfonyInstrumentation;
7+
use OpenTelemetry\SDK\Sdk;
8+
9+
if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(SymfonyInstrumentation::NAME) === true) {
10+
return;
11+
}
712

813
if (extension_loaded('otel_instrumentation') === false) {
914
trigger_error('The otel_instrumentation extension must be loaded in order to autoload the OpenTelemetry Laravel auto-instrumentation', E_USER_WARNING);

src/SymfonyInstrumentation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
final class SymfonyInstrumentation
2121
{
22+
public const NAME = 'symfony';
23+
2224
public static function register(): void
2325
{
2426
$instrumentation = new CachedInstrumentation('io.opentelemetry.contrib.php.symfony');

0 commit comments

Comments
 (0)