Skip to content

Commit

Permalink
updating/removing phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Feb 29, 2024
1 parent be34c22 commit d81115a
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace OpenTelemetry\Example;

use OpenTelemetry\API\Globals;
use OpenTelemetry\SDK\Trace\TracerProviderInterface;

putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=console');
Expand All @@ -14,12 +13,14 @@

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

$tracerProvider = Globals::tracerProvider();
/**
* Demonstrates batch span processing which also emits metrics for the internal state
* of the processor (eg spans received, queue length)
*/

$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');
echo 'Starting ConsoleSpanExporter with BatchSpanProcessor and metrics' . PHP_EOL;

$span = $tracer->spanBuilder('root')->startSpan();
$span->end();
$tracer = Globals::tracerProvider()->getTracer('io.opentelemetry.contrib.php');
$tracer->spanBuilder('root')->startSpan()->end();

echo PHP_EOL;
$tracerProvider instanceof TracerProviderInterface && $tracerProvider->shutdown();
echo PHP_EOL . 'Example complete! ' . PHP_EOL;
3 changes: 0 additions & 3 deletions src/API/Trace/Propagation/TraceContextValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class TraceContextValidator
public const TRACE_FLAG_LENGTH = 2;
public const TRACE_VERSION_REGEX = '/^(?!ff)[\da-f]{2}$/';

