Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split config into own package #1248

Closed
wants to merge 14 commits into from
2 changes: 2 additions & 0 deletions .gitsplit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ splits:
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/gen-otlp-protobuf.git"
- prefix: "src/Context"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/context.git"
- prefix: "src/Config/Configuration"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/config.git"
- prefix: "src/SemConv"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/sem-conv.git"
- prefix: "src/API"
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
],
"replace": {
"open-telemetry/api": "1.0.x-dev",
"open-telemetry/config": "1.0.x-dev",
"open-telemetry/context": "1.0.x-dev",
"open-telemetry/exporter-otlp": "1.0.x-dev",
"open-telemetry/exporter-zipkin": "1.0.x-dev",
Expand Down
28 changes: 28 additions & 0 deletions deptrac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ deptrac:
collectors:
- type: directory
value: src/SDK/.*
- name: Config
collectors:
- type: directory
value: src/Config/Configuration/.*
- name: ConfigSDK
collectors:
- type: directory
value: src/Config/SDK/.*
- name: Context
collectors:
- type: directory
Expand Down Expand Up @@ -77,12 +85,22 @@ deptrac:
collectors:
- type: className
regex: ^Composer\\*
- name: SymfonyConfig
collectors:
- type: className
regex: ^Symfony\\Component\\*
- name: SPI
collectors:
- type: className
regex: ^Nevay\\SPI\\*

ruleset:
Context:
- FFI
- Config
SemConv: ~
API:
- Config
- Context
- PsrLog
SDK:
Expand All @@ -91,6 +109,15 @@ deptrac:
- PsrHttp
- HttpPlug
- Composer
Config:
- PsrLog
ConfigSDK:
- Contrib
- Extension
- PsrLog
- SymfonyConfig
- +SDK
- SPI
Contrib:
- +SDK
- +OtelProto
Expand All @@ -101,3 +128,4 @@ deptrac:
OtelProto:
- GoogleProtobuf
- Grpc
SdkConfig:
5 changes: 0 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ parameters:
- tests/TraceContext/W3CTestService
- tests/Unit/Config/SDK/Configuration/ExampleSdk
ignoreErrors:
-
message: "#Call to an undefined method .*#"
paths:
- tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php
- tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php
-
message: "#Call to an undefined method .*:allows.*#"
paths:
Expand Down
18 changes: 9 additions & 9 deletions src/API/Behavior/Internal/LogWriterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@
use OpenTelemetry\API\Behavior\Internal\LogWriter\NoopLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\Psr3LogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\StreamLogWriter;
use OpenTelemetry\API\Instrumentation\ConfigurationResolver;
use OpenTelemetry\API\LoggerHolder;
use OpenTelemetry\Config\Configuration\Configuration;
use OpenTelemetry\Config\Configuration\KnownValues;
use OpenTelemetry\Config\Configuration\Variables;

class LogWriterFactory
{
private const OTEL_PHP_LOG_DESTINATION = 'OTEL_PHP_LOG_DESTINATION';

public function create(): LogWriterInterface
{
$dest = (new ConfigurationResolver())->getString(self::OTEL_PHP_LOG_DESTINATION);
$dest = (new Configuration())->getEnum(Variables::OTEL_PHP_LOG_DESTINATION);
$logger = LoggerHolder::get();

switch ($dest) {
case 'none':
case KnownValues::VALUE_NONE:
return new NoopLogWriter();
case 'stderr':
case KnownValues::VALUE_STDERR:
return new StreamLogWriter('php://stderr');
case 'stdout':
case KnownValues::VALUE_STDOUT:
return new StreamLogWriter('php://stdout');
case 'psr3':
case KnownValues::VALUE_PSR3:
if ($logger) {
return new Psr3LogWriter($logger);
}
error_log('OpenTelemetry: cannot use OTEL_PHP_LOG_DESTINATION=psr3 without providing a PSR-3 logger');

//default to error log
return new ErrorLogWriter();
case 'error_log':
case KnownValues::VALUE_ERROR_LOG:
return new ErrorLogWriter();
default:
if ($logger) {
Expand Down
12 changes: 3 additions & 9 deletions src/API/Behavior/Internal/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace OpenTelemetry\API\Behavior\Internal;

use OpenTelemetry\API\Behavior\Internal\LogWriter\LogWriterInterface;
use OpenTelemetry\Config\Configuration\Configuration;
use OpenTelemetry\Config\Configuration\Variables;
use Psr\Log\LogLevel;

/**
Expand Down Expand Up @@ -69,15 +71,7 @@ public static function logLevel(): int

private static function getLogLevel(): int
{
$level = array_key_exists(self::OTEL_LOG_LEVEL, $_SERVER)
? $_SERVER[self::OTEL_LOG_LEVEL]
: getenv(self::OTEL_LOG_LEVEL);
if (!$level) {
$level = ini_get(self::OTEL_LOG_LEVEL);
}
if (!$level) {
$level = self::DEFAULT_LEVEL;
}
$level = Configuration::getEnum(Variables::OTEL_LOG_LEVEL, self::DEFAULT_LEVEL);

return self::level($level);
}
Expand Down
77 changes: 0 additions & 77 deletions src/API/Instrumentation/ConfigurationResolver.php

This file was deleted.

14 changes: 0 additions & 14 deletions src/API/Instrumentation/ConfigurationResolverInterface.php

This file was deleted.

1 change: 1 addition & 0 deletions src/API/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"require": {
"php": "^8.1",
"open-telemetry/config": "*",
"open-telemetry/context": "^1.0",
"psr/log": "^1.1|^2.0|^3.0",
"symfony/polyfill-php82": "^1.26"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

declare(strict_types=1);

namespace OpenTelemetry\SDK\Common\Util;
namespace OpenTelemetry\Config\Configuration\Accessor;

use LogicException;

/**
* @internal
*/
class ClassConstantAccessor
{
public static function requireValue(string $className, string $constantName)
public static function requireValue(string $className, string $constantName): mixed
{
$constant = self::getFullName($className, $constantName);

Expand All @@ -21,7 +24,7 @@ public static function requireValue(string $className, string $constantName)
return constant($constant);
}

public static function getValue(string $className, string $constantName)
public static function getValue(string $className, string $constantName): mixed
{
$constant = self::getFullName($className, $constantName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

declare(strict_types=1);

namespace OpenTelemetry\SDK\Common\Configuration\Resolver;
namespace OpenTelemetry\Config\Configuration\Accessor;

/**
* @internal
*/
class PhpIniAccessor
{
/**
* Mockable accessor for php.ini values
* @internal
* @return array|false|string
*/
public function get(string $variableName)
public function get(string $variableName): array|false|string
{
return get_cfg_var($variableName);
}
Expand Down
Loading
Loading