Skip to content

Commit

Permalink
Merge pull request #30 from tidal/psr4
Browse files Browse the repository at this point in the history
Reorganize directory structure
  • Loading branch information
bobstrecansky authored Nov 10, 2021
2 parents 5529a84 + bd45001 commit 1536b14
Show file tree
Hide file tree
Showing 96 changed files with 349 additions and 335 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $ composer require open-telemetry/opentelemetry-php-contrib

### Symfony
#### SdkBundle
- The documentation for the Symfony SdkBundle can be found [here](/instrumentation/symfony/OtelSdkBundle/README.md).
- The documentation for the Symfony SdkBundle can be found [here](/src/Symfony/OtelSdkBundle/README.md).
- An example symfony application using the SdkBundle can be found [here](https://github.com/tidal/otel-sdk-bundle-example-sf5).


Expand Down
17 changes: 4 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,13 @@
},
"autoload": {
"psr-4": {
"OpenTelemetry\\Instrumentation\\Symfony\\": "instrumentation/symfony"
},
"classmap": [
"detectors/",
"exporters/",
"instrumentation/",
"propagators/"
],
"exclude-from-classmap": ["instrumentation/symfony/OtelSdkBundle/vendor"]
"OpenTelemetry\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"OpenTelemetry\\Test\\Unit\\Symfony\\": "tests/unit/instrumentation/Symfony",
"OpenTelemetry\\Test\\Integration\\Symfony\\": "tests/integration/instrumentation/Symfony"
},
"classmap": ["examples/"]
"OpenTelemetry\\Test\\": "tests"
}
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand Down
1 change: 0 additions & 1 deletion detectors/README.md

This file was deleted.

16 changes: 8 additions & 8 deletions examples/aws/sampleApp1/SampleApp1.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
require __DIR__ . '/../../../vendor/autoload.php';

use GuzzleHttp\Client;
use Instrumentation\Aws\Xray\AwsXrayIdGenerator;
use OpenTelemetry\Aws\Xray\IdGenerator;
use OpenTelemetry\Aws\Xray\Propagator;
use OpenTelemetry\Contrib\OtlpGrpc\Exporter as OTLPExporter;
use OpenTelemetry\Sdk\Trace\PropagationMap;
use OpenTelemetry\Sdk\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\Sdk\Trace\TracerProvider;
use OpenTelemetry\SDK\Trace\PropagationMap;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;
use OpenTelemetry\Trace as API;
use Propagators\Aws\Xray\AwsXrayPropagator;

// use Aws\S3\S3Client;
// use Aws\Exception\AwsException;
Expand Down Expand Up @@ -71,7 +71,7 @@

// Create a tracer object that uses the AWS X-Ray ID Generator to
// generate trace Ids in the correct format
$tracer = (new TracerProvider(null, null, new AwsXrayIdGenerator()))
$tracer = (new TracerProvider(null, null, new IdGenerator()))
->addSpanProcessor(new SimpleSpanProcessor($Exporter))
->getTracer('io.opentelemetry.contrib.php');

Expand All @@ -92,7 +92,7 @@
// Make an HTTP request to take some time up
// Carrier is injected into the header to simulate a microservice needing the carrier
$childSpan = $tracer->startAndActivateSpan('session.generate.http.span.' . microtime(true), API\SpanKind::KIND_CLIENT);
AwsXrayPropagator::inject($childSpan->getContext(), $carrier, $map);
Propagator::inject($childSpan->getContext(), $carrier, $map);

