Flow PHP

DSL

Functions

trace_id()

Create a TraceId.

trace_id([null|string $hex = null ]) : TraceId

If a hex string is provided, creates a TraceId from it. Otherwise, generates a new random TraceId.

Parameters
$hex : null|string = null

Optional 32-character hexadecimal string

Tags
throws
InvalidArgumentException

if the hex string is invalid

Return values
TraceId

span_id()

Create a SpanId.

span_id([null|string $hex = null ]) : SpanId

If a hex string is provided, creates a SpanId from it. Otherwise, generates a new random SpanId.

Parameters
$hex : null|string = null

Optional 16-character hexadecimal string

Tags
throws
InvalidArgumentException

if the hex string is invalid

Return values
SpanId

baggage()

Create a Baggage.

baggage([array<string, string> $entries = [] ]) : Baggage
Parameters
$entries : array<string, string> = []

Initial key-value entries

Return values
Baggage

context()

Create a Context.

context([null|TraceId $traceId = null ][, null|Baggage $baggage = null ]) : Context

If no TraceId is provided, generates a new one. If no Baggage is provided, creates an empty one.

Parameters
$traceId : null|TraceId = null

Optional TraceId to use

$baggage : null|Baggage = null

Optional Baggage to use

Return values
Context

memory_context_storage()

Create a MemoryContextStorage.

memory_context_storage([null|Context $context = null ]) : MemoryContextStorage

In-memory context storage for storing and retrieving the current context. A single instance should be shared across all providers within a request lifecycle.

Parameters
$context : null|Context = null

Optional initial context

Return values
MemoryContextStorage

resource()

Create a Resource.

resource([array<string, array<string|int, bool|float|int|string>|bool|float|int|string>|Attributes $attributes = [] ]) : Resource
Parameters
$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>|Attributes = []

Resource attributes

Return values
Resource

span_event()

Create a SpanEvent (GenericEvent) with an explicit timestamp.

span_event(string $name, DateTimeImmutable $timestamp[, array<string, array<string|int, bool|float|int|string>|bool|float|int|string>|Attributes $attributes = [] ]) : GenericEvent
Parameters
$name : string

Event name

$timestamp : DateTimeImmutable

Event timestamp

$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>|Attributes = []

Event attributes

Return values
GenericEvent

Create a SpanLink.

span_link(SpanContext $context[, array<string, array<string|int, bool|float|int|string>|bool|float|int|string>|Attributes $attributes = [] ]) : SpanLink
Parameters
$context : SpanContext

The linked span context

$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>|Attributes = []

Link attributes

Return values
SpanLink

span_limits()

Create SpanLimits configuration.

span_limits([int $attributeCountLimit = 128 ][, int $eventCountLimit = 128 ][, int $linkCountLimit = 128 ][, int $attributePerEventCountLimit = 128 ][, int $attributePerLinkCountLimit = 128 ][, null|int $attributeValueLengthLimit = null ]) : SpanLimits

SpanLimits controls the maximum amount of data a span can collect, preventing unbounded memory growth and ensuring reasonable span sizes.

Parameters
$attributeCountLimit : int = 128

Maximum number of attributes per span

$eventCountLimit : int = 128

Maximum number of events per span

$linkCountLimit : int = 128

Maximum number of links per span

$attributePerEventCountLimit : int = 128

Maximum number of attributes per event

$attributePerLinkCountLimit : int = 128

Maximum number of attributes per link

$attributeValueLengthLimit : null|int = null

Maximum length for string attribute values (null = unlimited)

Return values
SpanLimits

log_record_limits()

Create LogRecordLimits configuration.

log_record_limits([int $attributeCountLimit = 128 ][, null|int $attributeValueLengthLimit = null ]) : LogRecordLimits

LogRecordLimits controls the maximum amount of data a log record can collect, preventing unbounded memory growth and ensuring reasonable log record sizes.

Parameters
$attributeCountLimit : int = 128

Maximum number of attributes per log record

$attributeValueLengthLimit : null|int = null

Maximum length for string attribute values (null = unlimited)

Return values
LogRecordLimits

metric_limits()

Create MetricLimits configuration.

metric_limits([int $cardinalityLimit = 2000 ]) : MetricLimits

MetricLimits controls the maximum cardinality (unique attribute combinations) per metric instrument, preventing memory exhaustion from high-cardinality attributes.

When the cardinality limit is exceeded, new attribute combinations are aggregated into an overflow data point with otel.metric.overflow: true attribute.

Note: Unlike spans and logs, metrics are EXEMPT from attribute count and value length limits per the OpenTelemetry specification. Only cardinality is limited.

Parameters
$cardinalityLimit : int = 2000

Maximum number of unique attribute combinations per instrument

Return values
MetricLimits

