Skip to content

Commit 7e52fd7

Browse files
authored
Fix AWS &%$§$, Fix SDKBundle config, Update SDK dependency (#46)
* Fix Ec2 Detector * Fix Ecs Detector * Fix Eks Detector * Fix Lambda Detector * Fix Xray IdGenerator * Fix Xray Propagator * Temporarily run against SDK dev-main * Remove conflict warning * Fix Symfony config * Fix naming in test matrix
1 parent 15c55b3 commit 7e52fd7

File tree

17 files changed

+97
-78
lines changed

17 files changed

+97
-78
lines changed

.github/workflows/php.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ jobs:
1414
strategy:
1515
matrix:
1616
operating-system: [ubuntu-latest]
17-
php-versions: ['7.4', '8.0', '8.1']
17+
php-version: ['7.4', '8.0', '8.1']
1818

1919
steps:
2020
- uses: actions/checkout@v2
2121

2222
- name: Setup PHP
2323
uses: shivammathur/setup-php@v2
2424
with:
25-
php-version: ${{ matrix.php-versions }}
25+
php-version: ${{ matrix.php-version }}
2626
coverage: xdebug
2727
tools: php-cs-fixer
2828
extensions: ast, grpc
@@ -55,7 +55,7 @@ jobs:
5555
run: vendor/bin/phan
5656

5757
- name: Run Psalm
58-
run: vendor/bin/psalm --output-format=github --php-version=${{ matrix.php-versions }}
58+
run: vendor/bin/psalm --output-format=github --php-version=${{ matrix.php-version }}
5959

6060
- name: Run Phpstan
6161
run: vendor/bin/phpstan analyse --error-format=github

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
"require": {
1515
"php": "^7.4 || ^8.0",
1616
"ext-json": "*",
17-
"open-telemetry/opentelemetry": "^0.0.4",
17+
"open-telemetry/opentelemetry": "dev-main",
1818
"php-http/message": "^1.12",
1919
"php-http/discovery": "^1.14"
2020
},
2121
"replace": {
2222
"open-telemetry/otel-sdk-bundle": "self.version"
2323
},
2424
"conflict": {
25-
"open-telemetry/opentelemetry": "<=0.0.3|0.0.5"
25+
"open-telemetry/opentelemetry": "<=0.0.3"
2626
},
2727
"autoload": {
2828
"psr-4": {

src/Aws/Ec2/Detector.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222

2323
use GuzzleHttp\Client;
2424
use GuzzleHttp\Psr7\Request;
25+
use OpenTelemetry\SDK\Attributes;
26+
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
2527
use OpenTelemetry\SDK\Resource\ResourceInfo;
26-
use OpenTelemetry\SDK\Trace\Attributes;
2728
use OpenTelemetry\SemConv\ResourceAttributes;
2829
use Throwable;
2930

@@ -32,7 +33,7 @@
3233
* and return a Resource populated with metadata about the EC2
3334
* instance. Returns an empty Resource if detection fails.
3435
*/
35-
class Detector
36+
class Detector implements ResourceDetectorInterface
3637
{
3738
private const SCHEME = 'http://';
3839
private const AWS_IDMS_ENDPOINT = '169.254.169.254';
@@ -44,7 +45,7 @@ class Detector
4445
private const MILLISECOND_TIME_OUT = 1000;
4546
private const CLOUD_PROVIDER = 'aws';
4647

47-
private $guzzle;
48+
private Client $guzzle;
4849

4950
public function __construct(Client $guzzle)
5051
{
@@ -53,12 +54,12 @@ public function __construct(Client $guzzle)
5354

5455
/**
5556
* Attempts to connect and obtain an AWS instance Identity document. If the
56-
* connection is succesful it returns a Resource
57+
* connection is successful it returns a Resource
5758
* populated with instance metadata. Returns an empty Resource
5859
* if the connection or parsing of the identity document fails.
5960
*
6061
*/
61-
public function detect(): ResourceInfo
62+
public function getResource(): ResourceInfo
6263
{
6364
try {
6465
$token = $this->fetchToken();
@@ -109,7 +110,7 @@ public function detect(): ResourceInfo
109110
$attributes->setAttribute(ResourceAttributes::HOST_NAME, $hostName);
110111
$attributes->setAttribute(ResourceAttributes::CLOUD_PROVIDER, self::CLOUD_PROVIDER);
111112

112-
return ResourceInfo::create($attributes);
113+
return ResourceInfo::create(new Attributes($attributes), ResourceAttributes::SCHEMA_URL);
113114
} catch (\Throwable $e) {
114115
//TODO: add 'Process is not running on K8S when logging is added
115116
return ResourceInfo::emptyResource();

src/Aws/Ecs/Detector.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@
1919

2020
namespace OpenTelemetry\Aws\Ecs;
2121

22+
use OpenTelemetry\SDK\Attributes;
23+
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
2224
use OpenTelemetry\SDK\Resource\ResourceInfo;
23-
use OpenTelemetry\SDK\Trace\Attributes;
2425
use OpenTelemetry\SemConv\ResourceAttributes;
26+
use Throwable;
2527

2628
/**
2729
* The AwsEcsDetector can be used to detect if a process is running in AWS
2830
* ECS and return a {@link Resource} populated with data about the ECS
2931
* plugins of AWS ˜X-Ray. Returns an empty Resource if detection fails.
3032
*/
31-
class Detector
33+
class Detector implements ResourceDetectorInterface
3234
{
3335
private const ECS_METADATA_KEY_V4 = 'ECS_CONTAINER_METADATA_URI_V4';
3436
private const ECS_METADATA_KEY_V3 = 'ECS_CONTAINER_METADATA_URI';
@@ -47,7 +49,7 @@ public function __construct(DataProvider $processData)
4749
* returns resource with valid extracted values
4850
* If not running on ECS, returns empty rsource
4951
*/
50-
public function detect(): ResourceInfo
52+
public function getResource(): ResourceInfo
5153
{
5254
// Check if running on ECS by looking for below environment variables
5355
if (!getenv(self::ECS_METADATA_KEY_V4) && !getenv(self::ECS_METADATA_KEY_V3)) {
@@ -84,7 +86,7 @@ private function getContainerId(): ?string
8486
return substr($str, strlen($str) - self::CONTAINER_ID_LENGTH);
8587
}
8688
}
87-
} catch (\Throwable $e) {
89+
} catch (Throwable $e) {
8890
//TODO: add 'Failed to read container ID' when logging is added
8991
}
9092

src/Aws/Eks/Detector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
use GuzzleHttp\Client;
2323
use GuzzleHttp\Exception\RequestException;
2424
use GuzzleHttp\Psr7\Request;
25+
use OpenTelemetry\SDK\Attributes;
26+
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
2527
use OpenTelemetry\SDK\Resource\ResourceInfo;
26-
use OpenTelemetry\SDK\Trace\Attributes;
2728
use OpenTelemetry\SemConv\ResourceAttributes;
2829

2930
/**
3031
* The AwsEksDetector can be used to detect if a process is running in AWS
3132
* Elastic Kubernetes and return a {@link Resource} populated with data about the Kubernetes
3233
* plugins of AWS X-Ray. Returns an empty Resource if detection fails.
3334
*/
34-
class Detector
35+
class Detector implements ResourceDetectorInterface
3536
{
3637
// Credentials and path for locating API
3738
private const K8S_SVC_URL = 'kubernetes.default.svc';
@@ -52,7 +53,7 @@ public function __construct(DataProvider $dataProvider, Client $client)
5253
$this->client = $client;
5354
}
5455

55-
public function detect(): ResourceInfo
56+
public function getResource(): ResourceInfo
5657
{
5758
try {
5859
if (!$this->dataProvider->isK8s() || !$this->isEks()) {

src/Aws/Lambda/Detector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020

2121
namespace OpenTelemetry\Aws\Lambda;
2222

23+
use OpenTelemetry\SDK\Attributes;
24+
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
2325
use OpenTelemetry\SDK\Resource\ResourceInfo;
24-
use OpenTelemetry\SDK\Trace\Attributes;
2526
use OpenTelemetry\SemConv\ResourceAttributes;
2627

2728
/**
2829
* The AwsLambdaDetector can be used to detect if a process is running in AWS Lambda
2930
* and return a {@link Resource} populated with data about the environment.
3031
* Returns an empty Resource if detection fails.
3132
*/
32-
class Detector
33+
class Detector implements ResourceDetectorInterface
3334
{
3435
private const LAMBDA_NAME_ENV = 'AWS_LAMBDA_FUNCTION_NAME';
3536
private const LAMBDA_VERSION_ENV = 'AWS_LAMBDA_FUNCTION_VERSION';
3637
private const AWS_REGION_ENV = 'AWS_REGION';
3738
private const CLOUD_PROVIDER = 'aws';
3839

39-
public function detect(): ResourceInfo
40+
public function getResource(): ResourceInfo
4041
{
4142
$lambdaName = getenv(self::LAMBDA_NAME_ENV);
4243
$functionVersion = getenv(self::LAMBDA_VERSION_ENV);

src/Aws/Xray/IdGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(?RandomIdGenerator $randomIdGenerator = null)
5353
*/
5454
public function generateTraceId(): string
5555
{
56-
return dechex(time()) . $this->randomIdGenerator->randomHex(self::TRACE_ID_RANDOM_HEX_LENGTH);
56+
return dechex(time()) . substr($this->randomIdGenerator->generateTraceId(), 0, self::TRACE_ID_RANDOM_HEX_LENGTH);
5757
}
5858

5959
/**

src/Aws/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"open-telemetry/opentelemetry": "^0.0.4"
1818
},
1919
"conflict": {
20-
"open-telemetry/opentelemetry": "<=0.0.3|0.0.5"
20+
"open-telemetry/opentelemetry": "<=0.0.3"
2121
},
2222
"autoload": {
2323
"psr-4": {

src/Symfony/OtelSdkBundle/DependencyInjection/OtelSdkExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace OpenTelemetry\Symfony\OtelSdkBundle\DependencyInjection;
66

7+
use OpenTelemetry\SDK\AttributeLimits;
8+
use OpenTelemetry\SDK\Attributes;
79
use OpenTelemetry\SDK\Trace;
810
use OpenTelemetry\Symfony\OtelSdkBundle\DependencyInjection\Configuration as Conf;
911
use OpenTelemetry\Symfony\OtelSdkBundle\Trace\ExporterFactory;
@@ -96,7 +98,7 @@ private function configureResourceInfo(): void
9698
return;
9799
}
98100
// configure resource attribute limits
99-
$limits = $this->getDefinitionByClass(Trace\AttributeLimits::class);
101+
$limits = $this->getDefinitionByClass(AttributeLimits::class);
100102
if (isset($config[Conf::LIMITS_NODE])) {
101103
$limits->setArguments([
102104
$config[Conf::LIMITS_NODE][Conf::ATTR_COUNT_NODE],
@@ -110,10 +112,10 @@ private function configureResourceInfo(): void
110112
}
111113
$this->getContainer()->setParameter(Parameters::RESOURCE_ATTRIBUTES, $attributesParams);
112114

113-
$attributes = $this->getDefinitionByClass(Trace\Attributes::class);
115+
$attributes = $this->getDefinitionByClass(Attributes::class);
114116
$attributes->setArguments([
115117
'%' . Parameters::RESOURCE_ATTRIBUTES . '%',
116-
self::createReferenceFromClass(Trace\AttributeLimits::class),
118+
self::createReferenceFromClass(AttributeLimits::class),
117119
]);
118120

119121
// reference service name for later use

src/Symfony/OtelSdkBundle/Resources/config/sdk.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
namespace OpenTelemetry\Symfony\OtelSdkBundle\Resources;
66

7+
use OpenTelemetry\SDK\AttributeLimits;
8+
use OpenTelemetry\SDK\Attributes;
79
use OpenTelemetry\SDK\Resource;
10+
use OpenTelemetry\SDK\SystemClock;
811
use OpenTelemetry\SDK\Trace;
912
use OpenTelemetry\SDK\Trace\Sampler;
1013
use OpenTelemetry\SDK\Trace\SpanProcessor;
@@ -35,24 +38,24 @@
3538

3639
// UTIL
3740

38-
$helper->setService(Trace\SystemClock::class);
41+
$helper->setService(SystemClock::class);
3942

4043
$helper->setService(Trace\RandomIdGenerator::class);
4144

4245
// RESOURCE
4346

44-
$helper->setService(Trace\AttributeLimits::class);
47+
$helper->setService(AttributeLimits::class);
4548

46-
$helper->setService(Trace\Attributes::class)
49+
$helper->setService(Attributes::class)
4750
->args([
4851
ConfigHelper::wrapParameter(Parameters::RESOURCE_ATTRIBUTES),
49-
ConfigHelper::createReferenceFromClass(Trace\AttributeLimits::class),
52+
ConfigHelper::createReferenceFromClass(AttributeLimits::class),
5053
]);
5154

5255
$helper->setService(Resource\ResourceInfo::class)
5356
->factory([Resource\ResourceInfo::class , 'create'])
5457
->args([
55-
ConfigHelper::createReferenceFromClass(Trace\Attributes::class),
58+
ConfigHelper::createReferenceFromClass(Attributes::class),
5659
]);
5760

5861
// SAMPLER
@@ -95,7 +98,7 @@
9598
$helper->setService(SpanProcessor\BatchSpanProcessor::class)
9699
->args([
97100
null,
98-
ConfigHelper::createReferenceFromClass(Trace\SystemClock::class),
101+
ConfigHelper::createReferenceFromClass(SystemClock::class),
99102
]);
100103
$helper->setAlias(
101104
Ids::SPAN_PROCESSOR_DEFAULT,

0 commit comments

Comments
 (0)