try {
$res = $client->request('GET', 'https://aws.amazon.com', ['headers' => $carrier, 'timeout' => 2000,]);
Expand All @@ -110,7 +110,7 @@
echo 'The desired function is currently unavailable';
// // Create a child span for sdk call
// $childSpan = $tracer->startAndActivateSpan('session.generate.aws.sdk.span.' . microtime(true), API\SpanKind::KIND_CLIENT);
// AwsXrayPropagator::inject($childSpan->getContext(), $carrier, $map);
// Propagator::inject($childSpan->getContext(), $carrier, $map);

// // Make a call to aws s3 buckets
// $s3Client = new S3Client([
Expand Down
16 changes: 8 additions & 8 deletions examples/aws/sampleApp2/SampleApp2.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

require __DIR__ . '/../../../vendor/autoload.php';

use Instrumentation\Aws\Xray\AwsXrayIdGenerator;
use OpenTelemetry\Aws\Xray\IdGenerator;
use OpenTelemetry\Aws\Xray\Propagator;
use OpenTelemetry\Contrib\OtlpGrpc\Exporter as OTLPExporter;
use OpenTelemetry\Sdk\Trace\PropagationMap;
use OpenTelemetry\Sdk\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\Sdk\Trace\TracerProvider;
use Propagators\Aws\Xray\AwsXrayPropagator;
use OpenTelemetry\SDK\Trace\PropagationMap;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;

/**
* This is a sample app that makes an http request to aws.amazon.com
Expand All @@ -46,7 +46,7 @@

// Create a tracer object that uses the AWS X-Ray ID Generator to
// generate trace IDs in the correct format
$tracer = (new TracerProvider(null, null, new AwsXrayIdGenerator()))
$tracer = (new TracerProvider(null, null, new IdGenerator()))
->addSpanProcessor(new SimpleSpanProcessor($Exporter))
->getTracer('io.opentelemetry.contrib.php');

Expand All @@ -64,12 +64,12 @@

// TODO: The next step for testing propagation would be to create two separate
// web application, each making a request from a client front end.
AwsXrayPropagator::inject($span->getContext(), $carrier, $map);
Propagator::inject($span->getContext(), $carrier, $map);
$service1 = new Service1($carrier);
$childSpanContext = $service1->useService();

// Inject the context of the child span into the carrier to pass to the first service2
AwsXrayPropagator::inject($childSpanContext, $carrier, $map);
Propagator::inject($childSpanContext, $carrier, $map);
$service2 = new Service2($carrier);
$childSpanContext2 = $service2->useService();

Expand Down
14 changes: 7 additions & 7 deletions examples/aws/sampleApp2/Service1.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

require __DIR__ . '/../../../vendor/autoload.php';

use Instrumentation\Aws\Xray\AwsXrayIdGenerator;
use OpenTelemetry\Aws\Xray\IdGenerator;
use OpenTelemetry\Aws\Xray\Propagator;
use OpenTelemetry\Contrib\OtlpGrpc\Exporter as OTLPExporter;
use OpenTelemetry\Sdk\Trace\PropagationMap;
use OpenTelemetry\Sdk\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\Sdk\Trace\TracerProvider;
use OpenTelemetry\SDK\Trace\PropagationMap;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;
use OpenTelemetry\Trace as API;
use Propagators\Aws\Xray\AwsXrayPropagator;

class Service1
{
Expand All @@ -48,12 +48,12 @@ public function useService()

// Create a tracer object that uses the AWS X-Ray ID Generator to
// generate trace IDs in the correct format
$tracer = (new TracerProvider(null, null, new AwsXrayIdGenerator()))
$tracer = (new TracerProvider(null, null, new IdGenerator()))
->addSpanProcessor(new SimpleSpanProcessor($Exporter))
->getTracer('io.opentelemetry.contrib.php');

// Extract the SpanContext from the carrier
$spanContext = AwsXrayPropagator::extract($this->carrier, $map);
$spanContext = Propagator::extract($this->carrier, $map);

// Do some kind of operation
$i = 0;
Expand Down
14 changes: 7 additions & 7 deletions examples/aws/sampleApp2/Service2.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

require __DIR__ . '/../../../vendor/autoload.php';

use Instrumentation\Aws\Xray\AwsXrayIdGenerator;
use OpenTelemetry\Aws\Xray\IdGenerator;
use OpenTelemetry\Aws\Xray\Propagator;
use OpenTelemetry\Contrib\OtlpGrpc\Exporter as OTLPExporter;
use OpenTelemetry\Sdk\Trace\PropagationMap;
use OpenTelemetry\Sdk\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\Sdk\Trace\TracerProvider;
use OpenTelemetry\SDK\Trace\PropagationMap;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;
use OpenTelemetry\Trace as API;
use Propagators\Aws\Xray\AwsXrayPropagator;

class Service2
{
Expand All @@ -48,12 +48,12 @@ public function useService()

// Create a tracer object that uses the AWS X-Ray ID Generator to
// generate trace IDs in the correct format
$tracer = (new TracerProvider(null, null, new AwsXrayIdGenerator()))
$tracer = (new TracerProvider(null, null, new IdGenerator()))
->addSpanProcessor(new SimpleSpanProcessor($Exporter))
->getTracer('io.opentelemetry.contrib.php');

// Extract the SpanContext from the carrier
$spanContext = AwsXrayPropagator::extract($this->carrier, $map);
$spanContext = Propagator::extract($this->carrier, $map);

// Do some kind of operation
$i = 0;
Expand Down
1 change: 0 additions & 1 deletion exporters/README.md

This file was deleted.

1 change: 0 additions & 1 deletion instrumentation/README.md

This file was deleted.

11 changes: 4 additions & 7 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ parameters:
tmpDir: var/cache/phpstan
level: 5
paths:
- .
excludes_analyse:
- var
- vendor
- proto
- tests/TraceContext/W3CTestService
- examples # TODO: Remove this once examples are updated
- src
- tests
# - examples # TODO: Remove this once examples are updated

9 changes: 3 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@

<coverage processUncoveredFiles="true" disableCodeCoverageIgnore="false">
<include>
<directory>detectors</directory>
<directory>exporters</directory>
<directory>instrumentation</directory>
<directory>propagators</directory>
<directory>src</directory>
</include>
<exclude>
<directory suffix=".php">instrumentation/symfony/OtelSdkBundle/Resources</directory>
<directory suffix=".php">src/Symfony/OtelSdkBundle/Resources</directory>
</exclude>
</coverage>

Expand All @@ -44,7 +41,7 @@

<testsuites>
<testsuite name="Unit Tests">
<directory>tests/unit</directory>
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

Expand Down
1 change: 0 additions & 1 deletion propagators/README.md

This file was deleted.

7 changes: 2 additions & 5 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
<directory name="var"/>
<directory name="vendor"/>
<directory name="examples"/> <!-- TODO: Remove this once examples are updated -->
<directory name="instrumentation/symfony/OtelSdkBundle/Resources"/>
<directory name="tests/integration/instrumentation/Symfony/OtelSdkBundle"/>
<directory name="tests/unit/instrumentation/Symfony/OtelSdkBundle"/>
<directory name="instrumentation/symfony/OtelSdkBundle/Resources"/>
<file name="instrumentation/symfony/OtelSdkBundle/DependencyInjection/Configuration.php"/>
<directory name="src/Symfony/OtelSdkBundle/Resources"/>
<file name="src/Symfony/OtelSdkBundle/DependencyInjection/Configuration.php"/>
</ignoreFiles>
</projectFiles>
<plugins>
Expand Down
4 changes: 2 additions & 2 deletions detectors/aws/Ec2Detector.php → src/Aws/Ec2/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* limitations under the License.
*/

namespace Detectors\Aws;
namespace OpenTelemetry\Aws\Ec2;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
Expand All @@ -32,7 +32,7 @@
* and return a Resource populated with metadata about the EC2
* instance. Returns an empty Resource if detection fails.
*/
class Ec2Detector
class Detector
{
private const SCHEME = 'http://';
private const AWS_IDMS_ENDPOINT = '169.254.169.254';
Expand Down
28 changes: 28 additions & 0 deletions src/Aws/Ecs/DataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Aws\Ecs;

class DataProvider
{
private const DEFAULT_CGROUP_PATH = '/proc/self/cgroup';

/**
* Returns the host name of the container the process is in.
* This would be the os the container is running on,
* i.e. the platform on which it is deployed
*/
public function getHostName()
{
return php_uname('n');
}

/**
* Get data from the Cgroup file
*/
public function getCgroupData()
{
return file(self::DEFAULT_CGROUP_PATH, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
}
33 changes: 3 additions & 30 deletions detectors/aws/EcsDetector.php → src/Aws/Ecs/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

namespace Detectors\Aws;
namespace OpenTelemetry\Aws\Ecs;

use OpenTelemetry\SDK\Resource\ResourceConstants;
use OpenTelemetry\SDK\Resource\ResourceInfo;
Expand All @@ -28,7 +28,7 @@
* ECS and return a {@link Resource} populated with data about the ECS
* plugins of AWS ˜X-Ray. Returns an empty Resource if detection fails.
*/
class EcsDetector
class Detector
{
private const ECS_METADATA_KEY_V4 = 'ECS_CONTAINER_METADATA_URI_V4';
private const ECS_METADATA_KEY_V3 = 'ECS_CONTAINER_METADATA_URI';
Expand All @@ -37,7 +37,7 @@ class EcsDetector

private $processData;

public function __construct(EcsProcessDataProvider $processData)
public function __construct(DataProvider $processData)
{
$this->processData = $processData;
}
Expand Down Expand Up @@ -91,30 +91,3 @@ private function getContainerId()
return null;
}
}

/**
* Separated from above class to be able to test using
* mock values through unit tests
*/
class EcsProcessDataProvider
{
private const DEFAULT_CGROUP_PATH = '/proc/self/cgroup';

/**
* Returns the host name of the container the process is in.
* This would be the os the container is running on,
* i.e. the platform on which it is deployed
*/
public function getHostName()
{
return php_uname('n');
}

/**
* Get data from the Cgroup file
*/
public function getCgroupData()
{
return file(self::DEFAULT_CGROUP_PATH, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
}
35 changes: 35 additions & 0 deletions src/Aws/Eks/DataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Aws\Eks;

class DataProvider
{
private const DEFAULT_CGROUP_PATH = '/proc/self/cgroup';
private const K8S_TOKEN_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/token';
private const K8S_CERT_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt';

public function getK8sHeader()
{
$credHeader = file_get_contents(self::K8S_TOKEN_PATH);

if ($credHeader) {
return 'Bearer' . $credHeader;
}

//TODO: Add log 'Unable to load K8s client token'
return null;
}

// Check if there exists a k8s certification file
public function isK8s()
{
return file_get_contents(self::K8S_CERT_PATH);
}

public function getCgroupData()
{
return file(self::DEFAULT_CGROUP_PATH, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
}
Loading

0 comments on commit 1536b14

Please sign in to comment.