-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.php
61 lines (52 loc) · 1.7 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace OpenTelemetry\Config\SDK;
use Nevay\SPI\ServiceLoader;
use OpenTelemetry\Config\SDK\ComponentProvider\OpenTelemetrySdk;
use OpenTelemetry\Config\SDK\Configuration\ComponentPlugin;
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
use OpenTelemetry\Config\SDK\Configuration\ConfigurationFactory;
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\Config\SDK\Configuration\Environment\EnvSourceReader;
use OpenTelemetry\Config\SDK\Configuration\Environment\PhpIniEnvSource;
use OpenTelemetry\Config\SDK\Configuration\Environment\ServerEnvSource;
use OpenTelemetry\SDK\SdkBuilder;
final class Configuration
{
/**
* @param ComponentPlugin<SdkBuilder> $sdkPlugin
*/
private function __construct(
private readonly ComponentPlugin $sdkPlugin,
) {
}
public function create(Context $context = new Context()): SdkBuilder
{
return $this->sdkPlugin->create($context);
}
/**
* @param string|list<string> $file
*/
public static function parseFile(
string|array $file,
?string $cacheFile = null,
bool $debug = true,
): Configuration {
return new self(self::factory()->parseFile($file, $cacheFile, $debug));
}
/**
* @return ConfigurationFactory<SdkBuilder>
*/
private static function factory(): ConfigurationFactory
{
static $factory;
return $factory ??= new ConfigurationFactory(
ServiceLoader::load(ComponentProvider::class),
new OpenTelemetrySdk(),
new EnvSourceReader([
new ServerEnvSource(),
new PhpIniEnvSource(),
]),
);
}
}