functions.php
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
Return values
TraceIdspan_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
Return values
SpanIdbaggage()
Create a Baggage.
baggage([array<string, string> $entries = [] ]) : Baggage
Parameters
- $entries : array<string, string> = []
-
Initial key-value entries
Return values
Baggagecontext()
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
Contextmemory_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
MemoryContextStorageresource()
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
Resourcespan_context()
Create a SpanContext.
span_context(TraceId $traceId, SpanId $spanId[, null|SpanId $parentSpanId = null ]) : SpanContext
Parameters
- $traceId : TraceId
-
The trace ID
- $spanId : SpanId
-
The span ID
- $parentSpanId : null|SpanId = null
-
Optional parent span ID
Return values
SpanContextspan_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
GenericEventspan_link()
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
SpanLinkspan_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
SpanLimitslog_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
LogRecordLimitsmetric_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
MetricLimitsvoid_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
VoidSpanProcessorvoid_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
VoidMetricProcessorvoid_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
VoidLogProcessorvoid_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
VoidSpanExportervoid_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
VoidMetricExportervoid_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
VoidLogExportermemory_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
MemorySpanExportermemory_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
MemoryMetricExportermemory_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
MemoryLogExportermemory_span_processor()
Create a MemorySpanProcessor.
memory_span_processor(SpanExporter $exporter) : MemorySpanProcessor
Span processor that stores spans in memory and exports via configured exporter. Useful for testing.
Parameters
- $exporter : SpanExporter
-
The exporter to send spans to
Return values
MemorySpanProcessormemory_metric_processor()
Create a MemoryMetricProcessor.
memory_metric_processor(MetricExporter $exporter) : MemoryMetricProcessor
Metric processor that stores metrics in memory and exports via configured exporter. Useful for testing.
Parameters
- $exporter : MetricExporter
-
The exporter to send metrics to
Return values
MemoryMetricProcessormemory_log_processor()
Create a MemoryLogProcessor.
memory_log_processor(LogExporter $exporter) : MemoryLogProcessor
Log processor that stores log records in memory and exports via configured exporter. Useful for testing.
Parameters
- $exporter : LogExporter
-
The exporter to send logs to
Return values
MemoryLogProcessortracer_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
TracerProviderlogger_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
LoggerProvidermeter_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
MeterProvidertelemetry()
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
Telemetryinstrumentation_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
InstrumentationScopebatching_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
BatchingSpanProcessorpass_through_span_processor()
Create a PassThroughSpanProcessor.
pass_through_span_processor(SpanExporter $exporter) : PassThroughSpanProcessor
Exports each span immediately when it ends. Useful for debugging where immediate visibility is more important than performance.
Parameters
- $exporter : SpanExporter
-
The exporter to send spans to
Return values
PassThroughSpanProcessorbatching_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
BatchingMetricProcessorpass_through_metric_processor()
Create a PassThroughMetricProcessor.
pass_through_metric_processor(MetricExporter $exporter) : PassThroughMetricProcessor
Exports each metric immediately when processed. Useful for debugging where immediate visibility is more important than performance.
Parameters
- $exporter : MetricExporter
-
The exporter to send metrics to
Return values
PassThroughMetricProcessorbatching_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
BatchingLogProcessorpass_through_log_processor()
Create a PassThroughLogProcessor.
pass_through_log_processor(LogExporter $exporter) : PassThroughLogProcessor
Exports each log record immediately when processed. Useful for debugging where immediate visibility is more important than performance.
Parameters
- $exporter : LogExporter
-
The exporter to send logs to
Return values
PassThroughLogProcessorseverity_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
SeverityFilteringLogProcessorconsole_span_exporter()
Create a ConsoleSpanExporter.
console_span_exporter([bool $colors = true ][, ConsoleSpanOptions $options = new ConsoleSpanOptions() ]) : ConsoleSpanExporter
Outputs spans to the console with ASCII table formatting. Useful for debugging and development.
Parameters
- $colors : bool = true
-
Whether to use ANSI colors (default: true)
- $options : ConsoleSpanOptions = new ConsoleSpanOptions()
-
Display options for the exporter
Return values
ConsoleSpanExporterconsole_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
ConsoleMetricExporterconsole_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
ConsoleLogExporterconsole_span_options()
Create ConsoleSpanOptions with all display options enabled (default behavior).
console_span_options() : ConsoleSpanOptions
Return values
ConsoleSpanOptionsconsole_span_options_minimal()
Create ConsoleSpanOptions with minimal display (legacy compact format).
console_span_options_minimal() : ConsoleSpanOptions
Return values
ConsoleSpanOptionsconsole_log_options()
Create ConsoleLogOptions with all display options enabled (default behavior).
console_log_options() : ConsoleLogOptions
Return values
ConsoleLogOptionsconsole_log_options_minimal()
Create ConsoleLogOptions with minimal display (legacy compact format).
console_log_options_minimal() : ConsoleLogOptions
Return values
ConsoleLogOptionsconsole_metric_options()
Create ConsoleMetricOptions with all display options enabled (default behavior).
console_metric_options() : ConsoleMetricOptions
Return values
ConsoleMetricOptionsconsole_metric_options_minimal()
Create ConsoleMetricOptions with minimal display (legacy compact format).
console_metric_options_minimal() : ConsoleMetricOptions
Return values
ConsoleMetricOptionsalways_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
AlwaysOnExemplarFilteralways_off_exemplar_filter()
Create an AlwaysOffExemplarFilter.
always_off_exemplar_filter() : AlwaysOffExemplarFilter
Never records exemplars. Use this filter to disable exemplar collection entirely for performance optimization.
Return values
AlwaysOffExemplarFiltertrace_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
TraceBasedExemplarFilterpropagation_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
PropagationContextarray_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
ArrayCarriersuperglobal_carrier()
Create a SuperglobalCarrier.
superglobal_carrier() : SuperglobalCarrier
Read-only carrier that extracts context from PHP superglobals ($_SERVER, $_GET, $_POST, $_COOKIE).
Return values
SuperglobalCarrierw3c_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
W3CTraceContextw3c_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
W3CBaggagecomposite_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
CompositePropagatorchain_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
ChainDetectoros_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
OsDetectorhost_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
HostDetectorprocess_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
ProcessDetectorenvironment_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
EnvironmentDetectorcomposer_detector()
Create a ComposerDetector.
composer_detector() : ComposerDetector
Detects service.name and service.version from Composer's InstalledVersions using the root package information.
Return values
ComposerDetectormanual_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
ManualDetectorcaching_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
CachingDetectorresource_detector()
Create a resource detector chain.
resource_detector([array<string|int, ResourceDetector> $detectors = [] ]) : ChainDetector
When no detectors are provided, uses the default detector chain:
- OsDetector - Operating system information
- HostDetector - Host information
- ProcessDetector - Process information
- ComposerDetector - Service information from Composer
- 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)