void_span_processor()

Create a VoidSpanProcessor.

void_span_processor() : VoidSpanProcessor

No-op span processor that discards all data. Use this when tracing is disabled to minimize overhead.

Return values
VoidSpanProcessor

void_metric_processor()

Create a VoidMetricProcessor.

void_metric_processor() : VoidMetricProcessor

No-op metric processor that discards all data. Use this when metrics collection is disabled to minimize overhead.

Return values
VoidMetricProcessor

void_log_processor()

Create a VoidLogProcessor.

void_log_processor() : VoidLogProcessor

No-op log processor that discards all data. Use this when logging is disabled to minimize overhead.

Return values
VoidLogProcessor

void_span_exporter()

Create a VoidSpanExporter.

void_span_exporter() : VoidSpanExporter

No-op span exporter that discards all data. Use this when telemetry export is disabled to minimize overhead.

Return values
VoidSpanExporter

void_metric_exporter()

Create a VoidMetricExporter.

void_metric_exporter() : VoidMetricExporter

No-op metric exporter that discards all data. Use this when telemetry export is disabled to minimize overhead.

Return values
VoidMetricExporter

void_log_exporter()

Create a VoidLogExporter.

void_log_exporter() : VoidLogExporter

No-op log exporter that discards all data. Use this when telemetry export is disabled to minimize overhead.

Return values
VoidLogExporter

memory_span_exporter()

Create a MemorySpanExporter.

memory_span_exporter() : MemorySpanExporter

Span exporter that stores data in memory. Provides direct getter access to exported spans. Useful for testing and inspection without serialization.

Return values
MemorySpanExporter

memory_metric_exporter()

Create a MemoryMetricExporter.

memory_metric_exporter() : MemoryMetricExporter

Metric exporter that stores data in memory. Provides direct getter access to exported metrics. Useful for testing and inspection without serialization.

Return values
MemoryMetricExporter

memory_log_exporter()

Create a MemoryLogExporter.

memory_log_exporter() : MemoryLogExporter

Log exporter that stores data in memory. Provides direct getter access to exported log entries. Useful for testing and inspection without serialization.

Return values
MemoryLogExporter

tracer_provider()

Create a TracerProvider.

tracer_provider(SpanProcessor $processor, ClockInterface $clock, ContextStorage $contextStorage[, Sampler $sampler = new AlwaysOnSampler() ][, SpanLimits $limits = new SpanLimits() ]) : TracerProvider

Creates a provider that uses a SpanProcessor for processing spans. For void/disabled tracing, pass void_processor(). For memory-based testing, pass memory_processor() with exporters.

Parameters
$processor : SpanProcessor

The processor for spans

$clock : ClockInterface

The clock for timestamps

$contextStorage : ContextStorage

Storage for context propagation

$sampler : Sampler = new AlwaysOnSampler()

Sampling strategy for spans

$limits : SpanLimits = new SpanLimits()

Limits for span attributes, events, and links

Return values
TracerProvider

logger_provider()

Create a LoggerProvider.

logger_provider(LogProcessor $processor, ClockInterface $clock, ContextStorage $contextStorage[, LogRecordLimits $limits = new LogRecordLimits() ]) : LoggerProvider

Creates a provider that uses a LogProcessor for processing logs. For void/disabled logging, pass void_processor(). For memory-based testing, pass memory_processor() with exporters.

Parameters
$processor : LogProcessor

The processor for logs

$clock : ClockInterface

The clock for timestamps

$contextStorage : ContextStorage

Storage for span correlation

$limits : LogRecordLimits = new LogRecordLimits()

Limits for log record attributes

Return values
LoggerProvider

meter_provider()

Create a MeterProvider.

meter_provider(MetricProcessor $processor, ClockInterface $clock[, AggregationTemporality $temporality = AggregationTemporality::CUMULATIVE ][, ExemplarFilter $exemplarFilter = new TraceBasedExemplarFilter() ][, MetricLimits $limits = new MetricLimits() ]) : MeterProvider

Creates a provider that uses a MetricProcessor for processing metrics. For void/disabled metrics, pass void_processor(). For memory-based testing, pass memory_processor() with exporters.

Parameters
$processor : MetricProcessor

The processor for metrics

$clock : ClockInterface

The clock for timestamps

$temporality : AggregationTemporality = AggregationTemporality::CUMULATIVE

Aggregation temporality for metrics

$exemplarFilter : ExemplarFilter = new TraceBasedExemplarFilter()

Filter for exemplar sampling (default: TraceBasedExemplarFilter)

$limits : MetricLimits = new MetricLimits()

Cardinality limits for metric instruments

Return values
MeterProvider

telemetry()

Create a new Telemetry instance with the given providers.

