Skip to content

Commit 0e3d296

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 7f27ed4 commit 0e3d296

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,14 @@ From Laravel 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) | laravel | 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
@@ -3,6 +3,11 @@
33
declare(strict_types=1);
44

55
use OpenTelemetry\Contrib\Instrumentation\Laravel\LaravelInstrumentation;
6+
use OpenTelemetry\SDK\Sdk;
7+
8+
if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(LaravelInstrumentation::NAME) === true) {
9+
return;
10+
}
611

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

src/LaravelInstrumentation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
class LaravelInstrumentation
2424
{
25+
public const NAME = 'laravel';
2526
private static $watchersInstalled = false;
2627
private static $application;
2728

0 commit comments

Comments
 (0)