Skip to content

Commit

Permalink
Ensure compatibility with upstream (#55)
Browse files Browse the repository at this point in the history
* Ensure compatibility with upstream

* Fix CS

* Pin upstream version to 0.0.8
  • Loading branch information
tidal authored Mar 28, 2022
1 parent dbc5850 commit 258aa9c
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-json": "*",
"open-telemetry/opentelemetry": "~0.0.6",
"open-telemetry/opentelemetry": "^0.0.8",
"php-http/discovery": "^1.14",
"php-http/message": "^1.12"
},
Expand Down
9 changes: 5 additions & 4 deletions src/Aws/Ec2/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

namespace OpenTelemetry\Aws\Ec2;

use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SemConv\ResourceAttributes;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
Expand Down Expand Up @@ -67,15 +68,15 @@ public function getResource(): ResourceInfo
$token = $this->fetchToken();

if ($token === null) {
return ResourceInfo::emptyResource();
return ResourceInfoFactory::emptyResource();
}

$hostName = $this->fetchHostname($token);

$identitiesJson = $this->fetchIdentity($token);

if (!$token || !$identitiesJson) {
return ResourceInfo::emptyResource();
return ResourceInfoFactory::emptyResource();
}

$attributes = new Attributes();
Expand Down Expand Up @@ -115,7 +116,7 @@ public function getResource(): ResourceInfo
return ResourceInfo::create(new Attributes($attributes), ResourceAttributes::SCHEMA_URL);
} catch (\Throwable $e) {
//TODO: add 'Process is not running on K8S when logging is added
return ResourceInfo::emptyResource();
return ResourceInfoFactory::emptyResource();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/Aws/Ecs/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

namespace OpenTelemetry\Aws\Ecs;

use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SemConv\ResourceAttributes;
use Throwable;

Expand Down Expand Up @@ -54,14 +55,14 @@ public function getResource(): ResourceInfo
// Check if running on ECS by looking for below environment variables
if (!getenv(self::ECS_METADATA_KEY_V4) && !getenv(self::ECS_METADATA_KEY_V3)) {
// TODO: add 'Process is not running on ECS' when logs are added
return ResourceInfo::emptyResource();
return ResourceInfoFactory::emptyResource();
}

$hostName = $this->processData->getHostname();
$containerId = $this->getContainerId();

return !$hostName && !$containerId
? ResourceInfo::emptyResource()
? ResourceInfoFactory::emptyResource()
: ResourceInfo::create(new Attributes([
ResourceAttributes::CONTAINER_NAME => $hostName,
ResourceAttributes::CONTAINER_ID => $containerId,
Expand Down
9 changes: 5 additions & 4 deletions src/Aws/Eks/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

namespace OpenTelemetry\Aws\Eks;

use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SemConv\ResourceAttributes;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
Expand Down Expand Up @@ -62,21 +63,21 @@ public function getResource(): ResourceInfo
{
try {
if (!$this->dataProvider->isK8s() || !$this->isEks()) {
return ResourceInfo::emptyResource();
return ResourceInfoFactory::emptyResource();
}

$clusterName = $this->getClusterName();
$containerId = $this->getContainerId();

return !$clusterName && !$containerId
? ResourceInfo::emptyResource()
? ResourceInfoFactory::emptyResource()
: ResourceInfo::create(new Attributes([
ResourceAttributes::CONTAINER_ID => $containerId,
ResourceAttributes::K8S_CLUSTER_NAME => $clusterName,
]));
} catch (\Throwable $e) {
//TODO: add 'Process is not running on K8S when logging is added
return ResourceInfo::emptyResource();
return ResourceInfoFactory::emptyResource();
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Aws/Lambda/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

namespace OpenTelemetry\Aws\Lambda;

use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SemConv\ResourceAttributes;

/**
Expand Down Expand Up @@ -51,7 +52,7 @@ public function getResource(): ResourceInfo
$awsRegion = $awsRegion ? $awsRegion : null;

return !$lambdaName && !$awsRegion && !$functionVersion
? ResourceInfo::emptyResource()
? ResourceInfoFactory::emptyResource()
: ResourceInfo::create(new Attributes([
ResourceAttributes::FAAS_NAME => $lambdaName,
ResourceAttributes::FAAS_VERSION => $functionVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace OpenTelemetry\Symfony\OtelSdkBundle\DependencyInjection;

use OpenTelemetry\SDK\AttributeLimits;
use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\AttributeLimits;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Trace;
use OpenTelemetry\Symfony\OtelSdkBundle\DependencyInjection\Configuration as Conf;
use OpenTelemetry\Symfony\OtelSdkBundle\Trace\ExporterFactory;
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/OtelSdkBundle/Resources/config/sdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace OpenTelemetry\Symfony\OtelSdkBundle\Resources;

use OpenTelemetry\SDK\AttributeLimits;
use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\AttributeLimits;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Common\Time\SystemClock;
use OpenTelemetry\SDK\Resource;
use OpenTelemetry\SDK\SystemClock;
use OpenTelemetry\SDK\Trace;
use OpenTelemetry\SDK\Trace\Sampler;
use OpenTelemetry\SDK\Trace\SpanProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Exception;
use OpenTelemetry\SDK;
use OpenTelemetry\SDK\AttributeLimits;
use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\SystemClock;
use OpenTelemetry\SDK\Common\Attribute\AttributeLimits;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Common\Time\SystemClock;
use OpenTelemetry\SDK\Trace\SpanProcessor;
use OpenTelemetry\Symfony\OtelSdkBundle\DependencyInjection\OtelSdkExtension;
use OpenTelemetry\Symfony\OtelSdkBundle\DependencyInjection\Parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace OpenTelemetry\Test\Integration\Symfony\OtelSdkBundle\Resources;

use Exception;
use OpenTelemetry\SDK\AttributeLimits;
use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\AttributeLimits;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Common\Time\SystemClock;
use OpenTelemetry\SDK\Resource;
use OpenTelemetry\SDK\SystemClock;
use OpenTelemetry\SDK\Trace;
use OpenTelemetry\SDK\Trace\Sampler;
use OpenTelemetry\SDK\Trace\SpanProcessor;
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Aws/Ec2/DetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use GuzzleHttp\Psr7\HttpFactory;
use GuzzleHttp\Psr7\Response;
use OpenTelemetry\Aws\Ec2\Detector;
use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SemConv\ResourceAttributes;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -100,7 +100,7 @@ public function TestInvalidTokenBody()

$detector = new Detector($client, $requestFactory);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}

/**
Expand All @@ -123,7 +123,7 @@ public function TestInvalidTokenResponseCode()

$detector = new Detector($client, $requestFactory);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}

/**
Expand Down Expand Up @@ -182,7 +182,7 @@ public function TestInvalidIdentities()

$detector = new Detector($client, $requestFactory);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}

/**
Expand Down
7 changes: 4 additions & 3 deletions tests/Unit/Aws/Ecs/DetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use OpenTelemetry\Aws\Ecs\DataProvider;
use OpenTelemetry\Aws\Ecs\Detector;
use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SemConv\ResourceAttributes;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -95,7 +96,7 @@ public function TestIsRunningOnEcsReturnsEmpty()

$detector = new Detector($mockData);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}

/**
Expand Down Expand Up @@ -197,7 +198,7 @@ public function TestReturnEmptyResourceInvalidContainerIdAndHostname()

$detector = new Detector($mockData);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());

// Unset environment variable
putenv(self::ECS_ENV_VAR_V4_KEY);
Expand Down
11 changes: 6 additions & 5 deletions tests/Unit/Aws/Eks/DetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
use GuzzleHttp\Psr7\Response;
use OpenTelemetry\Aws\Eks\DataProvider;
use OpenTelemetry\Aws\Eks\Detector;
use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SemConv\ResourceAttributes;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -257,7 +258,7 @@ public function testInvalidBodyIsEks()

$detector = new Detector($mockData, $client, $requestFactory);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}

public function testInvalidResponseCode()
Expand All @@ -280,7 +281,7 @@ public function testInvalidResponseCode()

$detector = new Detector($mockData, $client, $requestFactory);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}

public function testInvalidContainerIdAndClusterName()
Expand All @@ -303,7 +304,7 @@ public function testInvalidContainerIdAndClusterName()

$detector = new Detector($mockData, $client, $requestFactory);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}

public function testInvalidKubernetesFile()
Expand All @@ -324,6 +325,6 @@ public function testInvalidKubernetesFile()

$detector = new Detector($mockData, $client, $requestFactory);

$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}
}
5 changes: 3 additions & 2 deletions tests/Unit/Aws/Lambda/DetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace OpenTelemetry\Test\Unit\Aws\Lambda;

use OpenTelemetry\Aws\Lambda\Detector;
use OpenTelemetry\SDK\Attributes;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SDK\Resource\ResourceInfoFactory;
use OpenTelemetry\SemConv\ResourceAttributes;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -53,7 +54,7 @@ public function TestValidLambda()
public function TestInvalidLambda()
{
$detector = new Detector();
$this->assertEquals(ResourceInfo::emptyResource(), $detector->getResource());
$this->assertEquals(ResourceInfoFactory::emptyResource(), $detector->getResource());
}

/**
Expand Down

0 comments on commit 258aa9c

Please sign in to comment.