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

⚠️ Experimental SPI with Laravel instrumentation 👷 #269

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ChrisLightfootWild
Copy link
Contributor

@ChrisLightfootWild ChrisLightfootWild commented Jun 10, 2024

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.

public static function fromArray(array $properties): self
{
return new self(
enabled: $properties['enabled'] ?? (class_exists(Sdk::class) ? !Sdk::isDisabled() : true),
Copy link
Contributor Author

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.

Comment on lines +27 to +29
$logger = $context->loggerProvider->getLogger(self::INSTRUMENTATION_NAME);
$meter = $context->meterProvider->getMeter(self::INSTRUMENTATION_NAME);
$tracer = $context->tracerProvider->getTracer(self::INSTRUMENTATION_NAME);
Copy link
Contributor Author

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.

Comment on lines +31 to +34
foreach (ServiceLoader::load(Hook::class) as $hook) {
/** @var Hook $hook */
$hook->instrument($hookManager, $config, $logger, $meter, $tracer);
}
Copy link
Contributor Author

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');
Copy link
Contributor Author

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()
Copy link
Contributor Author

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?

Copy link

codecov bot commented Jun 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.26%. Comparing base (00bf8ba) to head (c1ed471).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #269      +/-   ##
============================================
+ Coverage     83.59%   86.26%   +2.67%     
+ Complexity     1057      951     -106     
============================================
  Files           104       84      -20     
  Lines          4389     3823     -566     
============================================
- Hits           3669     3298     -371     
+ Misses          720      525     -195     
Flag Coverage Δ
Aws:7.4 86.02% <ø> (ø)
Aws:8.0 85.75% <ø> (ø)
Aws:8.1 85.75% <ø> (ø)
Aws:8.2 85.75% <ø> (ø)
Aws:8.3 85.75% <ø> (ø)
Context/Swoole:7.4 0.00% <ø> (ø)
Context/Swoole:8.0 0.00% <ø> (ø)
Context/Swoole:8.1 0.00% <ø> (ø)
Context/Swoole:8.2 0.00% <ø> (ø)
Context/Swoole:8.3 0.00% <ø> (ø)
Instrumentation/CakePHP:8.0 93.47% <ø> (ø)
Instrumentation/CakePHP:8.1 93.47% <ø> (ø)
Instrumentation/CakePHP:8.2 93.47% <ø> (ø)
Instrumentation/CakePHP:8.3 93.47% <ø> (ø)
Instrumentation/CodeIgniter:8.0 75.86% <ø> (ø)
Instrumentation/CodeIgniter:8.1 75.86% <ø> (ø)
Instrumentation/CodeIgniter:8.2 75.86% <ø> (ø)
Instrumentation/CodeIgniter:8.3 75.86% <ø> (ø)
Instrumentation/ExtAmqp:8.2 89.58% <ø> (ø)
Instrumentation/ExtAmqp:8.3 89.58% <ø> (ø)
Instrumentation/Guzzle:8.0 72.60% <ø> (ø)
Instrumentation/Guzzle:8.1 72.60% <ø> (ø)
Instrumentation/Guzzle:8.2 72.60% <ø> (ø)
Instrumentation/Guzzle:8.3 72.60% <ø> (ø)
Instrumentation/HttpAsyncClient:8.0 81.33% <ø> (ø)
Instrumentation/HttpAsyncClient:8.1 81.33% <ø> (ø)
Instrumentation/HttpAsyncClient:8.2 81.33% <ø> (ø)
Instrumentation/HttpAsyncClient:8.3 81.33% <ø> (ø)
Instrumentation/IO:8.2 75.00% <ø> (ø)
Instrumentation/IO:8.3 75.00% <ø> (ø)
Instrumentation/Laravel:8.0 ?
Instrumentation/Laravel:8.1 ?
Instrumentation/Laravel:8.2 ?
Instrumentation/Laravel:8.3 ?
Instrumentation/MongoDB:7.4 80.55% <ø> (ø)
Instrumentation/MongoDB:8.0 80.55% <ø> (ø)
Instrumentation/MongoDB:8.1 80.55% <ø> (ø)
Instrumentation/MongoDB:8.2 80.55% <ø> (ø)
Instrumentation/MongoDB:8.3 80.55% <ø> (ø)
Instrumentation/OpenAIPHP:8.1 86.82% <ø> (ø)
Instrumentation/OpenAIPHP:8.2 86.82% <ø> (ø)
Instrumentation/OpenAIPHP:8.3 86.82% <ø> (ø)
Instrumentation/PDO:8.2 97.46% <ø> (ø)
Instrumentation/PDO:8.3 97.46% <ø> (ø)
Instrumentation/Psr14:8.0 80.64% <ø> (ø)
Instrumentation/Psr14:8.1 80.64% <ø> (ø)
Instrumentation/Psr14:8.2 80.64% <ø> (ø)
Instrumentation/Psr14:8.3 80.64% <ø> (ø)
Instrumentation/Psr15:8.0 93.50% <ø> (ø)
Instrumentation/Psr15:8.1 93.50% <ø> (ø)
Instrumentation/Psr15:8.2 93.50% <ø> (ø)
Instrumentation/Psr15:8.3 93.50% <ø> (ø)
Instrumentation/Psr16:8.0 97.50% <ø> (ø)
Instrumentation/Psr16:8.1 97.50% <ø> (ø)
Instrumentation/Psr16:8.2 97.50% <ø> (ø)
Instrumentation/Psr16:8.3 97.50% <ø> (ø)
Instrumentation/Psr18:8.0 82.08% <ø> (ø)
Instrumentation/Psr18:8.1 82.08% <ø> (ø)
Instrumentation/Psr18:8.2 82.08% <ø> (ø)
Instrumentation/Psr18:8.3 82.08% <ø> (ø)
Instrumentation/Psr3:8.0 63.51% <ø> (ø)
Instrumentation/Psr3:8.1 63.51% <ø> (ø)
Instrumentation/Psr3:8.2 63.51% <ø> (ø)
Instrumentation/Psr3:8.3 63.51% <ø> (ø)
Instrumentation/Psr6:8.0 97.61% <ø> (ø)
Instrumentation/Psr6:8.1 97.61% <ø> (ø)
Instrumentation/Psr6:8.2 97.61% <ø> (ø)
Instrumentation/Psr6:8.3 97.61% <ø> (ø)
Instrumentation/Slim:8.0 86.23% <ø> (-1.92%) ⬇️
Instrumentation/Slim:8.1 86.95% <ø> (-1.94%) ⬇️
Instrumentation/Slim:8.2 86.95% <ø> (-1.94%) ⬇️
Instrumentation/Slim:8.3 86.95% <ø> (-1.94%) ⬇️
Instrumentation/Symfony:8.0 94.83% <ø> (ø)
Instrumentation/Symfony:8.1 94.83% <ø> (ø)
Instrumentation/Symfony:8.2 94.83% <ø> (ø)
Instrumentation/Symfony:8.3 94.83% <ø> (ø)
Instrumentation/Yii:8.0 79.82% <ø> (ø)
Instrumentation/Yii:8.1 79.82% <ø> (ø)
Instrumentation/Yii:8.2 79.82% <ø> (ø)
Instrumentation/Yii:8.3 79.82% <ø> (ø)
Logs/Monolog:7.4 100.00% <ø> (ø)
Logs/Monolog:8.0 100.00% <ø> (ø)
Logs/Monolog:8.1 100.00% <ø> (ø)
Logs/Monolog:8.2 100.00% <ø> (ø)
Logs/Monolog:8.3 100.00% <ø> (ø)
Propagation/ServerTiming:8.0 100.00% <ø> (ø)
Propagation/ServerTiming:8.1 100.00% <ø> (ø)
Propagation/ServerTiming:8.2 100.00% <ø> (ø)
Propagation/ServerTiming:8.3 100.00% <ø> (ø)
Propagation/TraceResponse:7.4 ?
Propagation/TraceResponse:8.0 100.00% <ø> (ø)
Propagation/TraceResponse:8.1 100.00% <ø> (ø)
Propagation/TraceResponse:8.2 100.00% <ø> (ø)
Propagation/TraceResponse:8.3 100.00% <ø> (ø)
ResourceDetectors/Azure:7.4 91.66% <ø> (ø)
ResourceDetectors/Azure:8.0 91.66% <ø> (ø)
ResourceDetectors/Azure:8.1 91.66% <ø> (ø)
ResourceDetectors/Azure:8.2 91.66% <ø> (ø)
ResourceDetectors/Azure:8.3 91.66% <ø> (ø)
ResourceDetectors/Container:8.0 93.02% <ø> (ø)
ResourceDetectors/Container:8.1 93.02% <ø> (ø)
ResourceDetectors/Container:8.2 93.02% <ø> (ø)
ResourceDetectors/Container:8.3 93.02% <ø> (ø)
Shims/OpenTracing:7.4 92.99% <ø> (ø)
Shims/OpenTracing:8.0 92.99% <ø> (ø)
Shims/OpenTracing:8.1 92.99% <ø> (ø)
Shims/OpenTracing:8.2 92.99% <ø> (ø)
Shims/OpenTracing:8.3 92.99% <ø> (ø)
Symfony:7.4 88.43% <ø> (ø)
Symfony:8.0 88.20% <ø> (ø)
Symfony:8.1 88.20% <ø> (ø)
Symfony:8.2 88.20% <ø> (ø)
Symfony:8.3 88.20% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 20 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00bf8ba...c1ed471. Read the comment docs.


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);
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant