From d5494151ba64f2ba0fb0703afa445838d7ca52e9 Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Fri, 26 Jan 2024 15:53:21 +0100 Subject: [PATCH 01/18] Add auto instrumentation for open telemetry --- .../RequestInsuranceInstrumentation.php | 122 ++++++++++++++++++ .../OpenTelemetry/_register.php | 18 +++ 2 files changed, 140 insertions(+) create mode 100644 src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php create mode 100644 src/RequestInsurance/OpenTelemetry/_register.php diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php new file mode 100644 index 0000000..5eb5b27 --- /dev/null +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -0,0 +1,122 @@ +tracer()->spanBuilder($className . '::' . $methodName)->startSpan(); + Context::storage()->attach($span->storeInContext(Context::getCurrent())); + }, + static function ($object, $params, $result, ?Throwable $exception) { + self::endCurrentSpan($exception); + } + ); + } + + public static function register(): void + { + $instrumentation = new CachedInstrumentation('dk.cego.request-insurance-instrumentation'); + + $methodsToHook = [ + [RequestInsuranceWorker::class, 'processRequestInsurances'], + [RequestInsuranceWorker::class, 'readyWaitingRequestInsurances'], + ]; + + foreach ($methodsToHook as $methodToHook) { + self::hookClassMethod($instrumentation, $methodToHook[0], $methodToHook[1]); + } + } + + /** + * @param CachedInstrumentation $instrumentation + * + * @return void + */ + public static function registerHandleNextMessageHook(CachedInstrumentation $instrumentation): void + { + hook(Consumer::class, 'handleNextMessage', + static function (Consumer $topicHandler, array $params) use ($instrumentation) { + // Detach the current span, if any + $scope = Context::storage()->scope(); + + if ($scope) { + $scope->detach(); + } + + if ( ! ($kafkaMessage = $params[0]) instanceof KafkaMessage || ! $kafkaMessage->isRealMessage()) { + return; + } + $span = $instrumentation->tracer()->spanBuilder(sprintf('%s | %s', $topicHandler->getGroupId(), $kafkaMessage->getTopic())) + ->setSpanKind(SpanKind::KIND_CONSUMER) + ->setAttribute(TraceAttributes::MESSAGING_SYSTEM, 'kafka') + ->startSpan(); + Context::storage()->attach($span->storeInContext(Context::getCurrent())); + }, + static function (Consumer $topicHandler, array $params, bool $result, ?Throwable $exception) { + if ( ! ($kafkaMessage = $params[0]) instanceof KafkaMessage || ! $kafkaMessage->isRealMessage()) { + return; + } + + self::endCurrentSpan($exception); + }); + } + + /** + * @param Throwable|null $exception + * + * @return void + */ + private static function endCurrentSpan(?Throwable $exception): void + { + $scope = Context::storage()->scope(); + + if ( ! $scope) { + return; + } + + $scope->detach(); + $span = Span::fromContext($scope->context()); + + if ($exception) { + $span->recordException($exception, [TraceAttributes::EXCEPTION_ESCAPED => true]); + $span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage()); + } else { + $span->setStatus(StatusCode::STATUS_OK); + } + + $span->end(); + } +} diff --git a/src/RequestInsurance/OpenTelemetry/_register.php b/src/RequestInsurance/OpenTelemetry/_register.php new file mode 100644 index 0000000..a60274b --- /dev/null +++ b/src/RequestInsurance/OpenTelemetry/_register.php @@ -0,0 +1,18 @@ + Date: Fri, 26 Jan 2024 15:54:54 +0100 Subject: [PATCH 02/18] Add auto instrumentation for open telemetry --- composer.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f68fc96..718a199 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,10 @@ "autoload-dev": { "psr-4": { "Tests\\": "tests/" - } + }, + "files": [ + "src/RequestInsurance/OpenTelemetry/_register.php" + ] }, "extra": { "laravel": { @@ -52,4 +55,4 @@ ] } } -} \ No newline at end of file +} From 359405df062474f80770568a534ecb8b305e2907 Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Fri, 26 Jan 2024 15:55:24 +0100 Subject: [PATCH 03/18] Add auto instrumentation for open telemetry --- .../RequestInsuranceInstrumentation.php | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php index 5eb5b27..bbc34b7 100644 --- a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -60,40 +60,6 @@ public static function register(): void } } - /** - * @param CachedInstrumentation $instrumentation - * - * @return void - */ - public static function registerHandleNextMessageHook(CachedInstrumentation $instrumentation): void - { - hook(Consumer::class, 'handleNextMessage', - static function (Consumer $topicHandler, array $params) use ($instrumentation) { - // Detach the current span, if any - $scope = Context::storage()->scope(); - - if ($scope) { - $scope->detach(); - } - - if ( ! ($kafkaMessage = $params[0]) instanceof KafkaMessage || ! $kafkaMessage->isRealMessage()) { - return; - } - $span = $instrumentation->tracer()->spanBuilder(sprintf('%s | %s', $topicHandler->getGroupId(), $kafkaMessage->getTopic())) - ->setSpanKind(SpanKind::KIND_CONSUMER) - ->setAttribute(TraceAttributes::MESSAGING_SYSTEM, 'kafka') - ->startSpan(); - Context::storage()->attach($span->storeInContext(Context::getCurrent())); - }, - static function (Consumer $topicHandler, array $params, bool $result, ?Throwable $exception) { - if ( ! ($kafkaMessage = $params[0]) instanceof KafkaMessage || ! $kafkaMessage->isRealMessage()) { - return; - } - - self::endCurrentSpan($exception); - }); - } - /** * @param Throwable|null $exception * From 88397d086541f773f5c88a9806ce4874125d5f9e Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Fri, 26 Jan 2024 16:29:26 +0100 Subject: [PATCH 04/18] Fix namespace --- .../OpenTelemetry/RequestInsuranceInstrumentation.php | 2 +- src/RequestInsurance/OpenTelemetry/_register.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php index bbc34b7..2315f26 100644 --- a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -1,6 +1,6 @@ Date: Fri, 26 Jan 2024 16:31:58 +0100 Subject: [PATCH 05/18] Rename spans --- .../RequestInsuranceInstrumentation.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php index 2315f26..36f78b2 100644 --- a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -31,13 +31,13 @@ class RequestInsuranceInstrumentation { public const NAME = 'cego-request-insurance'; - private static function hookClassMethod(CachedInstrumentation $instrumentation, string $className, string $methodName): void + private static function hookClassMethod(CachedInstrumentation $instrumentation, string $className, string $methodName, string $spanName): void { hook( $className, $methodName, - static function () use ($instrumentation, $className, $methodName) { - $span = $instrumentation->tracer()->spanBuilder($className . '::' . $methodName)->startSpan(); + static function () use ($instrumentation, $className, $methodName, $spanName) { + $span = $instrumentation->tracer()->spanBuilder($spanName)->startSpan(); Context::storage()->attach($span->storeInContext(Context::getCurrent())); }, static function ($object, $params, $result, ?Throwable $exception) { @@ -51,12 +51,12 @@ public static function register(): void $instrumentation = new CachedInstrumentation('dk.cego.request-insurance-instrumentation'); $methodsToHook = [ - [RequestInsuranceWorker::class, 'processRequestInsurances'], - [RequestInsuranceWorker::class, 'readyWaitingRequestInsurances'], + [RequestInsuranceWorker::class, 'processRequestInsurances', 'Process request insurances'], + [RequestInsuranceWorker::class, 'readyWaitingRequestInsurances', 'Ready waiting request insurances'], ]; foreach ($methodsToHook as $methodToHook) { - self::hookClassMethod($instrumentation, $methodToHook[0], $methodToHook[1]); + self::hookClassMethod($instrumentation, $methodToHook[0], $methodToHook[1], $methodToHook[2]); } } From 7cbc07ad2d066544857218dcd3483707be8ab919 Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Fri, 26 Jan 2024 16:43:09 +0100 Subject: [PATCH 06/18] Bump ri --- composer.json | 8 +++++++- .../OpenTelemetry/RequestInsuranceInstrumentation.php | 4 ---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 718a199..02ef13f 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "illuminate/encryption": "^7.0|^8.0|^9.0|^10.0", "guzzlehttp/guzzle": "^6.5.5|^7.2", "jfcherng/php-diff": "^6.13", - "doctrine/dbal": "^3.3" + "doctrine/dbal": "^3.3", + "open-telemetry/sdk": "^1.0" }, "require-dev": { "cego/php-cs-fixer": "^1.0", @@ -54,5 +55,10 @@ "Cego\\RequestInsurance\\RequestInsuranceServiceProvider" ] } + }, + "config": { + "allow-plugins": { + "php-http/discovery": true + } } } diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php index 36f78b2..5f2a152 100644 --- a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -6,7 +6,6 @@ use Throwable; use RdKafka\KafkaConsumer; use OpenTelemetry\API\Trace\Span; -use Illuminate\Support\Collection; use OpenTelemetry\Context\Context; use OpenTelemetry\API\Trace\SpanKind; use Cego\Kafka\Kafka\Consumer\Consumer; @@ -18,11 +17,8 @@ use Cego\Kafka\Kafka\Consumer\TopicHandler; use Cego\Kafka\Kafka\Consumer\CommitManager; use Cego\Kafka\Laravel\Commands\KafkaProducer; - use Cego\Kafka\Kafka\Consumer\MessageRetriever; - use function OpenTelemetry\Instrumentation\hook; - use Cego\Kafka\Database\Consumer\DatabaseConsumer; use Cego\Kafka\Kafka\MessageHandlers\MessageHandler; use OpenTelemetry\API\Instrumentation\CachedInstrumentation; From 4ae03e4bf9027b1dd5d0abe6cbf94a615815d16d Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Fri, 26 Jan 2024 16:51:24 +0100 Subject: [PATCH 07/18] Fix uses --- .../RequestInsuranceInstrumentation.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php index 5f2a152..8b79489 100644 --- a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -4,23 +4,11 @@ use Cego\RequestInsurance\RequestInsuranceWorker; use Throwable; -use RdKafka\KafkaConsumer; use OpenTelemetry\API\Trace\Span; use OpenTelemetry\Context\Context; -use OpenTelemetry\API\Trace\SpanKind; -use Cego\Kafka\Kafka\Consumer\Consumer; -use Cego\Kafka\Kafka\Producer\Producer; use OpenTelemetry\API\Trace\StatusCode; -use Cego\Kafka\Common\CurrentApplication; use OpenTelemetry\SemConv\TraceAttributes; -use Cego\Kafka\Kafka\Consumer\KafkaMessage; -use Cego\Kafka\Kafka\Consumer\TopicHandler; -use Cego\Kafka\Kafka\Consumer\CommitManager; -use Cego\Kafka\Laravel\Commands\KafkaProducer; -use Cego\Kafka\Kafka\Consumer\MessageRetriever; use function OpenTelemetry\Instrumentation\hook; -use Cego\Kafka\Database\Consumer\DatabaseConsumer; -use Cego\Kafka\Kafka\MessageHandlers\MessageHandler; use OpenTelemetry\API\Instrumentation\CachedInstrumentation; class RequestInsuranceInstrumentation @@ -32,7 +20,7 @@ private static function hookClassMethod(CachedInstrumentation $instrumentation, hook( $className, $methodName, - static function () use ($instrumentation, $className, $methodName, $spanName) { + static function () use ($instrumentation, $spanName) { $span = $instrumentation->tracer()->spanBuilder($spanName)->startSpan(); Context::storage()->attach($span->storeInContext(Context::getCurrent())); }, From 6f56f462100a85c64dcb5487d7612d444c4fa5c3 Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Fri, 26 Jan 2024 16:52:03 +0100 Subject: [PATCH 08/18] Fix uses --- .../OpenTelemetry/RequestInsuranceInstrumentation.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php index 8b79489..f3ce004 100644 --- a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -2,13 +2,15 @@ namespace Cego\RequestInsurance\OpenTelemetry; -use Cego\RequestInsurance\RequestInsuranceWorker; use Throwable; use OpenTelemetry\API\Trace\Span; use OpenTelemetry\Context\Context; use OpenTelemetry\API\Trace\StatusCode; use OpenTelemetry\SemConv\TraceAttributes; + use function OpenTelemetry\Instrumentation\hook; + +use Cego\RequestInsurance\RequestInsuranceWorker; use OpenTelemetry\API\Instrumentation\CachedInstrumentation; class RequestInsuranceInstrumentation From 0918c809ffea591fc78bfac51607407d451dedb7 Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Mon, 29 Jan 2024 09:19:57 +0100 Subject: [PATCH 09/18] autoload for non dev --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 02ef13f..9b2f8b3 100644 --- a/composer.json +++ b/composer.json @@ -39,16 +39,16 @@ "autoload": { "psr-4": { "Cego\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" }, "files": [ "src/RequestInsurance/OpenTelemetry/_register.php" ] }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, "extra": { "laravel": { "providers": [ From c8710844ef5e6ca9ebc4c7b17e083d6a907e3657 Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Mon, 29 Jan 2024 09:37:30 +0100 Subject: [PATCH 10/18] Dont require opentelemetry sdk --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9b2f8b3..e545d39 100644 --- a/composer.json +++ b/composer.json @@ -29,12 +29,12 @@ "illuminate/encryption": "^7.0|^8.0|^9.0|^10.0", "guzzlehttp/guzzle": "^6.5.5|^7.2", "jfcherng/php-diff": "^6.13", - "doctrine/dbal": "^3.3", - "open-telemetry/sdk": "^1.0" + "doctrine/dbal": "^3.3" }, "require-dev": { "cego/php-cs-fixer": "^1.0", - "orchestra/testbench": "^6.18" + "orchestra/testbench": "^6.18", + "open-telemetry/sdk": "^1.0" }, "autoload": { "psr-4": { From 3f912690736e2ef15efc73fb5f700e14c5c28c72 Mon Sep 17 00:00:00 2001 From: Mads Jon Nielsen Date: Mon, 29 Jan 2024 09:40:59 +0100 Subject: [PATCH 11/18] Update quality-assurance.yml --- .github/workflows/quality-assurance.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index fd43f2a..34c71e8 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -15,6 +15,7 @@ jobs: strategy: matrix: php-version: [7.4, 8.0, 8.1, 8.2] + extensions: opentelemetry steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 @@ -28,6 +29,7 @@ jobs: strategy: matrix: php-version: [7.4, 8.0, 8.1] + extensions: opentelemetry steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 From ff651d0fb9c89b8c97ea45b4c5850fc0b1bf4b8d Mon Sep 17 00:00:00 2001 From: Mads Jon Nielsen Date: Mon, 29 Jan 2024 09:44:26 +0100 Subject: [PATCH 12/18] Update quality-assurance.yml --- .github/workflows/quality-assurance.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 34c71e8..07f6e68 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -14,13 +14,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: [7.4, 8.0, 8.1, 8.2] - extensions: opentelemetry + php-version: [7.4, 8.0, 8.1, 8.2] steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} + extensions: opentelemetry - run: composer install - run: ./vendor/bin/phpunit @@ -28,12 +28,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: [7.4, 8.0, 8.1] - extensions: opentelemetry + php-version: [7.4, 8.0, 8.1] steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} + extensions: opentelemetry - run: composer install - run: ./vendor/bin/php-cs-fixer fix --dry-run From eea47aaef56724e6aedccec76dcfdabe9c36bb24 Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Mon, 29 Jan 2024 09:46:24 +0100 Subject: [PATCH 13/18] Doc and refactor --- .../RequestInsuranceInstrumentation.php | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php index f3ce004..cccaf30 100644 --- a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -17,6 +17,16 @@ class RequestInsuranceInstrumentation { public const NAME = 'cego-request-insurance'; + /** + * Instruments the given class method, and gives the span around it the given spanName. + * + * @param CachedInstrumentation $instrumentation + * @param string $className + * @param string $methodName + * @param string $spanName + * + * @return void + */ private static function hookClassMethod(CachedInstrumentation $instrumentation, string $className, string $methodName, string $spanName): void { hook( @@ -27,11 +37,32 @@ static function () use ($instrumentation, $spanName) { Context::storage()->attach($span->storeInContext(Context::getCurrent())); }, static function ($object, $params, $result, ?Throwable $exception) { - self::endCurrentSpan($exception); + $scope = Context::storage()->scope(); + + if ( ! $scope) { + return; + } + + $scope->detach(); + $span = Span::fromContext($scope->context()); + + if ($exception) { + $span->recordException($exception, [TraceAttributes::EXCEPTION_ESCAPED => true]); + $span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage()); + } else { + $span->setStatus(StatusCode::STATUS_OK); + } + + $span->end(); } ); } + /** + * Initiated by ./_register.php + * + * @return void + */ public static function register(): void { $instrumentation = new CachedInstrumentation('dk.cego.request-insurance-instrumentation'); @@ -45,30 +76,4 @@ public static function register(): void self::hookClassMethod($instrumentation, $methodToHook[0], $methodToHook[1], $methodToHook[2]); } } - - /** - * @param Throwable|null $exception - * - * @return void - */ - private static function endCurrentSpan(?Throwable $exception): void - { - $scope = Context::storage()->scope(); - - if ( ! $scope) { - return; - } - - $scope->detach(); - $span = Span::fromContext($scope->context()); - - if ($exception) { - $span->recordException($exception, [TraceAttributes::EXCEPTION_ESCAPED => true]); - $span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage()); - } else { - $span->setStatus(StatusCode::STATUS_OK); - } - - $span->end(); - } } From 97dcfb626745b38be5d9fb88044600e7c2174e2e Mon Sep 17 00:00:00 2001 From: Mads Jon Nielsen Date: Mon, 29 Jan 2024 09:49:19 +0100 Subject: [PATCH 14/18] Update quality-assurance.yml --- .github/workflows/quality-assurance.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 07f6e68..8dc87c0 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -13,8 +13,9 @@ jobs: phpunit: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - php-version: [7.4, 8.0, 8.1, 8.2] + php-version: [7.4, 8.0, 8.1, 8.2] steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 @@ -27,8 +28,9 @@ jobs: php-cs-fixer: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - php-version: [7.4, 8.0, 8.1] + php-version: [7.4, 8.0, 8.1] steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 From 0ded21b65a25d045c57d910143f9c4d81074e0fd Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Mon, 29 Jan 2024 09:52:48 +0100 Subject: [PATCH 15/18] Do not error if otel is not installed --- src/RequestInsurance/OpenTelemetry/_register.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RequestInsurance/OpenTelemetry/_register.php b/src/RequestInsurance/OpenTelemetry/_register.php index 03fe5d3..56c20a6 100644 --- a/src/RequestInsurance/OpenTelemetry/_register.php +++ b/src/RequestInsurance/OpenTelemetry/_register.php @@ -5,7 +5,7 @@ use OpenTelemetry\SDK\Sdk; use Cego\RequestInsurance\OpenTelemetry\RequestInsuranceInstrumentation; -if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(RequestInsuranceInstrumentation::NAME) === true) { +if ( ! class_exists(Sdk::class) || Sdk::isInstrumentationDisabled(RequestInsuranceInstrumentation::NAME) === true) { return; } From cd18d37d148cb2c429b52d306e5df251661506b9 Mon Sep 17 00:00:00 2001 From: Mads Jon Nielsen Date: Mon, 29 Jan 2024 09:52:59 +0100 Subject: [PATCH 16/18] Update quality-assurance.yml --- .github/workflows/quality-assurance.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 8dc87c0..65cfa14 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -21,7 +21,6 @@ jobs: - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - extensions: opentelemetry - run: composer install - run: ./vendor/bin/phpunit @@ -36,6 +35,5 @@ jobs: - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - extensions: opentelemetry - run: composer install - run: ./vendor/bin/php-cs-fixer fix --dry-run From 413a8473b956cf84f5d7ce84c74243281d2949a6 Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Mon, 29 Jan 2024 10:07:25 +0100 Subject: [PATCH 17/18] Do not throw if otel is not loaded --- src/RequestInsurance/OpenTelemetry/_register.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/RequestInsurance/OpenTelemetry/_register.php b/src/RequestInsurance/OpenTelemetry/_register.php index 56c20a6..7a1466a 100644 --- a/src/RequestInsurance/OpenTelemetry/_register.php +++ b/src/RequestInsurance/OpenTelemetry/_register.php @@ -5,13 +5,11 @@ use OpenTelemetry\SDK\Sdk; use Cego\RequestInsurance\OpenTelemetry\RequestInsuranceInstrumentation; -if ( ! class_exists(Sdk::class) || Sdk::isInstrumentationDisabled(RequestInsuranceInstrumentation::NAME) === true) { +if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(RequestInsuranceInstrumentation::NAME) === true) { return; } if (extension_loaded('opentelemetry') === false) { - trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry Cego request-insurance auto-instrumentation', E_USER_WARNING); - return; } From 19ab7b10253096bd7f9998ff26678a58dad9074b Mon Sep 17 00:00:00 2001 From: Lau Josefsen Date: Mon, 29 Jan 2024 10:09:44 +0100 Subject: [PATCH 18/18] Insturment batches --- .../OpenTelemetry/RequestInsuranceInstrumentation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php index cccaf30..ef39c52 100644 --- a/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php +++ b/src/RequestInsurance/OpenTelemetry/RequestInsuranceInstrumentation.php @@ -70,6 +70,7 @@ public static function register(): void $methodsToHook = [ [RequestInsuranceWorker::class, 'processRequestInsurances', 'Process request insurances'], [RequestInsuranceWorker::class, 'readyWaitingRequestInsurances', 'Ready waiting request insurances'], + [RequestInsuranceWorker::class, 'processHttpRequestChunk', 'Process batch of http requests'], ]; foreach ($methodsToHook as $methodToHook) {