telemetry(resource $resource[, null|TracerProvider $tracerProvider = null ][, null|MeterProvider $meterProvider = null ][, null|LoggerProvider $loggerProvider = null ]) : Telemetry

If providers are not specified, void providers (no-op) are used.

Parameters
$resource : resource

The resource describing the entity producing telemetry

$tracerProvider : null|TracerProvider = null

The tracer provider (null for void/disabled)

$meterProvider : null|MeterProvider = null

The meter provider (null for void/disabled)

$loggerProvider : null|LoggerProvider = null

The logger provider (null for void/disabled)

Return values
Telemetry

instrumentation_scope()

Create an InstrumentationScope.

instrumentation_scope(string $name[, string $version = 'unknown' ][, null|string $schemaUrl = null ][, Attributes $attributes = new Attributes() ]) : InstrumentationScope
Parameters
$name : string

The instrumentation scope name

$version : string = 'unknown'

The instrumentation scope version

$schemaUrl : null|string = null

Optional schema URL

$attributes : Attributes = new Attributes()
Return values
InstrumentationScope

batching_span_processor()

Create a BatchingSpanProcessor.

batching_span_processor(SpanExporter $exporter[, int $batchSize = 512 ]) : BatchingSpanProcessor

Collects spans in memory and exports them in batches for efficiency. Spans are exported when batch size is reached, flush() is called, or shutdown().

Parameters
$exporter : SpanExporter

The exporter to send spans to

$batchSize : int = 512

Number of spans to collect before exporting (default 512)

Return values
BatchingSpanProcessor

batching_metric_processor()

Create a BatchingMetricProcessor.

batching_metric_processor(MetricExporter $exporter[, int $batchSize = 512 ]) : BatchingMetricProcessor

Collects metrics in memory and exports them in batches for efficiency. Metrics are exported when batch size is reached, flush() is called, or shutdown().

Parameters
$exporter : MetricExporter

The exporter to send metrics to

$batchSize : int = 512

Number of metrics to collect before exporting (default 512)

Return values
BatchingMetricProcessor

batching_log_processor()

Create a BatchingLogProcessor.

batching_log_processor(LogExporter $exporter[, int $batchSize = 512 ]) : BatchingLogProcessor

Collects log records in memory and exports them in batches for efficiency. Logs are exported when batch size is reached, flush() is called, or shutdown().

Parameters
$exporter : LogExporter

The exporter to send logs to

$batchSize : int = 512

Number of logs to collect before exporting (default 512)

Return values
BatchingLogProcessor

severity_filtering_log_processor()

Create a SeverityFilteringLogProcessor.

severity_filtering_log_processor(LogProcessor $processor[, Severity $minimumSeverity = Severity::INFO ]) : SeverityFilteringLogProcessor

Filters log entries based on minimum severity level. Only entries at or above the configured threshold are passed to the wrapped processor.

Parameters
$processor : LogProcessor

The processor to wrap

$minimumSeverity : Severity = Severity::INFO

Minimum severity level (default: INFO)

Return values
SeverityFilteringLogProcessor

console_metric_exporter()

Create a ConsoleMetricExporter.

console_metric_exporter([bool $colors = true ][, ConsoleMetricOptions $options = new ConsoleMetricOptions() ]) : ConsoleMetricExporter

Outputs metrics to the console with ASCII table formatting. Useful for debugging and development.

Parameters
$colors : bool = true

Whether to use ANSI colors (default: true)

$options : ConsoleMetricOptions = new ConsoleMetricOptions()

Display options for the exporter

Return values
ConsoleMetricExporter

console_log_exporter()

Create a ConsoleLogExporter.

console_log_exporter([bool $colors = true ][, null|int $maxBodyLength = 100 ][, ConsoleLogOptions $options = new ConsoleLogOptions() ]) : ConsoleLogExporter

Outputs log records to the console with severity-based coloring. Useful for debugging and development.

Parameters
$colors : bool = true

Whether to use ANSI colors (default: true)

$maxBodyLength : null|int = 100

Maximum length for body+attributes column (null = no limit, default: 100)

$options : ConsoleLogOptions = new ConsoleLogOptions()

Display options for the exporter

Return values
ConsoleLogExporter

always_on_exemplar_filter()

Create an AlwaysOnExemplarFilter.

always_on_exemplar_filter() : AlwaysOnExemplarFilter

Records exemplars whenever a span context is present. Use this filter for debugging or when complete trace context is important.

Return values
AlwaysOnExemplarFilter

trace_based_exemplar_filter()

Create a TraceBasedExemplarFilter.

trace_based_exemplar_filter() : TraceBasedExemplarFilter

Records exemplars only when the span is sampled (has SAMPLED trace flag). This is the default filter, balancing exemplar collection with performance.

Return values
TraceBasedExemplarFilter

