Skip to content

Commit

Permalink
Updated php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
riticksingh committed Nov 9, 2020
1 parent bdd4ca3 commit 16e6604
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
38 changes: 17 additions & 21 deletions contrib/Otlp/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request;
use Http\Adapter\Guzzle6\Client;
use OpenTelemetry\Sdk\Trace;
use OpenTelemetry\Trace as API;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Client\NetworkExceptionInterface;
use Psr\Http\Client\RequestExceptionInterface;
use OpenTelemetry\Sdk\Trace;
use OpenTelemetry\Trace as API;


class Exporter implements Trace\Exporter
{
/**
* @var string
*/
private $endpointURL;
private $endpointURL;

/**
* @var string
Expand Down Expand Up @@ -57,9 +56,9 @@ class Exporter implements Trace\Exporter
*/
private $spanConverter;

/**
* @var bool
*/
/**
* @var bool
*/
private $running = true;

/**
Expand All @@ -70,23 +69,21 @@ class Exporter implements Trace\Exporter

/**
* Exporter constructor.
* @param string $serviceName
* @param string $serviceName
*/
public function __construct(
$serviceName,
ClientInterface $client=null
)
{
) {

// Set default values based on presence of env variable
$this->endpointURL = getenv("OTEL_EXPORTER_OTLP_ENDPOINT") ?: "localhost:55680";
$this->protocol = getenv("OTEL_EXPORTER_OTLP_PROTOCOL") ?: "json";
$this->insecure = getenv("OTEL_EXPORTER_OTLP_INSECURE") ?: "false";
$this->certificateFile = getenv("OTEL_EXPORTER_OTLP_CERTIFICATE") ?: "none";
$this->headers[] = getenv("OTEL_EXPORTER_OTLP_HEADERS") ?: "none";
$this->compression = getenv("OTEL_EXPORTER_OTLP_COMPRESSION") ?: "none";
$this->timeout =(int)getenv("OTEL_EXPORTER_OTLP_TIMEOUT") ?: 10;

$this->endpointURL = getenv('OTEL_EXPORTER_OTLP_ENDPOINT') ?: 'localhost:55680';
$this->protocol = getenv('OTEL_EXPORTER_OTLP_PROTOCOL') ?: 'json';
$this->insecure = getenv('OTEL_EXPORTER_OTLP_INSECURE') ?: 'false';
$this->certificateFile = getenv('OTEL_EXPORTER_OTLP_CERTIFICATE') ?: 'none';
$this->headers[] = getenv('OTEL_EXPORTER_OTLP_HEADERS') ?: 'none';
$this->compression = getenv('OTEL_EXPORTER_OTLP_COMPRESSION') ?: 'none';
$this->timeout =(int) getenv('OTEL_EXPORTER_OTLP_TIMEOUT') ?: 10;

$this->client = $client ?? $this->createDefaultClient();
$this->spanConverter = new SpanConverter($serviceName);
Expand Down Expand Up @@ -118,9 +115,8 @@ public function export(iterable $spans): int

$this->headers[] = '';

if($this->protocol == "json") {
$headers = ['content-type' => 'application/json', "Content-Encoding" => "gzip"];

if ($this->protocol == 'json') {
$headers = ['content-type' => 'application/json', 'Content-Encoding' => 'gzip'];
}

$request = new Request('POST', $this->endpointURL, $this->headers, $json);
Expand Down
2 changes: 1 addition & 1 deletion contrib/Otlp/SpanConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function sanitiseTagValue($value)

public function convert(Span $span)
{
$spanParent = $span->getParent();
$spanParent = $span->getParent();
$row = [
'id' => $span->getContext()->getSpanId(),
'traceId' => $span->getContext()->getTraceId(),
Expand Down
7 changes: 3 additions & 4 deletions examples/AlwaysOnOTLPExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';


use OpenTelemetry\Contrib\Otlp\Exporter as OTLPExporter;
use OpenTelemetry\Sdk\Trace\Attributes;
use OpenTelemetry\Sdk\Trace\Clock;
Expand All @@ -22,19 +21,19 @@
API\SpanKind::KIND_INTERNAL
);
$Exporter = new OTLPExporter(
'OTLP Example Service');
'OTLP Example Service'
);

if (SamplingResult::RECORD_AND_SAMPLED === $samplingResult->getDecision()) {
echo 'Starting OTLPExample';
$tracer = (new TracerProvider())
->addSpanProcessor(new SimpleSpanProcessor($Exporter))
->getTracer('io.opentelemetry.contrib.php');


for ($i = 0; $i < 5; $i++) {
// start a span, register some events
$timestamp = Clock::get()->timestamp();
$span = $tracer->startAndActivateSpan('session.generate.span.' . microtime(true));
$span = $tracer->startAndActivateSpan('session.generate.span.' . microtime(true));

$spanParent = $span->getParent();
echo sprintf(
Expand Down
9 changes: 3 additions & 6 deletions tests/Contrib/Unit/OTLPExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
namespace OpenTelemetry\Tests\Contrib\Unit;

use GuzzleHttp\Psr7\Response;
use InvalidArgumentException;
use OpenTelemetry\Contrib\Otlp\Exporter;
use OpenTelemetry\Sdk\Trace\Span;
use OpenTelemetry\Sdk\Trace\SpanContext;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Client\NetworkExceptionInterface;
use Psr\Http\Client\RequestExceptionInterface;

class OTLPExporterTest extends TestCase
{
Expand All @@ -35,7 +33,7 @@ public function exporterResponseStatuses($responseStatus, $expected)
$expected,
$exporter->export([new Span('test.otlp.span', SpanContext::generate())])
);
}
}

public function exporterResponseStatusesDataProvider()
{
Expand Down Expand Up @@ -95,13 +93,12 @@ public function shouldBeOkToExporterEmptySpansCollection()
/**
* @test
*/
public function failsIfNotRunning()
public function failsIfNotRunning()
{
$exporter = new Exporter('test.otlp');
$span = $this->createMock(Span::class);
$exporter->shutdown();

$this->assertEquals(\OpenTelemetry\Sdk\Trace\Exporter::FAILED_NOT_RETRYABLE, $exporter->export([$span]));
}

}
}
2 changes: 1 addition & 1 deletion tests/Contrib/Unit/OTLPSpanConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ public function tagsAreCoercedCorrectlyToStrings()
// containing multiple value types from being passed to the Exporter.
$this->assertEquals($tags['list-of-random'], 'true,1,2,3,false,string-1,3.1415');
}
}
}

0 comments on commit 16e6604

Please sign in to comment.