Flow PHP

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

$description

public string|null $description = null

$exemplars

public array<string|int, mixed> $exemplars = []

$timestamp

public DateTimeImmutable $timestamp

$unit

public string|null $unit = null

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
self

normalize()

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}
Return values
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}

        
On this page

Search results