Metric
Read onlyYes
FinalYes
Represents a single metric measurement.
A Metric captures a point-in-time measurement with its metadata, including the instrument type, value, and categorization attributes.
Example:
$metric = new Metric(
name: 'http.requests',
type: MetricType::COUNTER,
value: 1,
attributes: Attributes::create(['http.method' => 'GET']),
timestamp: new \DateTimeImmutable(),
scope: $instrumentationScope,
);
Properties
- $attributes : Attributes
- $description : string|null
- $exemplars : array<string|int, mixed>
- $name : string
- $resource : Resource
- $scope : InstrumentationScope
- $temporality : AggregationTemporality
- $timestamp : DateTimeImmutable
- $type : MetricType
- $unit : string|null
- $value : int|float
Methods
- __construct() : mixed
- fromArray() : self
- Create a Metric from a normalized array representation.
-
normalize()
: array{name: string, type: string, value: float|int, attributes: array
, timestamp: string, resource: array{attributes: array }, scope: array{name: string, version: string, schemaUrl: null|string, attributes: array }, unit: null|string, description: null|string, temporality: int} - Normalize the Metric to an array representation for serialization.
Properties
$attributes
public
Attributes
$attributes
$description
public
string|null
$description
= null
$exemplars
public
array<string|int, mixed>
$exemplars
= []
$name
public
string
$name
$resource
public
Resource
$resource
$scope
public
InstrumentationScope
$scope
$temporality
public
AggregationTemporality
$temporality
= AggregationTemporality::CUMULATIVE
$timestamp
public
DateTimeImmutable
$timestamp
$type
public
MetricType
$type
$unit
public
string|null
$unit
= null
$value
public
int|float
$value
Methods
__construct()
public
__construct(string $name, MetricType $type, float|int $value, Attributes $attributes, DateTimeImmutable $timestamp, resource $resource, InstrumentationScope $scope[, null|string $unit = null ][, null|string $description = null ][, AggregationTemporality $temporality = AggregationTemporality::CUMULATIVE ][, array<string|int, Exemplar> $exemplars = [] ]) : mixed
Parameters
- $name : string
-
Metric name
- $type : MetricType
-
Type of metric instrument
- $value : float|int
-
Recorded value
- $attributes : Attributes
-
Categorization attributes
- $timestamp : DateTimeImmutable
-
When the measurement was recorded
- $resource : resource
-
The resource context for this metric
- $scope : InstrumentationScope
-
The instrumentation scope that created this metric
- $unit : null|string = null
-
Unit of measurement
- $description : null|string = null
-
Human-readable description
- $temporality : AggregationTemporality = AggregationTemporality::CUMULATIVE
-
How the metric is aggregated over time
- $exemplars : array<string|int, Exemplar> = []
-
Sample measurements with trace context for drill-down
fromArray()
Create a Metric from a normalized array representation.
public
static fromArray(array{name: string, type: string, value: float|int, attributes: array, timestamp: string, resource: array{attributes: array}, scope: array{name: string, version: string, schemaUrl: null|string, attributes: array}, unit: null|string, description: null|string, temporality?: int} $data) : self
Parameters
-
$data
: array{name: string, type: string, value: float|int, attributes: array
, timestamp: string, resource: array{attributes: array }, scope: array{name: string, version: string, schemaUrl: null|string, attributes: array }, unit: null|string, description: null|string, temporality?: int} -
Normalized Metric data
Return values
selfnormalize()
Normalize the Metric to an array representation for serialization.
public
normalize() : array{name: string, type: string, value: float|int, attributes: array, timestamp: string, resource: array{attributes: array}, scope: array{name: string, version: string, schemaUrl: null|string, attributes: array}, unit: null|string, description: null|string, temporality: int}