Skip to content

Commit a2f6405

Browse files
authored
Add Backward Compatibility layer (#637)
* Add Attributes BC layer * Add AttributeLimits BC layer * Add InstrumentationLibrary BC layer * Add GlobalLoggerHolder BC layer * Add triggerMethodDeprecationNotice * Move Clock BC layer * Add ResourceInfo BC notices * Add missing return statement * Add BC class directory to coverage ignore * Fix code coverage annotations
1 parent 8e1e912 commit a2f6405

20 files changed

+533
-107
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656
},
5757
"files": [
5858
"src/Context/fiber/initialize_fiber_handler.php",
59-
"src/SDK/Common/Time/ClockInterface.php",
60-
"src/SDK/Common/Time/AbstractClock.php",
61-
"src/SDK/Common/Time/SystemClock.php"
59+
"src/SDK/Common/Dev/Compatibility/_load.php"
6260
]
6361
},
6462
"autoload-dev": {

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<include>
2828
<directory>src</directory>
2929
</include>
30+
<exclude>
31+
<directory suffix=".php">src/SDK/Common/Dev/Compatibility/BC</directory>
32+
</exclude>
3033
</coverage>
3134

3235
<php>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\SDK\Common\Dev\Compatibility\BC;
6+
7+
use OpenTelemetry\SDK\Common\Dev\Compatibility\Util;
8+
use OpenTelemetry\SDK\Common\Time\ClockFactory;
9+
use OpenTelemetry\SDK\Common\Time\ClockInterface;
10+
use OpenTelemetry\SDK\Common\Time\Util as TimeUtil;
11+
12+
/**
13+
* @codeCoverageIgnoreStart
14+
*/
15+
abstract class AbstractClock implements ClockInterface
16+
{
17+
public static function getDefault(): ClockInterface
18+
{
19+
Util::triggerMethodDeprecationNotice(
20+
'OpenTelemetry\SDK\AbstractClock::getDefault',
21+
'getDefault',
22+
ClockFactory::class
23+
);
24+
25+
return ClockFactory::getDefault();
26+
}
27+
28+
public static function setTestClock(?ClockInterface $clock = null): void
29+
{
30+
Util::triggerMethodDeprecationNotice(
31+
'OpenTelemetry\SDK\AbstractClock::setTestClock',
32+
'setDefault',
33+
ClockFactory::class
34+
);
35+
36+
ClockFactory::setDefault($clock);
37+
}
38+
39+
public static function nanosToMicro(int $nanoseconds): int
40+
{
41+
Util::triggerMethodDeprecationNotice(
42+
'OpenTelemetry\SDK\AbstractClock::nanosToMicro',
43+
'nanosToMicros',
44+
TimeUtil::class
45+
);
46+
47+
return TimeUtil::nanosToMicros($nanoseconds);
48+
}
49+
50+
public static function nanosToMilli(int $nanoseconds): int
51+
{
52+
Util::triggerMethodDeprecationNotice(
53+
'OpenTelemetry\SDK\AbstractClock::nanosToMilli',
54+
'nanosToMillis',
55+
TimeUtil::class
56+
);
57+
58+
return TimeUtil::nanosToMillis($nanoseconds);
59+
}
60+
61+
public static function secondsToNanos(int $seconds): int
62+
{
63+
Util::triggerMethodDeprecationNotice(
64+
'OpenTelemetry\SDK\AbstractClock::secondsToNanos',
65+
'nanosToMillis',
66+
TimeUtil::class
67+
);
68+
69+
return TimeUtil::nanosToMillis($seconds);
70+
}
71+
}
72+
73+
/**
74+
* BC class alias
75+
* @todo: remove in future release. Also in composer.json autoload/files.
76+
*/
77+
class_alias(AbstractClock::class, 'OpenTelemetry\SDK\AbstractClock');
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\SDK\Common\Dev\Compatibility\BC;
6+
7+
use OpenTelemetry\SDK\Common\Attribute\AttributeLimits as Moved;
8+
use OpenTelemetry\SDK\Common\Dev\Compatibility\Util;
9+
10+
/**
11+
* @codeCoverageIgnoreStart
12+
*/
13+
const OpenTelemetry_SDK_AttributeLimits = 'OpenTelemetry\SDK\AttributeLimits';
14+
15+
final class AttributeLimits implements AttributeLimitsInterface
16+
{
17+
private Moved $adapted;
18+
19+
public function __construct(
20+
int $attributeCountLimit = AttributeLimitsInterface::DEFAULT_COUNT_LIMIT,
21+
int $attributeValueLengthLimit = AttributeLimitsInterface::DEFAULT_VALUE_LENGTH_LIMIT
22+
) {
23+
$this->adapted = new Moved(
24+
$attributeCountLimit,
25+
$attributeValueLengthLimit
26+
);
27+
Util::triggerClassDeprecationNotice(
28+
OpenTelemetry_SDK_AttributeLimits,
29+
Moved::class
30+
);
31+
}
32+
33+
public function getAttributeCountLimit(): int
34+
{
35+
return $this->adapted->getAttributeCountLimit();
36+
}
37+
38+
public function getAttributeValueLengthLimit(): int
39+
{
40+
return $this->adapted->getAttributeValueLengthLimit();
41+
}
42+
}
43+
44+
class_alias(AttributeLimits::class, OpenTelemetry_SDK_AttributeLimits);
45+
/**
46+
* @codeCoverageIgnoreEnd
47+
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\SDK\Common\Dev\Compatibility\BC;
6+
7+
use OpenTelemetry\SDK\Common\Attribute\AttributeLimitsInterface as Moved;
8+
9+
interface AttributeLimitsInterface extends Moved
10+
{
11+
}
12+
13+
/**
14+
* @codeCoverageIgnoreStart
15+
*/
16+
class_alias(AttributeLimitsInterface::class, 'OpenTelemetry\SDK\AttributeLimitsInterface');
17+
/**
18+
* @codeCoverageIgnoreEnd
19+
*/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\SDK\Common\Dev\Compatibility\BC;
6+
7+
use OpenTelemetry\SDK\Common\Attribute\Attributes as Moved;
8+
use OpenTelemetry\SDK\Common\Dev\Compatibility\Util;
9+
10+
/**
11+
* @codeCoverageIgnoreStart
12+
*/
13+
const OpenTelemetry_SDK_Attributes = 'OpenTelemetry\SDK\Attributes';
14+
15+
final class Attributes extends Moved implements AttributesInterface
16+
{
17+
public function __construct(iterable $attributes = [], AttributeLimitsInterface $attributeLimits = null)
18+
{
19+
parent::__construct($attributes, $attributeLimits);
20+
21+
Util::triggerClassDeprecationNotice(
22+
OpenTelemetry_SDK_Attributes,
23+
Moved::class
24+
);
25+
}
26+
}
27+
28+
class_alias(Attributes::class, OpenTelemetry_SDK_Attributes);
29+
/**
30+
* @codeCoverageIgnoreEnd
31+
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\SDK\Common\Dev\Compatibility\BC;
6+
7+
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface as Moved;
8+
9+
interface AttributesInterface extends Moved
10+
{
11+
}
12+
13+
/**
14+
* @codeCoverageIgnoreStart
15+
*/
16+
class_alias(AttributesInterface::class, 'OpenTelemetry\SDK\AttributesInterface');
17+
/**
18+
* @codeCoverageIgnoreEnd
19+
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\SDK\Common\Dev\Compatibility\BC;
6+
7+
use OpenTelemetry\SDK\Common\Time\ClockInterface as Moved;
8+
9+
interface ClockInterface extends Moved
10+
{
11+
}
12+
13+
/**
14+
* @codeCoverageIgnoreStart
15+
*/
16+
class_alias(ClockInterface::class, 'OpenTelemetry\SDK\ClockInterface');
17+
/**
18+
* @codeCoverageIgnoreEnd
19+
*/
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\SDK\Common\Dev\Compatibility\BC;
6+
7+
use OpenTelemetry\SDK\Common\Dev\Compatibility\Util;
8+
use OpenTelemetry\SDK\Common\Log\LoggerHolder as Moved;
9+
use Psr\Log\LoggerInterface;
10+
11+
/**
12+
* @codeCoverageIgnoreStart
13+
*/
14+
const OpenTelemetry_SDK_GlobalLoggerHolder = 'OpenTelemetry\SDK\GlobalLoggerHolder';
15+
16+
class GlobalLoggerHolder
17+
{
18+
public static function get(): LoggerInterface
19+
{
20+
self::triggerClassDeprecationNotice();
21+
22+
return Moved::get();
23+
}
24+
25+
public static function set(LoggerInterface $logger): void
26+
{
27+
self::triggerClassDeprecationNotice();
28+
29+
Moved::set($logger);
30+
}
31+
32+
public static function isSet(): bool
33+
{
34+
self::triggerClassDeprecationNotice();
35+
36+
return Moved::isSet();
37+
}
38+
39+
public static function unset(): void
40+
{
41+
self::triggerClassDeprecationNotice();
42+
43+
Moved::unset();
44+
}
45+
46+
public static function disable(): void
47+
{
48+
self::triggerClassDeprecationNotice();
49+
50+
Moved::disable();
51+
}
52+
53+
private static function triggerClassDeprecationNotice(): void
54+
{
55+
Util::triggerClassDeprecationNotice(
56+
OpenTelemetry_SDK_GlobalLoggerHolder,
57+
Moved::class
58+
);
59+
}
60+
}
61+
62+
class_alias(GlobalLoggerHolder::class, OpenTelemetry_SDK_GlobalLoggerHolder);
63+
/**
64+
* @codeCoverageIgnoreEnd
65+
*/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenTelemetry\SDK\Common\Dev\Compatibility\BC;
6+
7+
use OpenTelemetry\SDK\Common\Dev\Compatibility\Util;
8+
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationLibrary as Moved;
9+
10+
/**
11+
* @codeCoverageIgnoreStart
12+
*/
13+
const OpenTelemetry_SDK_InstrumentationLibrary = 'OpenTelemetry\SDK\InstrumentationLibrary';
14+
15+
final class InstrumentationLibrary implements InstrumentationLibraryInterface
16+
{
17+
private Moved $adapted;
18+
19+
public function __construct(string $name, ?string $version = null, ?string $schemaUrl = null)
20+
{
21+
$this->adapted = new Moved($name, $version, $schemaUrl);
22+
23+
Util::triggerClassDeprecationNotice(
24+
OpenTelemetry_SDK_InstrumentationLibrary,
25+
Moved::class
26+
);
27+
}
28+
29+
public function getName(): string
30+
{
31+
return $this->adapted->getName();
32+
}
33+
34+
public function getVersion(): ?string
35+
{
36+
return $this->adapted->getVersion();
37+
}
38+
39+
public function getSchemaUrl(): ?string
40+
{
41+
return $this->adapted->getSchemaUrl();
42+
}
43+
}
44+
45+
class_alias(InstrumentationLibrary::class, OpenTelemetry_SDK_InstrumentationLibrary);
46+
/**
47+
* @codeCoverageIgnoreEnd
48+
*/

0 commit comments

Comments
 (0)