Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Attributes/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* @phpstan-type AttributeType 'string'|'boolean'|'integer'|'double'
* @phpstan-type AttributeValue string|bool|int|float
* @phpstan-type AttributeValue string|bool|int|float|null
*/
class Attribute
{
Expand Down
4 changes: 2 additions & 2 deletions src/Metrics/MetricsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ final class MetricsAggregator
private $metrics;

/**
* @param int|float $value
* @param array<string, int|float|string|bool> $attributes
* @param int|float $value
* @param array<string, int|float|string|bool|null> $attributes
*/
public function add(
string $type,
Expand Down
12 changes: 6 additions & 6 deletions src/Metrics/TraceMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static function getInstance(): self
}

/**
* @param int|float $value
* @param array<string, int|float|string|bool> $attributes
* @param int|float $value
* @param array<string, int|float|string|bool|null> $attributes
*/
public function count(
string $name,
Expand All @@ -51,8 +51,8 @@ public function count(
}

/**
* @param int|float $value
* @param array<string, int|float|string|bool> $attributes
* @param int|float $value
* @param array<string, int|float|string|bool|null> $attributes
*/
public function distribution(
string $name,
Expand All @@ -70,8 +70,8 @@ public function distribution(
}

/**
* @param int|float $value
* @param array<string, int|float|string|bool> $attributes
* @param int|float $value
* @param array<string, int|float|string|bool|null> $attributes
*/
public function gauge(
string $name,
Expand Down
4 changes: 2 additions & 2 deletions src/Metrics/Types/CounterMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ final class CounterMetric extends Metric
private $value;

/**
* @param int|float $value
* @param array<string, int|float|string|bool> $attributes
* @param int|float $value
* @param array<string, int|float|string|bool|null> $attributes
*/
public function __construct(
string $name,
Expand Down
4 changes: 2 additions & 2 deletions src/Metrics/Types/DistributionMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ final class DistributionMetric extends Metric
private $value;

/**
* @param int|float $value
* @param array<string, int|float|string|bool> $attributes
* @param int|float $value
* @param array<string, int|float|string|bool|null> $attributes
*/
public function __construct(
string $name,
Expand Down
4 changes: 2 additions & 2 deletions src/Metrics/Types/GaugeMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ final class GaugeMetric extends Metric
private $value;

/**
* @param int|float $value
* @param array<string, int|float|string|bool> $attributes
* @param int|float $value
* @param array<string, int|float|string|bool|null> $attributes
*/
public function __construct(
string $name,
Expand Down
2 changes: 1 addition & 1 deletion src/Metrics/Types/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class Metric
private $unit;

/**
* @param array<string, int|float|string|bool> $attributes
* @param array<string, int|float|string|bool|null> $attributes
*/
public function __construct(
string $name,
Expand Down
14 changes: 14 additions & 0 deletions tests/Metrics/TraceMetricsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ public function testFloatType(): void
$this->assertEquals(10.50, $metric->getValue());
}

public function testNullAttributeValueIsStringified(): void
{
traceMetrics()->count('test-count', 2, ['foo' => null]);
traceMetrics()->flush();

$this->assertCount(1, StubTransport::$events);
$event = StubTransport::$events[0];

$this->assertCount(1, $event->getMetrics());
$metric = $event->getMetrics()[0];

$this->assertSame('null', $metric->getAttributes()->toSimpleArray()['foo']);
}

public function testInvalidTypeIsDiscarded(): void
{
// @phpstan-ignore-next-line
Expand Down