propagation_context()

Create a PropagationContext.

propagation_context([null|SpanContext $spanContext = null ][, null|Baggage $baggage = null ]) : PropagationContext

Value object containing both trace context (SpanContext) and application data (Baggage) that can be propagated across process boundaries.

Parameters
$spanContext : null|SpanContext = null

Optional span context

$baggage : null|Baggage = null

Optional baggage

Return values
PropagationContext

array_carrier()

Create an ArrayCarrier.

array_carrier([array<string, string> $data = [] ]) : ArrayCarrier

Carrier backed by an associative array with case-insensitive key lookup.

Parameters
$data : array<string, string> = []

Initial carrier data

Return values
ArrayCarrier

superglobal_carrier()

Create a SuperglobalCarrier.

superglobal_carrier() : SuperglobalCarrier

Read-only carrier that extracts context from PHP superglobals ($_SERVER, $_GET, $_POST, $_COOKIE).

Return values
SuperglobalCarrier

w3c_trace_context()

Create a W3CTraceContext propagator.

w3c_trace_context() : W3CTraceContext

Implements W3C Trace Context specification for propagating trace context using traceparent and tracestate headers.

Return values
W3CTraceContext

w3c_baggage()

Create a W3CBaggage propagator.

w3c_baggage() : W3CBaggage

Implements W3C Baggage specification for propagating application-specific key-value pairs using the baggage header.

Return values
W3CBaggage

composite_propagator()

Create a CompositePropagator.

composite_propagator(Propagator ...$propagators) : CompositePropagator

Combines multiple propagators into one. On extract, all propagators are invoked and their contexts are merged. On inject, all propagators are invoked.

Parameters
$propagators : Propagator

The propagators to combine

Return values
CompositePropagator

chain_detector()

Create a ChainDetector.

chain_detector(ResourceDetector ...$detectors) : ChainDetector

Combines multiple resource detectors into a chain. Detectors are executed in order and their results are merged. Later detectors take precedence over earlier ones when there are conflicting attribute keys.

Parameters
$detectors : ResourceDetector

The detectors to chain

Return values
ChainDetector

os_detector()

Create an OsDetector.

os_detector() : OsDetector

Detects operating system information including os.type, os.name, os.version, and os.description using PHP's php_uname() function.

Return values
OsDetector

host_detector()

Create a HostDetector.

host_detector() : HostDetector

Detects host information including host.name, host.arch, and host.id (from /etc/machine-id on Linux or IOPlatformUUID on macOS).

Return values
HostDetector

process_detector()

Create a ProcessDetector.

process_detector() : ProcessDetector

Detects process information including process.pid, process.executable.path, process.runtime.name (PHP), process.runtime.version, process.command, and process.owner (on POSIX systems).

Return values
ProcessDetector

environment_detector()

Create an EnvironmentDetector.

environment_detector() : EnvironmentDetector

Detects resource attributes from OpenTelemetry standard environment variables:

  • OTEL_SERVICE_NAME: Sets service.name attribute
  • OTEL_RESOURCE_ATTRIBUTES: Sets additional attributes in key=value,key2=value2 format
Return values
EnvironmentDetector

composer_detector()

Create a ComposerDetector.

composer_detector() : ComposerDetector

Detects service.name and service.version from Composer's InstalledVersions using the root package information.

Return values
ComposerDetector

manual_detector()

Create a ManualDetector.

manual_detector(array<string, array<string|int, bool|float|int|string>|bool|float|int|string> $attributes) : ManualDetector

Returns manually specified resource attributes. Use this when you need to set attributes explicitly rather than detecting them automatically.

Parameters
$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string>

Resource attributes

Return values
ManualDetector

caching_detector()

Create a CachingDetector.

caching_detector(ResourceDetector $detector[, null|string $cachePath = null ]) : CachingDetector

Wraps another detector and caches its results to a file. On subsequent calls, returns the cached resource instead of running detection again.

Parameters
$detector : ResourceDetector

The detector to wrap

$cachePath : null|string = null

Cache file path (default: sys_get_temp_dir()/flow_telemetry_resource.cache)

Return values
CachingDetector

resource_detector()

Create a resource detector chain.

resource_detector([array<string|int, ResourceDetector$detectors = [] ]) : ChainDetector

When no detectors are provided, uses the default detector chain:

  1. OsDetector - Operating system information
  2. HostDetector - Host information
  3. ProcessDetector - Process information
  4. ComposerDetector - Service information from Composer
  5. EnvironmentDetector - Environment variable overrides (highest precedence)

When detectors are provided, uses only those detectors.

Parameters
$detectors : array<string|int, ResourceDetector> = []

Optional custom detectors (empty = use defaults)

Return values
ChainDetector

        
On this page

Search results