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

Feature/otel optimisation #5

Merged
merged 49 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d03caa9
Updated otel initialisation
gechetspr Oct 22, 2024
3e2ffd2
Disabled instrumentation on env value provided
gechetspr Oct 23, 2024
74fbcaf
Fixed generation
gechetspr Oct 23, 2024
0ea4cd0
Updated instrumentation enabling condition
gechetspr Oct 23, 2024
ee208c9
Updated instrumentation sampling
gechetspr Oct 24, 2024
03dfc3c
Added filter for instrumentation only for public methods
gechetspr Oct 24, 2024
47184cc
Reworked instrumentation initialisation
gechetspr Oct 28, 2024
f17caea
Filtered covered code
gechetspr Oct 29, 2024
3a47f42
Added metric exporter otlp factory registration to make sure that it …
gechetspr Oct 30, 2024
df5ca74
Updated attributes setting
gechetspr Oct 31, 2024
f0c4443
Updated attributes setting
gechetspr Oct 31, 2024
5ff2f6e
Updated code readability and also cached tracer
gechetspr Nov 1, 2024
b9cf95f
Disable modules instrumentation if opentelemetry instrumentation is d…
asmarovydlo Nov 8, 2024
0ee7185
Added and fixed a root span
gechetspr Nov 14, 2024
1396029
Merge branch 'feature/otel-optimisation' of github.com:spryker/opente…
gechetspr Nov 14, 2024
bfcbbcb
test for generator
gechetspr Nov 14, 2024
891d527
Changed hook heneration mechanism to group by module
gechetspr Nov 14, 2024
553dc86
Removed metrics from setup
gechetspr Nov 14, 2024
a0f0a6e
Removed dropped spans log processing
gechetspr Nov 15, 2024
61836c3
Sampling optimisation
gechetspr Nov 15, 2024
f90e96d
Sampling optimisation
gechetspr Nov 15, 2024
00ce828
Span exporter and coverter update
gechetspr Nov 17, 2024
1d6f1ad
Fixed types
gechetspr Nov 17, 2024
4ce318a
Fixed types
gechetspr Nov 17, 2024
0e3f99d
Performance improvementes
gechetspr Nov 17, 2024
3c7b069
Updated sampling
gechetspr Nov 17, 2024
ba073bb
Removed heavy hitting methods from generation
gechetspr Nov 18, 2024
66f8d63
Removed heavy hitting methods from generation
gechetspr Nov 18, 2024
599c956
Reduced modules amount
gechetspr Nov 18, 2024
c2b48db
Reduced modules amount
gechetspr Nov 18, 2024
6273eb1
Updated list of modules and fixedcritical functionality
gechetspr Nov 19, 2024
b3038d1
Refactoring
gechetspr Nov 27, 2024
ab22a15
Added root span name processing
gechetspr Nov 28, 2024
de75b4c
Refactored config and plugin to support monitoring service actions
gechetspr Nov 30, 2024
e443f62
Updated hook generation
gechetspr Dec 2, 2024
35c6a0a
Updated generation and post sampling
gechetspr Dec 2, 2024
114e503
Test sampler based on random
gechetspr Dec 2, 2024
cd9f8e3
Performance testing
gechetspr Dec 3, 2024
d5b8c53
Added non critical probability processing
gechetspr Dec 3, 2024
8deb8d4
Added non critical probability processing
gechetspr Dec 3, 2024
871640b
Incriased visibility and fixed tree structure
gechetspr Dec 4, 2024
c7698e2
Disabled Kernel
gechetspr Dec 4, 2024
b3c193e
Reverted enabled modules
gechetspr Dec 5, 2024
dffb37e
Reverted enabled modules
gechetspr Dec 5, 2024
3480f4a
Fixes after rewiew and test of big hook file
gechetspr Dec 5, 2024
aca3018
Changed detailed flag
gechetspr Dec 5, 2024
b3af58a
Default values for config and disabled additional instrumentation
gechetspr Dec 6, 2024
52ed7fb
Fixes after a code review
gechetspr Dec 6, 2024
fb88dca
Updated requirements
gechetspr Dec 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
fail-fast: false
matrix:
php-version: [
'8.1',
'8.2'
'8.2',
'8.3'
]

steps:
Expand Down
6 changes: 5 additions & 1 deletion _register.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
use OpenTelemetry\SDK\Sdk;
use Spryker\Service\Opentelemetry\Instrumentation\SprykerInstrumentationBootstrap;

