Skip to content

Commit f3428c5

Browse files
Laravel: added LaravelComponentProvider and LaravelConfiguration.
1 parent 1ba04c2 commit f3428c5

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\Contrib\Instrumentation\Laravel;
6+
7+
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\InstrumentationConfiguration;
8+
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
9+
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
10+
use OpenTelemetry\Config\SDK\Configuration\Context;
11+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
12+
13+
class LaravelComponentProvider implements ComponentProvider
14+
{
15+
public function createPlugin(array $properties, Context $context): InstrumentationConfiguration
16+
{
17+
return LaravelConfiguration::fromArray($properties);
18+
}
19+
20+
public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
21+
{
22+
$root = new ArrayNodeDefinition('laravel');
23+
24+
return $root
25+
->canBeDisabled()
26+
->addDefaultsIfNotSet()
27+
;
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\Contrib\Instrumentation\Laravel;
6+
7+
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\InstrumentationConfiguration;
8+
use OpenTelemetry\SDK\Sdk;
9+
10+
final class LaravelConfiguration implements InstrumentationConfiguration
11+
{
12+
private function __construct(
13+
public readonly bool $enabled,
14+
) {
15+
}
16+
17+
public static function fromArray(array $properties): self
18+
{
19+
return new self(
20+
enabled: $properties['enabled'] ?? (class_exists(Sdk::class) ? !Sdk::isDisabled() : true),
21+
);
22+
}
23+
24+
public static function default(): self
25+
{
26+
return self::fromArray([]);
27+
}
28+
}

0 commit comments

Comments
 (0)