Skip to content

Commit 63d4d9c

Browse files
authored
Make ResourceInfo available to component providers (#1729)
* Fix declarative config resource merge order * Make resource info available in component providers
1 parent 610b79a commit 63d4d9c

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Configuration/Context.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,41 @@
1616

1717
final class Context
1818
{
19+
/** @psalm-var class-string-map<T, T> */
20+
private array $extensions = [];
21+
1922
public function __construct(
2023
public readonly TracerProviderInterface $tracerProvider = new NoopTracerProvider(),
2124
public readonly MeterProviderInterface $meterProvider = new NoopMeterProvider(),
2225
public readonly LoggerProviderInterface $loggerProvider = new NoopLoggerProvider(),
2326
public readonly LoggerInterface $logger = new NullLogger(),
2427
) {
2528
}
29+
30+
/**
31+
* @psalm-template T of object
32+
* @psalm-param T $extension
33+
* @psalm-param class-string<T>|null $type
34+
*/
35+
public function withExtension(object $extension, ?string $type = null): self
36+
{
37+
$type ??= $extension::class;
38+
39+
$clone = clone $this;
40+
$clone->extensions[$type] = $extension;
41+
42+
return $clone;
43+
}
44+
45+
/**
46+
* @psalm-template T of object
47+
* @psalm-param class-string<T> $type
48+
* @psalm-return T|null
49+
*/
50+
public function getExtension(string $type): ?object
51+
{
52+
return $this->extensions[$type] ?? null;
53+
}
2654
}
2755

2856
/** @phpstan-ignore-next-line @phan-suppress-next-line PhanUndeclaredClassReference */

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"extra": {
3737
"branch-alias": {
38-
"dev-main": "1.7.x-dev"
38+
"dev-main": "1.8.x-dev"
3939
},
4040
"spi": {
4141
"OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\HookManagerInterface": [

0 commit comments

Comments
 (0)