/**
* @return bool Returns a value that indicates whether a trace version is valid.
*/
public static function isValidTraceVersion(string $traceVersion): bool
{
return 1 === preg_match(self::TRACE_VERSION_REGEX, $traceVersion);
Expand Down
4 changes: 1 addition & 3 deletions src/Contrib/Otlp/MetricExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ final class MetricExporter implements PushMetricExporterInterface, AggregationTe
private ProtobufSerializer $serializer;

/**
* @param string|Temporality|null $temporality
*
* @psalm-param TransportInterface<SUPPORTED_CONTENT_TYPES> $transport
*/
public function __construct(
private TransportInterface $transport,
private $temporality = null
private string|Temporality|null $temporality = null
) {
if (!class_exists('\Google\Protobuf\Api')) {
throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)');
Expand Down
28 changes: 12 additions & 16 deletions src/Contrib/Otlp/ProtobufSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,17 @@
/**
* @internal
*
* @psalm-type SUPPORTED_CONTENT_TYPES = self::PROTOBUF|self::JSON|self::NDJSON
* @psalm-type SUPPORTED_CONTENT_TYPES = ContentTypes::PROTOBUF|ContentTypes::JSON|ContentTypes::NDJSON
*/
final class ProtobufSerializer
{
private const PROTOBUF = 'application/x-protobuf';
private const JSON = 'application/json';
private const NDJSON = 'application/x-ndjson';

private function __construct(private string $contentType)
{
}

public static function getDefault(): ProtobufSerializer
{
return new self(self::PROTOBUF);
return new self(ContentTypes::PROTOBUF);
}

/**
Expand All @@ -51,35 +47,35 @@ public static function getDefault(): ProtobufSerializer
public static function forTransport(TransportInterface $transport): ProtobufSerializer
{
return match ($contentType = $transport->contentType()) {
self::PROTOBUF, self::JSON, self::NDJSON => new self($contentType),
ContentTypes::PROTOBUF, ContentTypes::JSON, ContentTypes::NDJSON => new self($contentType),
default => throw new InvalidArgumentException(sprintf('Not supported content type "%s"', $contentType)),
};
}

public function serializeTraceId(string $traceId): string
{
return match ($this->contentType) {
self::PROTOBUF => $traceId,
self::JSON, self::NDJSON => base64_decode(bin2hex($traceId)),
ContentTypes::PROTOBUF => $traceId,
ContentTypes::JSON, ContentTypes::NDJSON => base64_decode(bin2hex($traceId)),
default => throw new AssertionError(),
};
}

public function serializeSpanId(string $spanId): string
{
return match ($this->contentType) {
self::PROTOBUF => $spanId,
self::JSON, self::NDJSON => base64_decode(bin2hex($spanId)),
ContentTypes::PROTOBUF => $spanId,
ContentTypes::JSON, ContentTypes::NDJSON => base64_decode(bin2hex($spanId)),
default => throw new AssertionError(),
};
}

public function serialize(Message $message): string
{
return match ($this->contentType) {
self::PROTOBUF => $message->serializeToString(),
self::JSON => self::postProcessJsonEnumValues($message, $message->serializeToJsonString()),
self::NDJSON => self::postProcessJsonEnumValues($message, $message->serializeToJsonString()) . "\n",
ContentTypes::PROTOBUF => $message->serializeToString(),
ContentTypes::JSON => self::postProcessJsonEnumValues($message, $message->serializeToJsonString()),
ContentTypes::NDJSON => self::postProcessJsonEnumValues($message, $message->serializeToJsonString()) . "\n",
default => throw new AssertionError(),
};
}
Expand All @@ -90,8 +86,8 @@ public function serialize(Message $message): string
public function hydrate(Message $message, string $payload): void
{
match ($this->contentType) {
self::PROTOBUF => $message->mergeFromString($payload),
self::JSON, self::NDJSON => $message->mergeFromJsonString($payload, true),
ContentTypes::PROTOBUF => $message->mergeFromString($payload),
ContentTypes::JSON, ContentTypes::NDJSON => $message->mergeFromJsonString($payload, true),
default => throw new AssertionError(),
};
}
Expand Down
4 changes: 0 additions & 4 deletions src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ final class CloudTraceFormatter

/**
* Generate a SpanContext object from the Trace Context header
*
* @return SpanContextInterface
*/
public static function deserialize(string $header) : SpanContextInterface
{
Expand All @@ -46,8 +44,6 @@ public static function deserialize(string $header) : SpanContextInterface

/**
* Convert a SpanContextInterface to header string
*
* @return string
*/
public static function serialize(SpanContextInterface $context) : string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ final class ExplicitBucketHistogramAggregation implements AggregationInterface
* @param list<float|int> $boundaries strictly ascending histogram bucket boundaries
*/
public function __construct(
/**
* @readonly
*/
/** @readonly */
public array $boundaries
) {
}
Expand Down
29 changes: 7 additions & 22 deletions src/SDK/Metrics/Data/Exemplar.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,17 @@

final class Exemplar
{

/**
* @param int|string $index
* @param float|int $value
*/
public function __construct(
private $index,
/**
* @readonly
*/
public $value,
/**
* @readonly
*/
private int|string $index,
/** @readonly */
public float|int $value,
/** @readonly */
public int $timestamp,
/**
* @readonly
*/
/** @readonly */
public AttributesInterface $attributes,
/**
* @readonly
*/
/** @readonly */
public ?string $traceId,
/**
* @readonly
*/
/** @readonly */
public ?string $spanId
) {
}
Expand Down
12 changes: 3 additions & 9 deletions src/SDK/Metrics/Data/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

final class Histogram implements DataInterface
{

/**
* @param iterable<HistogramDataPoint> $dataPoints
* @param string|Temporality $temporality
*/
public function __construct(
/**
* @readonly
*/
/** @readonly */
public iterable $dataPoints,
/**
* @readonly
*/
public $temporality
/** @readonly */
public string|Temporality $temporality
) {
}
}
49 changes: 13 additions & 36 deletions src/SDK/Metrics/Data/HistogramDataPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,29 @@
final class HistogramDataPoint
{
/**
* @param float|int $sum
* @param float|int $min
* @param float|int $max
* @param int[] $bucketCounts
* @param list<float|int> $explicitBounds
*/
public function __construct(
/**
* @readonly
*/
/** @readonly */
public int $count,
/**
* @readonly
*/
public $sum,
/**
* @readonly
*/
public $min,
/**
* @readonly
*/
public $max,
/**
* @readonly
*/
/** @readonly */
public float|int $sum,
/** @readonly */
public float|int $min,
/** @readonly */
public float|int $max,
/** @readonly */
public array $bucketCounts,
/**
* @readonly
*/
/** @readonly */
public array $explicitBounds,
/**
* @readonly
*/
/** @readonly */
public AttributesInterface $attributes,
/**
* @readonly
*/
/** @readonly */
public int $startTimestamp,
/**
* @readonly
*/
/** @readonly */
public int $timestamp,
/**
* @readonly
*/
/** @readonly */
public iterable $exemplars = []
) {
}
Expand Down
25 changes: 6 additions & 19 deletions src/SDK/Metrics/Data/NumberDataPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,16 @@

final class NumberDataPoint
{
/**
* @param float|int $value
*/
public function __construct(
/**
* @readonly
*/
public $value,
/**
* @readonly
*/
/** @readonly */
public float|int $value,
/** @readonly */
public AttributesInterface $attributes,
/**
* @readonly
*/
/** @readonly */
public int $startTimestamp,
/**
* @readonly
*/
/** @readonly */
public int $timestamp,
/**
* @readonly
*/
/** @readonly */
public iterable $exemplars = []
) {
}
Expand Down
16 changes: 4 additions & 12 deletions src/SDK/Metrics/Data/Sum.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@

final class Sum implements DataInterface
{

/**
* @param iterable<NumberDataPoint> $dataPoints
* @param string|Temporality $temporality
*/
public function __construct(
/**
* @readonly
*/
/** @readonly */
public iterable $dataPoints,
/**
* @readonly
*/
public $temporality,
/**
* @readonly
*/
/** @readonly */
public string|Temporality $temporality,
/** @readonly */
public bool $monotonic
) {
}
Expand Down
25 changes: 6 additions & 19 deletions src/SDK/Metrics/Instrument.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,16 @@

final class Instrument
{
/**
* @param string|InstrumentType $type
*/
public function __construct(
/**
* @readonly
*/
public $type,
/**
* @readonly
*/
/** @readonly */
public string|InstrumentType $type,
/** @readonly */
public string $name,
/**
* @readonly
*/
/** @readonly */
public ?string $unit,
/**
* @readonly
*/
/** @readonly */
public ?string $description,
/**
* @readonly
*/
/** @readonly */
public array $advisory = []
) {
}
Expand Down
Loading

0 comments on commit d81115a

Please sign in to comment.