-
Notifications
You must be signed in to change notification settings - Fork 187
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
implement scope configuration #1353
Merged
Merged
Changes from 27 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
c12f89d
add enabled function
brettmc 7f8324b
tracer configurator
brettmc b61feed
logger config
brettmc 3111994
meter config
brettmc 6248609
allow tracer reconfiguration after creation
brettmc 1a4fca7
test enabling a tracer mid-trace
brettmc 0d70f91
tracer configurator builder
brettmc 8c6fb99
consolidate configurators and config
brettmc dbd1108
Merge branch 'main' into scope-config
brettmc 776f87a
metrics reconfig
brettmc 3c8cd17
gauge enabled
brettmc 46c5730
rector
brettmc 3bdae48
default values
brettmc 8447c8d
instrument disabled if meter disabled
brettmc 83f81c6
rename enabled to isEnabled
brettmc ccf7da5
do not export metrics when meter disabled
brettmc 9b33ef7
add benchmark test
brettmc 705bfc4
update logger config on provider config update
brettmc 0feb995
tests
brettmc 3955dba
rename method, add tests
brettmc 0eb8707
rename method, tests
brettmc 0447da6
add configurable interface to providers
brettmc 471d391
interface
brettmc f94a733
ScopeConfigurator interface
brettmc 4d21c6d
param
brettmc 25c7249
remove duplicate interface implementation
brettmc f30df57
nullsafe, rename method
brettmc 9807215
fix weakmap GC
brettmc 48cf8fa
do not export metrics of disabled meters
brettmc 4dcdb01
update benchmark per review feedback
brettmc 65ff1d3
use wildcards instead of regex pattern in name predicate
brettmc 6d018cc
rector + style
brettmc a233ad7
Merge branch 'main' into scope-config
brettmc d2c9793
add isEnabled to late binding tracer/logger/meter
brettmc b5f0c72
disable metrics streams instead of callbacks
brettmc 6fb6b1d
add skipped test for disabling metric streams
brettmc e7e0104
note a todo on reconfiguring meters
brettmc 1d78401
replace scope configurator implementation
brettmc b2f89b6
Merge branch 'main' into scope-config
brettmc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope; | ||
|
||
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface; | ||
|
||
class Condition implements ConditionInterface | ||
{ | ||
public function __construct( | ||
private readonly Predicate $predicate, | ||
private readonly State $state, | ||
) { | ||
} | ||
|
||
public function matches(InstrumentationScopeInterface $scope): bool | ||
{ | ||
return $this->predicate->matches($scope); | ||
} | ||
|
||
public function state(): State | ||
{ | ||
return $this->state; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/SDK/Common/InstrumentationScope/ConditionInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope; | ||
|
||
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface; | ||
|
||
interface ConditionInterface | ||
{ | ||
public function matches(InstrumentationScopeInterface $scope): bool; | ||
public function state(): State; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class Config | ||
{ | ||
public function __construct(private readonly State $state = State::ENABLED) | ||
{ | ||
} | ||
|
||
public function isEnabled(): bool | ||
{ | ||
return $this->state === State::ENABLED; | ||
} | ||
|
||
public static function default(): self | ||
{ | ||
return new self(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope; | ||
|
||
interface Configurable | ||
{ | ||
public function updateConfigurator(ScopeConfigurator $configurator): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope; | ||
|
||
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface; | ||
|
||
class Configurator implements ScopeConfigurator | ||
{ | ||
/** | ||
* @param list<Condition> $conditions | ||
*/ | ||
public function __construct(private readonly array $conditions = []) | ||
{ | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public function getConfig(InstrumentationScopeInterface $scope): Config | ||
{ | ||
foreach ($this->conditions as $condition) { | ||
if ($condition->matches($scope)) { | ||
return new Config($condition->state()); | ||
} | ||
} | ||
|
||
return Config::default(); | ||
} | ||
|
||
public static function builder(): ConfiguratorBuilder | ||
{ | ||
return new ConfiguratorBuilder(); | ||
} | ||
|
||
public static function default(): ScopeConfigurator | ||
{ | ||
return new self(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/SDK/Common/InstrumentationScope/ConfiguratorBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope; | ||
|
||
class ConfiguratorBuilder | ||
{ | ||
/** @var list<Condition> */ | ||
private array $conditions = []; | ||
|
||
public function addCondition(Predicate $predicate, State $state): ConfiguratorBuilder | ||
{ | ||
$this->conditions[] = new Condition($predicate, $state); | ||
|
||
return $this; | ||
} | ||
|
||
public function build(): Configurator | ||
{ | ||
return new Configurator($this->conditions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope; | ||
|
||
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface; | ||
|
||
interface Predicate | ||
{ | ||
public function matches(InstrumentationScopeInterface $scope): bool; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/SDK/Common/InstrumentationScope/Predicate/Attribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope\Predicate; | ||
|
||
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface; | ||
use OpenTelemetry\SDK\Common\InstrumentationScope\Predicate; | ||
|
||
/** | ||
* Predicate which matches exactly on key+value on an {@link InstrumentationScope} attribute. | ||
*/ | ||
class Attribute implements Predicate | ||
{ | ||
public function __construct( | ||
private readonly string $key, | ||
private readonly mixed $value, | ||
) { | ||
} | ||
|
||
public function matches(InstrumentationScopeInterface $scope): bool | ||
{ | ||
if (!$scope->getAttributes()->has($this->key)) { | ||
return false; | ||
} | ||
$attribute = $scope->getAttributes()->get($this->key); | ||
|
||
return $attribute === $this->value; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/SDK/Common/InstrumentationScope/Predicate/AttributeExists.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\InstrumentationScope\Predicate; | ||
|
||
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface; | ||
use OpenTelemetry\SDK\Common\InstrumentationScope\Predicate; | ||
|
||
/** | ||
* Predicate which matches on the existence of an {@link InstrumentationScope} attribute. | ||
*/ | ||
class AttributeExists implements Predicate | ||
{ | ||
public function __construct( | ||
private readonly string $key, | ||
) { | ||
} | ||
|
||
public function matches(InstrumentationScopeInterface $scope): bool | ||
{ | ||
return $scope->getAttributes()->has($this->key); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will we add new configuration options if the spec is extended (esp. if signal specific options are added; do we want a dedicated config class per signal?)?
I'm currently playing around with an alternative approach that uses callbacks to modify the config rather than using the config state that is returned by the first matching condition; all matching callbacks are applied to the initial config, which would make supporting new config options trivial. The configurator uses a
WeakMap<InstrumentationScope, TConfig>
to update configs when a new callback is registered.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we do, or will, need a config class per signal. I was just trying to avoid copy-pasting the same code when they currently have the same functionality.
I don't mind addressing that sooner than later - either I do just turn the one general class into 3 signal-specific ones, or I'm happy to incorporate your alternative if you've got some more code to point me at?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using the following
Configurator
implementation, withTracerProvider
/MeterProvider
/LoggerProvider
accepting aClosure(InstrumentationScope): TConfig
as configurator ("[Tracer/Meter/Logger]Configurator is modeled as a function to maximize flexibility.").Configurator implementation
I'm not too happy with the state of this implementation as it does not support removal of callbacks yet.
Might want to add a predicate parameter to
::with()
that allows flexible conditions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the Configurator implementation to use the above. I had to suppress a couple of phan/phpstan complaints about templates, but it works. I added a couple of convenience methods to create a default Configurator for each signal (
Configurator::meter()
etc).I think it's also worth noting/documenting that if there are multiple matching rules in a configurator, then the last one wins.