-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathfunctions.php
More file actions
972 lines (901 loc) · 32 KB
/
Copy pathfunctions.php
File metadata and controls
972 lines (901 loc) · 32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
<?php
declare(strict_types=1);
namespace Flow\Telemetry\DSL;
use Flow\ETL\Attribute\{DocumentationDSL, Module, Type as DSLType};
use Flow\Telemetry\{Attributes, Resource, Telemetry};
use Flow\Telemetry\Context\{Baggage, Context, ContextStorage, MemoryContextStorage, SpanId, TraceId};
use Flow\Telemetry\InstrumentationScope;
use Flow\Telemetry\Logger\{LogExporter, LogProcessor, LogRecordLimits, LoggerProvider, Severity};
use Flow\Telemetry\Logger\Processor\{BatchingLogProcessor, PassThroughLogProcessor, SeverityFilteringLogProcessor};
use Flow\Telemetry\Meter\{AggregationTemporality, MeterProvider, MetricExporter, MetricLimits, MetricProcessor};
use Flow\Telemetry\Meter\Exemplar\{AlwaysOffExemplarFilter, AlwaysOnExemplarFilter, ExemplarFilter, TraceBasedExemplarFilter};
use Flow\Telemetry\Meter\Processor\{BatchingMetricProcessor, PassThroughMetricProcessor};
use Flow\Telemetry\Propagation\{ArrayCarrier, CompositePropagator, PropagationContext, Propagator, SuperglobalCarrier, W3CBaggage, W3CTraceContext};
use Flow\Telemetry\Provider\Clock\SystemClock;
use Flow\Telemetry\Provider\Console\{ConsoleLogExporter, ConsoleLogOptions, ConsoleMetricExporter, ConsoleMetricOptions, ConsoleSpanExporter, ConsoleSpanOptions};
use Flow\Telemetry\Provider\Memory\{MemoryLogExporter, MemoryLogProcessor, MemoryMetricExporter, MemoryMetricProcessor, MemorySpanExporter, MemorySpanProcessor};
use Flow\Telemetry\Provider\Void\{VoidLogExporter, VoidLogProcessor, VoidMetricExporter, VoidMetricProcessor, VoidSpanExporter, VoidSpanProcessor};
use Flow\Telemetry\Resource\Detector\{CachingDetector, ChainDetector, ComposerDetector, EnvironmentDetector, HostDetector, ManualDetector, OsDetector, ProcessDetector};
use Flow\Telemetry\Resource\ResourceDetector;
use Flow\Telemetry\Tracer\{GenericEvent, SpanContext, SpanExporter, SpanLimits, SpanLink, SpanProcessor, TracerProvider};
use Flow\Telemetry\Tracer\Processor\{BatchingSpanProcessor, PassThroughSpanProcessor};
use Flow\Telemetry\Tracer\Sampler\{AlwaysOnSampler, Sampler};
use Psr\Clock\ClockInterface;
/**
* Create a TraceId.
*
* If a hex string is provided, creates a TraceId from it.
* Otherwise, generates a new random TraceId.
*
* @param null|string $hex Optional 32-character hexadecimal string
*
* @throws \InvalidArgumentException if the hex string is invalid
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function trace_id(?string $hex = null) : TraceId
{
if ($hex !== null) {
return TraceId::fromHex($hex);
}
return TraceId::generate();
}
/**
* Create a SpanId.
*
* If a hex string is provided, creates a SpanId from it.
* Otherwise, generates a new random SpanId.
*
* @param null|string $hex Optional 16-character hexadecimal string
*
* @throws \InvalidArgumentException if the hex string is invalid
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function span_id(?string $hex = null) : SpanId
{
if ($hex !== null) {
return SpanId::fromHex($hex);
}
return SpanId::generate();
}
/**
* Create a Baggage.
*
* @param array<string, string> $entries Initial key-value entries
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function baggage(array $entries = []) : Baggage
{
return new Baggage($entries);
}
/**
* Create a Context.
*
* If no TraceId is provided, generates a new one.
* If no Baggage is provided, creates an empty one.
*
* @param null|TraceId $traceId Optional TraceId to use
* @param null|Baggage $baggage Optional Baggage to use
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function context(?TraceId $traceId = null, ?Baggage $baggage = null) : Context
{
$traceId ??= TraceId::generate();
$baggage ??= new Baggage();
return new Context($traceId, $baggage);
}
/**
* Create a 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.
*
* @param null|Context $context Optional initial context
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function memory_context_storage(?Context $context = null) : MemoryContextStorage
{
return new MemoryContextStorage($context);
}
/**
* Create a Resource.
*
* @param array<string, array<bool|float|int|string>|bool|float|int|string>|Attributes $attributes Resource attributes
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function resource(array|Attributes $attributes = []) : Resource
{
return Resource::create($attributes);
}
/**
* Create a SpanContext.
*
* @param TraceId $traceId The trace ID
* @param SpanId $spanId The span ID
* @param null|SpanId $parentSpanId Optional parent span ID
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function span_context(TraceId $traceId, SpanId $spanId, ?SpanId $parentSpanId = null) : SpanContext
{
return SpanContext::create($traceId, $spanId, $parentSpanId);
}
/**
* Create a SpanEvent (GenericEvent) with an explicit timestamp.
*
* @param string $name Event name
* @param \DateTimeImmutable $timestamp Event timestamp
* @param array<string, array<bool|float|int|string>|bool|float|int|string>|Attributes $attributes Event attributes
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function span_event(string $name, \DateTimeImmutable $timestamp, array|Attributes $attributes = []) : GenericEvent
{
return GenericEvent::create($name, $timestamp, $attributes);
}
/**
* Create a SpanLink.
*
* @param SpanContext $context The linked span context
* @param array<string, array<bool|float|int|string>|bool|float|int|string>|Attributes $attributes Link attributes
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function span_link(SpanContext $context, array|Attributes $attributes = []) : SpanLink
{
return SpanLink::create($context, $attributes);
}
/**
* Create SpanLimits configuration.
*
* SpanLimits controls the maximum amount of data a span can collect,
* preventing unbounded memory growth and ensuring reasonable span sizes.
*
* @param int $attributeCountLimit Maximum number of attributes per span
* @param int $eventCountLimit Maximum number of events per span
* @param int $linkCountLimit Maximum number of links per span
* @param int $attributePerEventCountLimit Maximum number of attributes per event
* @param int $attributePerLinkCountLimit Maximum number of attributes per link
* @param null|int $attributeValueLengthLimit Maximum length for string attribute values (null = unlimited)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function span_limits(
int $attributeCountLimit = 128,
int $eventCountLimit = 128,
int $linkCountLimit = 128,
int $attributePerEventCountLimit = 128,
int $attributePerLinkCountLimit = 128,
?int $attributeValueLengthLimit = null,
) : SpanLimits {
return new SpanLimits(
$attributeCountLimit,
$eventCountLimit,
$linkCountLimit,
$attributePerEventCountLimit,
$attributePerLinkCountLimit,
$attributeValueLengthLimit,
);
}
/**
* Create LogRecordLimits configuration.
*
* LogRecordLimits controls the maximum amount of data a log record can collect,
* preventing unbounded memory growth and ensuring reasonable log record sizes.
*
* @param int $attributeCountLimit Maximum number of attributes per log record
* @param null|int $attributeValueLengthLimit Maximum length for string attribute values (null = unlimited)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function log_record_limits(
int $attributeCountLimit = 128,
?int $attributeValueLengthLimit = null,
) : LogRecordLimits {
return new LogRecordLimits(
$attributeCountLimit,
$attributeValueLengthLimit,
);
}
/**
* Create MetricLimits configuration.
*
* 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.
*
* @param int $cardinalityLimit Maximum number of unique attribute combinations per instrument
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function metric_limits(
int $cardinalityLimit = 2000,
) : MetricLimits {
return new MetricLimits(
$cardinalityLimit,
);
}
/**
* Create a VoidSpanProcessor.
*
* No-op span processor that discards all data.
* Use this when tracing is disabled to minimize overhead.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function void_span_processor() : VoidSpanProcessor
{
return new VoidSpanProcessor();
}
/**
* Create a VoidMetricProcessor.
*
* No-op metric processor that discards all data.
* Use this when metrics collection is disabled to minimize overhead.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function void_metric_processor() : VoidMetricProcessor
{
return new VoidMetricProcessor();
}
/**
* Create a VoidLogProcessor.
*
* No-op log processor that discards all data.
* Use this when logging is disabled to minimize overhead.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function void_log_processor() : VoidLogProcessor
{
return new VoidLogProcessor();
}
/**
* Create a VoidSpanExporter.
*
* No-op span exporter that discards all data.
* Use this when telemetry export is disabled to minimize overhead.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function void_span_exporter() : VoidSpanExporter
{
return new VoidSpanExporter();
}
/**
* Create a VoidMetricExporter.
*
* No-op metric exporter that discards all data.
* Use this when telemetry export is disabled to minimize overhead.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function void_metric_exporter() : VoidMetricExporter
{
return new VoidMetricExporter();
}
/**
* Create a VoidLogExporter.
*
* No-op log exporter that discards all data.
* Use this when telemetry export is disabled to minimize overhead.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function void_log_exporter() : VoidLogExporter
{
return new VoidLogExporter();
}
/**
* Create a MemorySpanExporter.
*
* Span exporter that stores data in memory.
* Provides direct getter access to exported spans.
* Useful for testing and inspection without serialization.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function memory_span_exporter() : MemorySpanExporter
{
return new MemorySpanExporter();
}
/**
* Create a MemoryMetricExporter.
*
* Metric exporter that stores data in memory.
* Provides direct getter access to exported metrics.
* Useful for testing and inspection without serialization.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function memory_metric_exporter() : MemoryMetricExporter
{
return new MemoryMetricExporter();
}
/**
* Create a MemoryLogExporter.
*
* Log exporter that stores data in memory.
* Provides direct getter access to exported log entries.
* Useful for testing and inspection without serialization.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function memory_log_exporter() : MemoryLogExporter
{
return new MemoryLogExporter();
}
/**
* Create a MemorySpanProcessor.
*
* Span processor that stores spans in memory and exports via configured exporter.
* Useful for testing.
*
* @param SpanExporter $exporter The exporter to send spans to
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function memory_span_processor(SpanExporter $exporter) : MemorySpanProcessor
{
return new MemorySpanProcessor($exporter);
}
/**
* Create a MemoryMetricProcessor.
*
* Metric processor that stores metrics in memory and exports via configured exporter.
* Useful for testing.
*
* @param MetricExporter $exporter The exporter to send metrics to
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function memory_metric_processor(MetricExporter $exporter) : MemoryMetricProcessor
{
return new MemoryMetricProcessor($exporter);
}
/**
* Create a MemoryLogProcessor.
*
* Log processor that stores log records in memory and exports via configured exporter.
* Useful for testing.
*
* @param LogExporter $exporter The exporter to send logs to
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function memory_log_processor(LogExporter $exporter) : MemoryLogProcessor
{
return new MemoryLogProcessor($exporter);
}
/**
* Create a 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.
*
* @param SpanProcessor $processor The processor for spans
* @param ClockInterface $clock The clock for timestamps
* @param ContextStorage $contextStorage Storage for context propagation
* @param Sampler $sampler Sampling strategy for spans
* @param SpanLimits $limits Limits for span attributes, events, and links
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function tracer_provider(
SpanProcessor $processor,
ClockInterface $clock,
ContextStorage $contextStorage,
Sampler $sampler = new AlwaysOnSampler(),
SpanLimits $limits = new SpanLimits(),
) : TracerProvider {
return new TracerProvider(
$processor,
$clock,
$contextStorage,
$sampler,
$limits,
);
}
/**
* Create a 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.
*
* @param LogProcessor $processor The processor for logs
* @param ClockInterface $clock The clock for timestamps
* @param ContextStorage $contextStorage Storage for span correlation
* @param LogRecordLimits $limits Limits for log record attributes
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function logger_provider(
LogProcessor $processor,
ClockInterface $clock,
ContextStorage $contextStorage,
LogRecordLimits $limits = new LogRecordLimits(),
) : LoggerProvider {
return new LoggerProvider(
$processor,
$clock,
$contextStorage,
$limits,
);
}
/**
* Create a 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.
*
* @param MetricProcessor $processor The processor for metrics
* @param ClockInterface $clock The clock for timestamps
* @param AggregationTemporality $temporality Aggregation temporality for metrics
* @param ExemplarFilter $exemplarFilter Filter for exemplar sampling (default: TraceBasedExemplarFilter)
* @param MetricLimits $limits Cardinality limits for metric instruments
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function meter_provider(
MetricProcessor $processor,
ClockInterface $clock,
AggregationTemporality $temporality = AggregationTemporality::CUMULATIVE,
ExemplarFilter $exemplarFilter = new TraceBasedExemplarFilter(),
MetricLimits $limits = new MetricLimits(),
) : MeterProvider {
return new MeterProvider(
$processor,
$clock,
$temporality,
$exemplarFilter,
$limits,
);
}
/**
* Create a new Telemetry instance with the given providers.
*
* If providers are not specified, void providers (no-op) are used.
*
* @param resource $resource The resource describing the entity producing telemetry
* @param null|TracerProvider $tracerProvider The tracer provider (null for void/disabled)
* @param null|MeterProvider $meterProvider The meter provider (null for void/disabled)
* @param null|LoggerProvider $loggerProvider The logger provider (null for void/disabled)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function telemetry(
Resource $resource,
?TracerProvider $tracerProvider = null,
?MeterProvider $meterProvider = null,
?LoggerProvider $loggerProvider = null,
) : Telemetry {
$clock = new SystemClock();
$contextStorage = new MemoryContextStorage();
return new Telemetry(
$resource,
$tracerProvider ?? new TracerProvider(new VoidSpanProcessor(), $clock, $contextStorage),
$meterProvider ?? new MeterProvider(new VoidMetricProcessor(), $clock),
$loggerProvider ?? new LoggerProvider(new VoidLogProcessor(), $clock, $contextStorage),
);
}
/**
* Create an InstrumentationScope.
*
* @param string $name The instrumentation scope name
* @param string $version The instrumentation scope version
* @param null|string $schemaUrl Optional schema URL
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function instrumentation_scope(
string $name,
string $version = 'unknown',
?string $schemaUrl = null,
Attributes $attributes = new Attributes(),
) : InstrumentationScope {
return new InstrumentationScope($name, $version, $schemaUrl, $attributes);
}
/**
* Create a 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().
*
* @param SpanExporter $exporter The exporter to send spans to
* @param int $batchSize Number of spans to collect before exporting (default 512)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function batching_span_processor(SpanExporter $exporter, int $batchSize = 512) : BatchingSpanProcessor
{
return new BatchingSpanProcessor($exporter, $batchSize);
}
/**
* Create a PassThroughSpanProcessor.
*
* Exports each span immediately when it ends.
* Useful for debugging where immediate visibility is more important than performance.
*
* @param SpanExporter $exporter The exporter to send spans to
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function pass_through_span_processor(SpanExporter $exporter) : PassThroughSpanProcessor
{
return new PassThroughSpanProcessor($exporter);
}
/**
* Create a 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().
*
* @param MetricExporter $exporter The exporter to send metrics to
* @param int $batchSize Number of metrics to collect before exporting (default 512)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function batching_metric_processor(MetricExporter $exporter, int $batchSize = 512) : BatchingMetricProcessor
{
return new BatchingMetricProcessor($exporter, $batchSize);
}
/**
* Create a PassThroughMetricProcessor.
*
* Exports each metric immediately when processed.
* Useful for debugging where immediate visibility is more important than performance.
*
* @param MetricExporter $exporter The exporter to send metrics to
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function pass_through_metric_processor(MetricExporter $exporter) : PassThroughMetricProcessor
{
return new PassThroughMetricProcessor($exporter);
}
/**
* Create a 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().
*
* @param LogExporter $exporter The exporter to send logs to
* @param int $batchSize Number of logs to collect before exporting (default 512)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function batching_log_processor(LogExporter $exporter, int $batchSize = 512) : BatchingLogProcessor
{
return new BatchingLogProcessor($exporter, $batchSize);
}
/**
* Create a PassThroughLogProcessor.
*
* Exports each log record immediately when processed.
* Useful for debugging where immediate visibility is more important than performance.
*
* @param LogExporter $exporter The exporter to send logs to
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function pass_through_log_processor(LogExporter $exporter) : PassThroughLogProcessor
{
return new PassThroughLogProcessor($exporter);
}
/**
* Create a SeverityFilteringLogProcessor.
*
* Filters log entries based on minimum severity level. Only entries at or above
* the configured threshold are passed to the wrapped processor.
*
* @param LogProcessor $processor The processor to wrap
* @param Severity $minimumSeverity Minimum severity level (default: INFO)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function severity_filtering_log_processor(
LogProcessor $processor,
Severity $minimumSeverity = Severity::INFO,
) : SeverityFilteringLogProcessor {
return new SeverityFilteringLogProcessor($processor, $minimumSeverity);
}
/**
* Create a ConsoleSpanExporter.
*
* Outputs spans to the console with ASCII table formatting.
* Useful for debugging and development.
*
* @param bool $colors Whether to use ANSI colors (default: true)
* @param ConsoleSpanOptions $options Display options for the exporter
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_span_exporter(bool $colors = true, ConsoleSpanOptions $options = new ConsoleSpanOptions()) : ConsoleSpanExporter
{
return new ConsoleSpanExporter($colors, null, $options);
}
/**
* Create a ConsoleMetricExporter.
*
* Outputs metrics to the console with ASCII table formatting.
* Useful for debugging and development.
*
* @param bool $colors Whether to use ANSI colors (default: true)
* @param ConsoleMetricOptions $options Display options for the exporter
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_metric_exporter(bool $colors = true, ConsoleMetricOptions $options = new ConsoleMetricOptions()) : ConsoleMetricExporter
{
return new ConsoleMetricExporter($colors, null, $options);
}
/**
* Create a ConsoleLogExporter.
*
* Outputs log records to the console with severity-based coloring.
* Useful for debugging and development.
*
* @param bool $colors Whether to use ANSI colors (default: true)
* @param null|int $maxBodyLength Maximum length for body+attributes column (null = no limit, default: 100)
* @param ConsoleLogOptions $options Display options for the exporter
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_log_exporter(bool $colors = true, ?int $maxBodyLength = 100, ConsoleLogOptions $options = new ConsoleLogOptions()) : ConsoleLogExporter
{
return new ConsoleLogExporter($colors, $maxBodyLength, null, $options);
}
/**
* Create ConsoleSpanOptions with all display options enabled (default behavior).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_span_options() : ConsoleSpanOptions
{
return ConsoleSpanOptions::default();
}
/**
* Create ConsoleSpanOptions with minimal display (legacy compact format).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_span_options_minimal() : ConsoleSpanOptions
{
return ConsoleSpanOptions::minimal();
}
/**
* Create ConsoleLogOptions with all display options enabled (default behavior).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_log_options() : ConsoleLogOptions
{
return ConsoleLogOptions::default();
}
/**
* Create ConsoleLogOptions with minimal display (legacy compact format).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_log_options_minimal() : ConsoleLogOptions
{
return ConsoleLogOptions::minimal();
}
/**
* Create ConsoleMetricOptions with all display options enabled (default behavior).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_metric_options() : ConsoleMetricOptions
{
return ConsoleMetricOptions::default();
}
/**
* Create ConsoleMetricOptions with minimal display (legacy compact format).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function console_metric_options_minimal() : ConsoleMetricOptions
{
return ConsoleMetricOptions::minimal();
}
/**
* Create an AlwaysOnExemplarFilter.
*
* Records exemplars whenever a span context is present.
* Use this filter for debugging or when complete trace context is important.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function always_on_exemplar_filter() : AlwaysOnExemplarFilter
{
return new AlwaysOnExemplarFilter();
}
/**
* Create an AlwaysOffExemplarFilter.
*
* Never records exemplars. Use this filter to disable exemplar collection
* entirely for performance optimization.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function always_off_exemplar_filter() : AlwaysOffExemplarFilter
{
return new AlwaysOffExemplarFilter();
}
/**
* Create a TraceBasedExemplarFilter.
*
* Records exemplars only when the span is sampled (has SAMPLED trace flag).
* This is the default filter, balancing exemplar collection with performance.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function trace_based_exemplar_filter() : TraceBasedExemplarFilter
{
return new TraceBasedExemplarFilter();
}
/**
* Create a PropagationContext.
*
* Value object containing both trace context (SpanContext) and application
* data (Baggage) that can be propagated across process boundaries.
*
* @param null|SpanContext $spanContext Optional span context
* @param null|Baggage $baggage Optional baggage
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::TYPE)]
function propagation_context(?SpanContext $spanContext = null, ?Baggage $baggage = null) : PropagationContext
{
return new PropagationContext($spanContext, $baggage);
}
/**
* Create an ArrayCarrier.
*
* Carrier backed by an associative array with case-insensitive key lookup.
*
* @param array<string, string> $data Initial carrier data
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function array_carrier(array $data = []) : ArrayCarrier
{
return new ArrayCarrier($data);
}
/**
* Create a SuperglobalCarrier.
*
* Read-only carrier that extracts context from PHP superglobals
* ($_SERVER, $_GET, $_POST, $_COOKIE).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function superglobal_carrier() : SuperglobalCarrier
{
return new SuperglobalCarrier();
}
/**
* Create a W3CTraceContext propagator.
*
* Implements W3C Trace Context specification for propagating trace context
* using traceparent and tracestate headers.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function w3c_trace_context() : W3CTraceContext
{
return new W3CTraceContext();
}
/**
* Create a W3CBaggage propagator.
*
* Implements W3C Baggage specification for propagating application-specific
* key-value pairs using the baggage header.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function w3c_baggage() : W3CBaggage
{
return new W3CBaggage();
}
/**
* Create a CompositePropagator.
*
* Combines multiple propagators into one. On extract, all propagators are
* invoked and their contexts are merged. On inject, all propagators are invoked.
*
* @param Propagator ...$propagators The propagators to combine
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function composite_propagator(Propagator ...$propagators) : CompositePropagator
{
return new CompositePropagator($propagators);
}
/**
* Create a 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.
*
* @param ResourceDetector ...$detectors The detectors to chain
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function chain_detector(ResourceDetector ...$detectors) : ChainDetector
{
return new ChainDetector(...$detectors);
}
/**
* Create an OsDetector.
*
* Detects operating system information including os.type, os.name, os.version,
* and os.description using PHP's php_uname() function.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function os_detector() : OsDetector
{
return new OsDetector();
}
/**
* Create a HostDetector.
*
* Detects host information including host.name, host.arch, and host.id
* (from /etc/machine-id on Linux or IOPlatformUUID on macOS).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function host_detector() : HostDetector
{
return new HostDetector();
}
/**
* Create a 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).
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function process_detector() : ProcessDetector
{
return new ProcessDetector();
}
/**
* Create an 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
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function environment_detector() : EnvironmentDetector
{
return new EnvironmentDetector();
}
/**
* Create a ComposerDetector.
*
* Detects service.name and service.version from Composer's InstalledVersions
* using the root package information.
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function composer_detector() : ComposerDetector
{
return new ComposerDetector();
}
/**
* Create a ManualDetector.
*
* Returns manually specified resource attributes. Use this when you need
* to set attributes explicitly rather than detecting them automatically.
*
* @param array<string, array<bool|float|int|string>|bool|float|int|string> $attributes Resource attributes
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function manual_detector(array $attributes) : ManualDetector
{
return new ManualDetector($attributes);
}
/**
* Create a CachingDetector.
*
* Wraps another detector and caches its results to a file. On subsequent
* calls, returns the cached resource instead of running detection again.
*
* @param ResourceDetector $detector The detector to wrap
* @param null|string $cachePath Cache file path (default: sys_get_temp_dir()/flow_telemetry_resource.cache)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function caching_detector(ResourceDetector $detector, ?string $cachePath = null) : CachingDetector
{
return new CachingDetector($detector, $cachePath);
}
/**
* Create a resource detector chain.
*
* 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.
*
* @param array<ResourceDetector> $detectors Optional custom detectors (empty = use defaults)
*/
#[DocumentationDSL(module: Module::TELEMETRY, type: DSLType::HELPER)]
function resource_detector(array $detectors = []) : ChainDetector
{
if (\count($detectors) === 0) {
return new ChainDetector(
new OsDetector(),
new HostDetector(),
new ProcessDetector(),
new ComposerDetector(),
new EnvironmentDetector(),
);
}
return new ChainDetector(...$detectors);
}