if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(SprykerInstrumentationBootstrap::NAME) === true) {
if (!class_exists(Sdk::class)) {
return;
}

if (Sdk::isDisabled()) {
return;
}

Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
"description": "Opentelemetry module",
"license": "proprietary",
"require": {
"ext-grpc": "*",
"ext-opentelemetry": "*",
"open-telemetry/api": "^1.0",
"open-telemetry/exporter-otlp": "^1.0",
"open-telemetry/gen-otlp-protobuf": "^1.1",
"open-telemetry/transport-grpc": "^1.0",
"open-telemetry/sdk": "^1.0",
"open-telemetry/sem-conv": "^1.0",
"php": ">=8.1",
"php": ">=8.2",
"spryker/kernel": "^3.30.0",
"spryker/monitoring-extension": "^1.0.0",
"spryker/symfony": "^3.0.0"
Expand Down
4 changes: 3 additions & 1 deletion otel-autoload-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
* This file should be copied to the root of Spryker application and enabled in `autoload.files` section of composer.json file.
*/

use OpenTelemetry\SDK\Sdk;

$autoload = function (string $class)
{
$convertedClassName = str_replace('\\', '-', $class);
$hookFilePath = __DIR__.'/src/Generated/OpenTelemetry/Hooks/' . $convertedClassName . 'Hook.php';

if (getenv('OTEL_SDK_DISABLED') !== true && file_exists($hookFilePath)) {
if (!Sdk::isDisabled() && file_exists($hookFilePath)) {
include_once $hookFilePath;
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Service\Opentelemetry\Instrumentation\Resource;

use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;

class CompositeResourceDetector implements ResourceDetectorInterface
{
/**
* @param array<\OpenTelemetry\SDK\Resource\ResourceDetectorInterface> $resourceDetectors
*/
public function __construct(protected array $resourceDetectors)
{
}

/**
* @return \Spryker\Service\Opentelemetry\Instrumentation\Resource\ResourceInfo
*/
public function getResource(): ResourceInfo
asmarovydlo marked this conversation as resolved.
Show resolved Hide resolved
{
$resource = ResourceInfoFactory::emptyResource();
foreach ($this->resourceDetectors as $resourceDetector) {
$detectorResource = $resourceDetector->getResource();
$resourceToMerge = new ResourceInfo($detectorResource->getAttributes(), $detectorResource->getSchemaUrl());
$resource = $resource->mergeSprykerResource($resourceToMerge);
}

return $resource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Service\Opentelemetry\Instrumentation\Resource;

use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo as OtelResourceInfo;
use OpenTelemetry\SemConv\ResourceAttributes;
use Spryker\Service\Opentelemetry\Instrumentation\Span\Attributes;
use Spryker\Service\Opentelemetry\Instrumentation\Span\WritableAttributesInterface;

class ResourceInfo extends OtelResourceInfo
{
public function __construct(
protected AttributesInterface $attributes,
protected ?string $schemaUrl = null,
) {
}

/**
* @param string $name
* @return void
*/
public function setServiceName(string $name): void
{
if ($this->attributes instanceof WritableAttributesInterface) {
$this->attributes->set(ResourceAttributes::SERVICE_NAME, $name);
}
}

/**
* @return \OpenTelemetry\SDK\Common\Attribute\AttributesInterface
*/
public function getAttributes(): AttributesInterface
{
return $this->attributes;
}

/**
* @param \OpenTelemetry\SDK\Common\Attribute\AttributesInterface $attributes
* @param string|null $schemaUrl
*
* @return \Spryker\Service\Opentelemetry\Instrumentation\Resource\ResourceInfo
*/
public static function createSprykerResource(AttributesInterface $attributes, ?string $schemaUrl = null): ResourceInfo
{
return new ResourceInfo($attributes, $schemaUrl);
}

/**
* @return string|null
*/
public function getSchemaUrl(): ?string
{
return $this->schemaUrl;
}

/**
* @param \Spryker\Service\Opentelemetry\Instrumentation\Resource\ResourceInfo $updating
*
* @return \Spryker\Service\Opentelemetry\Instrumentation\Resource\ResourceInfo
*/
public function mergeSprykerResource(ResourceInfo $updating): ResourceInfo
{
$schemaUrl = static::mergeSchemaUrl($this->getSchemaUrl(), $updating->getSchemaUrl());
$attributes = Attributes::factory()->builder()->merge($this->getAttributes(), $updating->getAttributes());

return ResourceInfo::createSprykerResource($attributes, $schemaUrl);
}

/**
* @param string|null $old
* @param string|null $updating
*
* @return string|null
*/
protected static function mergeSchemaUrl(?string $old, ?string $updating): ?string
{
if (empty($old)) {
return $updating;
}
if (empty($updating)) {
return $old;
}
if ($old === $updating) {
return $old;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Service\Opentelemetry\Instrumentation\Resource;

use OpenTelemetry\SDK\Registry;
use OpenTelemetry\SDK\Resource\Detectors\Composer;
use OpenTelemetry\SDK\Resource\Detectors\Environment;
use OpenTelemetry\SDK\Resource\Detectors\Host;
use OpenTelemetry\SDK\Resource\Detectors\OperatingSystem;
use OpenTelemetry\SDK\Resource\Detectors\Process;
use OpenTelemetry\SDK\Resource\Detectors\ProcessRuntime;
use OpenTelemetry\SDK\Resource\Detectors\Sdk;
use OpenTelemetry\SDK\Resource\Detectors\SdkProvided;
use Spryker\Service\Opentelemetry\Instrumentation\Span\Attributes;

class ResourceInfoFactory
{
/**
* @var \Spryker\Service\Opentelemetry\Instrumentation\Resource\ResourceInfo|null
*/
protected static ?ResourceInfo $emptyResource = null;

/**
* @return \Spryker\Service\Opentelemetry\Instrumentation\Resource\ResourceInfo
*/
public static function defaultResource(): ResourceInfo
{
return (new CompositeResourceDetector([
new Host(),
new OperatingSystem(),
new Process(),
new ProcessRuntime(),
new Sdk(),
new SdkProvided(),
new Composer(),
...Registry::resourceDetectors(),
new Environment(),
]))->getResource();
}

/**
* @return \Spryker\Service\Opentelemetry\Instrumentation\Resource\ResourceInfo
*/
public static function emptyResource(): ResourceInfo
{
if (null === self::$emptyResource) {
self::$emptyResource = ResourceInfo::createSprykerResource(Attributes::create([]));
}

return self::$emptyResource;
}
}

This file was deleted.

Loading
Loading