-
Notifications
You must be signed in to change notification settings - Fork 62
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
⚠️ Experimental SPI with Laravel instrumentation 👷 #269
base: main
Are you sure you want to change the base?
⚠️ Experimental SPI with Laravel instrumentation 👷 #269
Conversation
public static function fromArray(array $properties): self | ||
{ | ||
return new self( | ||
enabled: $properties['enabled'] ?? (class_exists(Sdk::class) ? !Sdk::isDisabled() : true), |
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 properties is always populated by withDefaults
functionality, so will need to double check this funtionality.
$logger = $context->loggerProvider->getLogger(self::INSTRUMENTATION_NAME); | ||
$meter = $context->meterProvider->getMeter(self::INSTRUMENTATION_NAME); | ||
$tracer = $context->tracerProvider->getTracer(self::INSTRUMENTATION_NAME); |
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.
CachedInstrumentation deferred this, but I was trying to avoid having to keep creating tracers.
foreach (ServiceLoader::load(Hook::class) as $hook) { | ||
/** @var Hook $hook */ | ||
$hook->instrument($hookManager, $config, $logger, $meter, $tracer); | ||
} |
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.
Lean into the power of SPI 👀
class_exists(Configuration::class) | ||
&& Configuration::getBoolean('OTEL_PHP_TRACE_CLI_ENABLED', false) | ||
); | ||
return PHP_SAPI !== 'cli' || (new ConfigurationResolver())->getBoolean('OTEL_PHP_TRACE_CLI_ENABLED'); |
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.
This works without an SDK component now (I was previously unaware of the ConfigurationResolver).
|
||
return $root | ||
->canBeDisabled() | ||
->addDefaultsIfNotSet() |
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'd like to add a hooks
array here with configuration of each hook, unless there's a better alternative?
|
||
if (extension_loaded('opentelemetry') === false) { | ||
trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry Laravel auto-instrumentation', E_USER_WARNING); | ||
ServiceLoader::register(Hooks\Hook::class, Hooks\Illuminate\Console\Command::class); |
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.
Having mapped all these out here, I might as well have kept them in LaravelInstrumentation
and just called them there without SPI.
WIP: current test approach needs tweaking.
Using new functionality provided via open-telemetry/opentelemetry-php#1304.
This should probably form the basis of a v1.1 package, so depends on a 1.0 release of the current Laravel instrumentation.