-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathddtrace.stub.php
More file actions
1255 lines (1098 loc) · 47.5 KB
/
ddtrace.stub.php
File metadata and controls
1255 lines (1098 loc) · 47.5 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
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/** @generate-class-entries */
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
namespace DDTrace {
/**
* @var int
* @cvalue DD_TRACE_DBM_PROPAGATION_DISABLED
*/
const DBM_PROPAGATION_DISABLED = UNKNOWN;
/**
* @var int
* @cvalue DD_TRACE_DBM_PROPAGATION_SERVICE
*/
const DBM_PROPAGATION_SERVICE = UNKNOWN;
/**
* @var int
* @cvalue DD_TRACE_DBM_PROPAGATION_FULL
*/
const DBM_PROPAGATION_FULL = UNKNOWN;
class SpanEvent implements \JsonSerializable {
/**
* SpanEvent constructor.
*
* @param string $name The event name.
* @param int|null $timestamp The event start time in nanoseconds, if not provided set the current Unix timestamp.
* @param array $attributes Optional attributes for the event.
*/
public function __construct(string $name, array $attributes = [], ?int $timestamp = null) {}
/**
* @var string The event name
*/
public string $name;
/**
* @var string[] $attributes
*/
public array $attributes;
/**
* @var int The event start time in nanoseconds, if not provided set the current Unix timestamp
*/
public int $timestamp;
/**
* @return mixed
*/
public function jsonSerialize(): mixed {}
}
class ExceptionSpanEvent extends SpanEvent {
/**
* ExceptionSpanEvent constructor.
*
* @param \Throwable $exception exception to record.
* @param array $attributes Optional attributes for the event.
*/
public function __construct(\Throwable $exception, array $attributes = []) {}
/**
* @var \Throwable
*/
public \Throwable $exception;
}
class SpanLink implements \JsonSerializable {
/**
* @var string $traceId A 32-character, lower-case hexadecimal encoded string of the linked trace ID. This field
* shouldn't be directly assigned an id from SpanData. Use the SpanData::getLink() method instead.
*/
public string $traceId;
/**
* @var string $spanId A 16-character, lower-case hexadecimal encoded string of the linked span ID. This field
* shouldn't be directly assigned an id from SpanData. Use the SpanData::getLink() method instead.
*/
public string $spanId;
/**
* @var string $traceState
*/
public string $traceState;
/**
* @var string[] $attributes
*/
public array $attributes;
/**
* @var int $droppedAttributesCount
*/
public int $droppedAttributesCount;
/**
* @return mixed
*/
public function jsonSerialize(): mixed {}
/**
* Consumes distributed tracing headers, from which a span link will be constructed.
*
* @param array|callable(string):mixed $headersOrCallback Either an array with a lowercase header to value mapping,
* or a callback, which given a header name for distributed tracing, returns the value it should be updated to.
*/
public static function fromHeaders(array|callable $headersOrCallback): SpanLink {}
}
class GitMetadata {
/**
* @var string The commit sha of the git repository
*/
public string $commitSha = "";
/**
* @var string The repository URL of the git repository
*/
public string $repositoryUrl = "";
}
class SpanData {
/**
* @var string|null The span name
*/
public string|null $name = "";
/**
* @var string|null The resource you are tracing
*/
public string|null $resource = "";
/**
* @var string|null The service you are tracing. Defaults to active service at the time of span creation (i.e.,
* the parent span), or datadog.service initialization settings if no parent exists
*/
public string|null $service = "";
/**
* @var string The environment you are tracing. Defaults to active environment at the time of span creation
* (i.e., the parent span), or datadog.env initialization settings if no parent exists
*/
public string $env = "";
/**
* @var string The version of the application you are tracing. Defaults to active version at the time of
* span creation (i.e., the parent span), or datadog.version initialization settings if no parent exists
*/
public string $version = "";
/**
* @var string[] Meta struct can be used to send any data to the backend. The peculiarity of meta struct is
* that the values are encoded with msgpack when sent to the agent. The values are first encoded to msgpack
* and then, encoded again with msgpack to binary
*/
public array $meta_struct = [];
/**
* @var string|null The type of request which can be set to: web, db, cache, or custom (Optional). Inherited
* from parent.
*/
public string|null $type = "";
/**
* @var string[] $meta An array of key-value span metadata; keys and values must be strings.
*/
public array $meta = [];
/**
* @var float[] $metrics An array of key-value span metrics; keys must be strings and values must be floats.
*/
public array $metrics = [];
/**
* @var \Throwable|null $exception An exception generated during the execution of the original function, if any.
*/
public \Throwable|null $exception = null;
/**
* @var string The unique identifier of the span
*/
public readonly string $id;
/**
* @var SpanLink[] $spanLinks An array of span links
*/
public array $links = [];
/**
* @var SpanEvent[] $spanEvents An array of span events
*/
public array $events = [];
/**
* @var string[] $peerServiceSources A sorted list of tag names used to set the `peer.service` tag. If a tag
* name is added to this field and the tag exists on the span at serialization time, then the value of the tag
* will be used to set the value of the `peer.service` tag.
*/
public array $peerServiceSources = [];
/**
* @var SpanData|null The parent span, or 'null' if there is none
*/
public readonly SpanData|null $parent;
/**
* @var SpanStack The span's stack trace
*/
public readonly SpanStack $stack;
/**
* @var \Closure(self $span)[] $handler Defines handlers which will be invoked in reverse order when this span
* is closed.
* These handlers will not be called when the span is dropped.
* This array is cleared upon span drop or close.
* The passed $span parameter is this instance.
*/
public array $onClose = [];
/**
* @return int Get the current span duration, in nanoseconds
*/
public function getDuration(): int {}
/**
* @return int Get the start time of the span, in nanoseconds
*/
public function getStartTime(): int {}
/**
* @return SpanLink Get a pre-populated SpanLink object with the current span's trace and span IDs
*/
public function getLink(): SpanLink {}
/**
* @return string Returns the span id as zero-padded 16 character hexadecimal string.
*/
public function hexId(): string {}
/**
* @var array In OpenTelemetry, Baggage is contextual information that resides next to context.
* Baggage is a key-value store, which means it lets you propagate any data you like alongside context regardless of trace ids existence.
*/
public array $baggage = [];
}
class InferredSpanData extends SpanData {}
class RootSpanData extends SpanData {
/**
* @var string The origin site of the trace. Propagated through distributed tracing by default.
*/
public string $origin;
/**
* @var array A hashset of keys which are propagated from meta, if present.
*/
public array $propagatedTags = [];
/**
* @var int The currently active sampling priority.
*/
public int $samplingPriority = \DD_TRACE_PRIORITY_SAMPLING_UNKNOWN;
/**
* @var int The unmodified sampling priority as inherited directly through distributed tracing.
*/
public int $propagatedSamplingPriority;
/**
* @var string The original tracestate minus datadog specific tags, as it will be propagated to upstream
* distributed tracing targets.
*/
public string $tracestate;
/**
* @var array A list of datadog specific tags, which will be propagated to upstream distributed tracing
* targets as part of the tracestate. Some known keys are not included here, but directly extracted, e.g. origin.
*/
public array $tracestateTags = [];
/**
* @var string The unique identifier of the parent span as a decimal number.
* Assignment of an invalid id will unset the parent id.
* This variable cannot be accessed by reference.
*/
public string $parentId;
/**
* @var string The unique identifier for the trace id, as a zero-padded 32 character hexadecimal string.
* Assignment of an invalid id will reset the trace id to the default trace id.
* This variable cannot be accessed by reference.
*/
public string $traceId = "";
/**
* @var GitMetadata|null The git metadata of the span
*/
public GitMetadata|null $gitMetadata = null;
public InferredSpanData|null $inferredSpan = null;
}
/**
* The SpanStack class allows context transfer between spans.
*
* When a new span is created, it will always be on the top the of active stack, becoming the new active span. This
* new span's stack property is assigned the stack of the previous active span (or a primary stack is initialized in
* the case of a root span). The parent of a SpanStack is the active stack at the time of the creation of the new
* stack.
*
* Each SpanStack has only one active span at a time, and can be manipulated using the 'create_stack' and
* 'switch_stack' functions. 'create_stack' creates a new SpanStack whose parent is the currently active stack,
* while 'switch_stack' switches the active span.
*/
class SpanStack {
/**
* @var SpanStack|null The parent stack, or 'null' if there is none
*/
public readonly SpanStack|null $parent;
/**
* @var SpanData|null The active span
*/
public SpanData|null $active = null;
/**
* @var \Closure(SpanData $span):(false|null)[] The observers to be called when a span on top of this span stack is started.
* This property is inherited when child span stacks are created.
* The handler can remove itself (globally) from further invocation by returning false.
* Maintained as an array of references (promoted to reference on nested create_stack) to ensure propagation of
* removal.
*/
public array $spanCreationObservers = [];
}
interface Integration {
// Possible statuses for the concrete:
/**
* It has not been loaded yet
*
* @cvalue DD_TRACE_INTEGRATION_NOT_LOADED
* @var int
*/
const NOT_LOADED = UNKNOWN;
/**
* It has been loaded, no more work required
*
* @cvalue DD_TRACE_INTEGRATION_LOADED
* @var int
*/
const LOADED = UNKNOWN;
/**
* Prerequisites are not matched and won't be matched in the future.
*
* @cvalue DD_TRACE_INTEGRATION_NOT_AVAILABLE
* @var int
*/
const NOT_AVAILABLE = UNKNOWN;
/** Load the integration */
public static function init(): int;
}
// phpcs:disable Generic.Files.LineLength.TooLong
/**
* Instrument (trace) a specific method call. This function automatically handle the following tasks:
* - Open a span before the code executes
* - Set any errors from the instrumented call on the span
* - Close the span when the instrumented call is done.
*
* Additional tags are set on the span from the closure (called a tracing closure).
*
* @param string $className The name of the class that contains the method.
* @param string $methodName The name of the method to instrument.
* @param null|\Closure(SpanData $span, array $args, mixed $retval, \Throwable|null $exception):void|array{prehook?: \Closure, posthook?: \Closure, instrument_when_limited?: int, recurse?: bool} $tracingClosureOrConfigArray
* The tracing closure is a function that adds extra tags to the span after the
* instrumented call is executed. It accepts four parameters, namely, an instance of 'DDTrace\SpanData', an array of
* arguments from the instrumented call, the return value of the instrumented call, and an instance of the exception
* that was thrown in the instrumented call (if any), or 'null' if no exception was thrown.
*
* Alternatively, an associative configuration array can be given whose recognized keys are:
* - 'prehook': a closure to be run prior to the method call
* - 'posthook': a closure to be run after the method was executed
* - 'instrument_when_limited': set to 1 shall the method be traced in limited mode (e.g., when span limit
* exceeded)
* - 'recurse': a boolean to state whether should recursive calls be traced as well
*
* Note that this closure will be bound to the object (or scope if static) of the target method.
* @return bool 'true' if the call was successfully instrumented, else 'false'
*/
function trace_method(
string $className,
string $methodName,
null|\Closure|array $tracingClosureOrConfigArray
): bool {}
/**
* Instrument (trace) a specific function call. This function automatically handle the following tasks:
* - Open a span before the code executes
* - Set any errors from the instrumented call on the span
* - Close the span when the instrumented call is done.
*
* Additional tags are set on the span from the closure (called a tracing closure).
*
* @param string $functionName The name of the function to trace.
* @param null|\Closure(SpanData $span, array $args, mixed $retval, \Throwable|null $exception):void|array{prehook?: \Closure, posthook?: \Closure, instrument_when_limited?: int, recurse?: bool} $tracingClosureOrConfigArray
* The tracing closure is a function that adds extra tags to the span after the
* instrumented call is executed. It accepts four parameters, namely, an instance of 'DDTrace\SpanData' that writes
* to the span properties, an array of arguments from the instrumented call, the return value of the instrumented
* call, and an instance of the exception that was thrown in the instrumented call (if any), or 'null' if no
* exception was thrown.
*
* Alternatively, an associative configuration array can be given whose recognized keys are:
* - 'prehook': a closure to be run prior to the function call
* - 'posthook': a closure to be run after the function was executed
* - 'instrument_when_limited': set to 1 shall the function be traced in limited mode (e.g., when span limit
* exceeded)
* - 'recurse': a boolean to state whether should recursive calls be traced as well
* @return bool 'true' if the call was successfully instrumented, else 'false'
*/
function trace_function(string $functionName, \Closure|array|null $tracingClosureOrConfigArray): bool {}
/**
* This function allows to define pre- and post-hooks that will be executed before and after the function is called.
*
* @param string $functionName The name of the function to be instrumented.
* @param \Closure(array $args, mixed $retval, \Throwable|null $exception):void|null|array{prehook?: \Closure, posthook?: \Closure, instrument_when_limited?: int, recurse?: bool} $prehookOrConfigArray
* A pre-hook function that will be called before the instrumented function is
* executed. This can be useful for things like asserting the function is passed the correct arguments.
*
* Alternatively, an associative configuration array can be given whose recognized keys are:
* - 'prehook': a closure to be run prior to the function call
* - 'posthook': a closure to be run after the function was executed
* - 'instrument_when_limited': set to 1 shall the function be traced in limited mode (e.g., when span limit
* exceeded)
* - 'recurse': a boolean to state whether should recursive calls be traced as well
* @param \Closure(array $args, mixed $retval, \Throwable|null $exception):void|null $posthook A post-hook function that will be called after
* the instrumented function is executed. This can be useful for things like formatting output data or logging the
* results of the function call.
*
* Note that the $posthook argument shouldn't be given when calling hook_function if a configuration array has been
* passed.
* @return bool 'false' if the hook could not be successfully installed, else 'true'
*/
function hook_function(
string $functionName,
\Closure|array|null $prehookOrConfigArray = null,
?\Closure $posthook = null
): bool {}
/**
* This function allows to define pre- and post-hooks that will be executed before and after the method is called.
*
* @param string $className The name of the class that contains the method.
* @param string $methodName The name of the method to instrument.
* @param \Closure(object $object, string $scope, array $args):void|null|array{prehook?: \Closure, posthook?: \Closure, instrument_when_limited?: int, recurse?: bool} $prehookOrConfigArray
* A pre-hook function that will be called before the instrumented
* method is executed. This can be useful for things like asserting the method is passed the correct arguments.
*
* Alternatively, an associative configuration array can be given whose recognized keys are:
* - 'prehook': a closure to be run prior to the function call
* - 'posthook': a closure to be run after the function was executed
* - 'instrument_when_limited': set to 1 shall the function be traced in limited mode (e.g., when span limit
* exceeded)
* - 'recurse': a boolean to state whether should recursive calls be traced as well
* @param \Closure(object $object, string $scope, array $args, mixed $retval, \Throwable|null $exception):void|null $posthook A post-hook function that will be called after
* the instrumented method is executed. This can be useful for things like formatting output data or logging the
* results of the method call.
*
* Note that the $posthook argument shouldn't be given when calling hook_function if a configuration array has been
* passed.
* @return bool 'false' when no hook is passed, else 'true'
*/
function hook_method(
string $className,
string $methodName,
\Closure|array|null $prehookOrConfigArray = null,
?\Closure $posthook = null
): bool {}
// phpcs:enable Generic.Files.LineLength.TooLong
/**
* Add a tag to be automatically applied to every span that is created, if tracing is enabled.
*
* @param string $key Tag key
* @param string $value Tag Value
*/
function add_global_tag(string $key, string $value): void {}
/**
* Add a tag to be propagated along distributed traces' information. It also adds the tag to the local root span.
*
* @param string $key Tag key
* @param string $value Tag value
*/
function add_distributed_tag(string $key, string $value): void {}
/**
* Add user information to monitor authenticated requests in the application.
*
* @param string $userId Unique identifier of the user (usr.id)
* @param array $metadata User monitoring tags (usr.<TAG_NAME>) applied to the 'meta' section of the root span
* @param bool|null $propagate If set to 'true', user's information will be propagated in distributed traces
*/
function set_user(string $userId, array $metadata = [], bool|null $propagate = null): void {}
/**
* Close child spans of a parent span if a non-internal span is given,
* else if 'null' is given, close active, non-internal spans
*
* @param SpanData|null $span The parent span
* @return false|int 'false' if spans couldn't be closed, else the number of span closed
*/
function close_spans_until(?SpanData $span): false|int {}
/**
* Get the active span
*
* @return SpanData|null 'null' if tracing isn't enabled or there isn't any active span, else the active span
*/
function active_span(): null|SpanData {}
/**
* Get the root span
*
* @return SpanData|null 'null' if tracing isn't enabled or if the active stack doesn't have a root span,
* else the root span of the active stack
*/
function root_span(): null|RootSpanData {}
/**
* Start a new custom user-span on the top of the stack. If no active span exists, the new created span will be a
* root span, on its own new span stack (i.e., it is equivalent to 'start_trace_span'). In that case, distributed
* tracing information will be applied if available.
*
* @param float $startTime Start time of the span in seconds.
* @return SpanData|false The newly started span, or 'false' if a wrong parameter was given.
*/
function start_span(float $startTime = 0): SpanData|false {}
/**
* Close the currently active user-span on the top of the stack
*
* @param float $finishTime Finish time in seconds. Defaults to now if zero.
* @return false|null 'false' if unexpected parameters were given, else 'null'
*/
function close_span(float $finishTime = 0): false|null {}
/**
* Update the duration of an already closed span
*
* Note that this API won't cause an update of a closed span if it's already sent. Its usage, particularly on
* root spans with datadog.trace.auto_flush_enabled may not yield the expected results.
*
* @param SpanData $span The span to update.
* @param float $finishTime Finish time in seconds. Defaults to now if zero.
* @return false|null 'false' if unexpected parameters were given, else 'null'
*/
function update_span_duration(SpanData $span, float $finishTime = 0): false|null {}
/**
* Start a new trace
*
* More precisely, a new root span stack will be created and switched on to, and a new span started.
*
* @param float $startTime Start time of the span in seconds.
* @return RootSpanData The newly created root span
*/
function start_trace_span(float $startTime = 0): RootSpanData {}
/**
* Attempts to drop a span without breaking the trace.
* No metrics will be collected for that span, if successfully dropped.
* This means, the span is not dropped if any of the following were true before calling this function:
* - the span has a non-dropped child span
* - generate_distributed_tracing_headers() was called while this span was active
* - a span link to this span was generated
* @return bool Whether the span was successfully dropped.
*/
function try_drop_span(SpanData $span): bool {}
/**
* Get the active stack
*
* @return SpanStack|null A copy of the active stack, or 'null' if the tracer is disabled. Won't happen
* under normal operation.
*/
function active_stack(): SpanStack|null {}
/**
* Initialize a new span stack and switch to it. If tracing isn't enabled, a root span stack will be created.
*
* @return SpanStack The newly created span stack
*/
function create_stack(): SpanStack {}
/**
* Switch back to a specific stack (even if there is no active span on that stack), or to the parent of the active
* stack if no stack is given.
*
* @param SpanData|SpanStack|null $newStack Stack to switch to. If 'null' is given, switches to the parent of the
* active stack. If a SpanData object is given, it will switch to the stack of the latter.
* @return null|false|SpanStack The newly active stack, or 'null' if the tracer is disabled (Won't happen under
* normal operation), or 'false' if unexpected parameters were given.
*/
function switch_stack(SpanData|SpanStack|null $newStack = null): null|false|SpanStack {}
/**
* Set the priority sampling level
*
* @param int $priority The priority level to be set to.
* @param bool|null $global If set to 'true' and if there is no active stack (or the active stack doesn't have a
* root span), then the default priority sampling will be set to the provided priority level. Otherwise, the root's
* priority sampling level will be updated with the new value.
*/
function set_priority_sampling(int $priority, bool $global = false): void {}
/**
* Get the priority sampling level
*
* @param bool|null $global If set to 'true' and if there is no active stack (or the active stack doesn't have a
* root span), then the default priority sampling will be returned, else it will be fetched from the root.
* @return int|null The priority sampling level, or 'null' if an unexpected parameter was given.
*/
function get_priority_sampling(bool $global = false): int|null {}
/**
* Sanitize an exception
*
* @param \Throwable $exception
* @param int $skipFrames The number of frames to be dropped from the start. E.g. to hide the fact that we're
* in a hook function.
* @return string
*/
function get_sanitized_exception_trace(\Throwable $exception, int $skipFrames = 0): string {}
/**
* Collects code origin tags for the current active span given the current stack. It is advised to set attributes
* like meta[span.kind] and type before calling this function as it makes use of them. Has no effect without active
* span
*
* @param int $skipFrames The number of frames to be dropped from the start. E.g. to hide the fact that we're
* in a hook function.
*/
function collect_code_origins(int $skipFrames = 0): void {}
/**
* Update datadog headers for distributed tracing for new spans. Also applies this information to the current trace,
* if there is one, as well as the future ones if it isn't overwritten
*
* @param null|array|callable(string):mixed $headersOrCallback Either an array with a lowercase header to value mapping,
* or a callback, which given a header name for distributed tracing, returns the value it should be updated to. If null,
* this reads the headers directly from the $_SERVER superglobal.
*/
function consume_distributed_tracing_headers(null|array|callable $headersOrCallback): void {}
/**
* Get information on the key-value pairs of the datadog headers for distributed tracing
*
* @param null|string[] $inject The types of sampling headers which shall be generated, equivalent to what
* DD_TRACE_PROPAGATION_STYLE_INJECT supports. Defaults to DD_TRACE_PROPAGATION_STYLE_INJECT if null.
*
* @return array{x-datadog-sampling-priority: string,
* x-datadog-origin: string,
* x-datadog-trace-id: string,
* x-datadog-parent-id: string,
* traceparent: string,
* tracestate: string
* }
*/
function generate_distributed_tracing_headers(array|null $inject = null): array {}
/**
* Searches parent frames to see whether it's currently within a catch block and returns that exception.
*
* @return \Throwable|null The active exception if there is one, else 'null'.
*/
function find_active_exception(): \Throwable|null {}
/**
* Retrieve IPs from the given array if valid headers are found, and return them in
* a metadata formatting
*
* @param string[] $headers
* @return array
*/
function extract_ip_from_headers(array $headers): array {}
/**
* Get startup information in JSON format
*
* @return string Startup information
*/
function startup_logs(): string {}
/**
* Return the id of the current trace
*
* @return string The id of the current trace
*/
function trace_id(): string {}
/**
* Formatted trace id to be used for logs correlation.
*
* This function handles 128-bit trace ids and 64-bit trace ids. More specifically, if
* DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED is set to true and the current trace id is 128-bit, then the trace id
* will be returned as a 32-character hexadecimal string. Otherwise, the trace id will be returned as the
* decimal representation of the 64-bit trace id.
*
* @return string The formatted id of the current trace
*/
function logs_correlation_trace_id(): string {}
/**
* Get information on the current context
*
* @return array{trace_id: string, span_id: string, version: string, env: string}
*/
function current_context(): array {}
/**
* Apply the distributed tracing information on the current and future spans. That API can be called if there is no
* other currently active span.
*
* The distributed tracing context can be reset by calling 'set_distributed_tracing_context("0", "0")'
*
* @param string $traceId The unique integer (128-bit unsigned) ID of the trace containing this span
* @param string $parentId The span integer ID of the parent span
* @param string|null $origin The distributed tracing origin
* @param array|string|null $propagated_tags If provided, propagated tags from the root span will be cleared and
* replaced by the given tags and applied to existing spans
* @return bool 'true' if the distributed tracing context was properly set, else 'false' if an error occurred
*/
function set_distributed_tracing_context(
string $traceId,
string $parentId,
?string $origin = null,
array|string|null $propagated_tags = null
): bool {}
/**
* Closes all spans and force-send finished traces to the agent
*/
function flush(): void {}
/**
* Returns the array to be populated with spans for each request during the next curl_multi_exec() call.
* That array will be dropped internally after the curl_multi_exec() call completed.
*
* @return list{\CurlHandle, SpanData}[] $array An array which will be populated with curl handles and spans.
*/
function &curl_multi_exec_get_request_spans(): array {}
/**
* Update a DogStatsD counter
*
* @param string $metric The metric name
* @param int $value The metric value
* @param array $tags A list of tags associated to the metric
*/
function dogstatsd_count(string $metric, int $value, array $tags = []): void {}
/**
* Update a DogStatsD distribution
*
* @param string $metric The metric name
* @param float $value The metric value
* @param array $tags A list of tags associated to the metric
*/
function dogstatsd_distribution(string $metric, float $value, array $tags = []): void {}
/**
* Update a DogStatsD gauge
*
* @param string $metric The metric name
* @param float $value The metric value
* @param array $tags A list of tags associated to the metric
*/
function dogstatsd_gauge(string $metric, float $value, array $tags = []): void {}
/**
* Update a DogStatsD histogram
*
* @param string $metric The metric name
* @param float $value The metric value
* @param array $tags A list of tags associated to the metric
*/
function dogstatsd_histogram(string $metric, float $value, array $tags = []): void {}
/**
* Update a DogStatsD set
*
* @param string $metric The metric name
* @param int $value The metric value
* @param array $tags A list of tags associated to the metric
*/
function dogstatsd_set(string $metric, int $value, array $tags = []): void {}
/**
* Store data tied to a resource. Behaves like a weakmap, i.e. data is freed when the associated resource is freed.
*
* @param resource $resource Some resource
* @param string $key An arbitrary string key to uniquely match
* @param mixed $value The data to be stored
*/
function resource_weak_store(mixed $resource, string $key, mixed $value): void {}
/**
* Get data tied to the resource.
*
* @param resource $resource Some resource
* @param string $key An arbitrary string key to uniquely match
* @return mixed|null The stored value, or null if missing.
*/
function resource_weak_get(mixed $resource, string $key): mixed {}
/**
* Check if endpoints are already collected
*
* @return bool
*/
function are_endpoints_collected(): bool {}
/**
* Add an endpoint
*
* @param string $path The path of the endpoint
* @param string $operation_name The operation name of the endpoint
* @param string $resource_name The resource name of the endpoint
* @param string $method The method of the endpoint
*/
function add_endpoint(string $path, string $operation_name, string $resource_name, string $method): bool {}
/**
* Flush all buffered endpoints to the sidecar immediately.
* Call this once after batching all add_endpoint() calls.
*/
function flush_endpoints(): void {}
}
namespace DDTrace\System {
/**
* Get the unique identifier of the container
*
* @return string|null The container id, or 'null' if no id was found
*/
function container_id(): string|null {}
/**
* Get the process tags base hash
*
* Returns the FNV-1a 64-bit hash of serialized process tags combined with container tags hash.
* This hash is used for Database Monitoring to correlate queries with application processes.
*
* @return string|null The base hash as a binary string (8 bytes), or 'null' if process tags are disabled or not computed
*/
function process_tags_base_hash(): string|null {}
}
namespace DDTrace\Config {
/**
* Check if the app analytics of an app is enabled for a given integration
*
* @param string $integrationName The name of the integration (e.g., mysqli)
* @return bool The status of the app analytics of the integration
*/
function integration_analytics_enabled(string $integrationName): bool {}
/**
* Check the app analytics sample rate of a given integration
*
* @param string $integrationName The name of the integration (e.g., mysqli)
* @return float The sample rate of the app analytics of the integration
*/
function integration_analytics_sample_rate(string $integrationName): float {}
}
namespace DDTrace\UserRequest {
/**
* If there are any listeners of user request events.
* @return bool true iif there are any listeners
*/
function has_listeners(): bool {}
/**
* Notifies the user request listeners of the start of a user request.
*
* @param \DDTrace\RootSpanData $span the span associated with this user request.
* @param array $data an array with keys named '_GET', '_POST', '_SERVER', '_FILES', '_COOKIE'
* @param string|resource|null $body the body of the request (a string or a seekable resource)
* @return array|null an array with the keys 'status', 'headers' and 'body', or null
*/
function notify_start(\DDTrace\RootSpanData $span, array $data, mixed $body = null): ?array {}
/**
* Notifies the user request listeners of the imminence of a commit, and allows for the replacement of the response.
* @param \DDTrace\Span $span the span associated with this user request.
* @param int $status the HTTP status code of the response
* @param array $headers the HTTP headers of the response in the form name => array(values)
* @param string|resource|null $body the body of the response (a string or a seekable resource)
* @return array|null an array with the keys 'status', 'headers' and 'body', or null
*/
function notify_commit(\DDTrace\RootSpanData $span, int $status, array $headers, mixed $body = null): ?array {}
/**
* Sets a function to be called when blocking a request midway.
*
* @param \DDTrace\RootSpanData $span
* @param callable $blockingFunction a blocking function taking an array with the keys 'status', 'headers', 'body'
* @return void
*/
function set_blocking_function(\DDTrace\RootSpanData $span, callable $blockingFunction): void {}
}
namespace DDTrace\Testing {
/**
* Overrides PHP's default error handling.
*
* @param string $message Error message
* @param int $errorType Error Type. Supported error types are: E_ERROR, E_WARNING, E_PARSE, E_NOTICE, E_CORE_ERROR,
* E_CORE_WARNING, E_COMPILE_ERROR, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_STRICT, E_RECOVERABLE_ERROR,
* E_DEPRECATED, E_USER_DEPRECATED
*/
function trigger_error(string $message, int $errorType): void {}
/**
* Emits an asm event
*/
function emit_asm_event(): void {}
/**
* Normalizes a process tag value
*
* @param string $value The tag value to normalize
* @return string The normalized tag value
*/
function normalize_tag_value(string $value): string {}
}
namespace DDTrace\Internal {
/**
* @var int
* @cvalue DDTRACE_SPAN_FLAG_OPENTELEMETRY
*/
const SPAN_FLAG_OPENTELEMETRY = UNKNOWN;
/**
* @var int
* @cvalue DDTRACE_SPAN_FLAG_OPENTRACING
*/
const SPAN_FLAG_OPENTRACING = UNKNOWN;
/**
* Adds a flag to a span.
*
* @internal
*
* @param \DDTrace\SpanData $span the span to flag
* @param int $flag the flag to add to the span
*/
function add_span_flag(\DDTrace\SpanData $span, int $flag): void {}
/**
* To be called when a fork is performed.
*
* @internal
*/
function handle_fork(): void {}
}
namespace datadog\appsec\v2 {
/**
* Track a user login success event.
*
* @param string $login is the data used by the user to authenticate
* @param string|array $user when string, it represents the user id. When array it represents the user information.
* The array should at least contain the following keys:
* - id: string, Unique identifier of the user. Should be the same id and format used on set_user
* @param array $metadata User metadata added to the root span
*/
function track_user_login_success(string $login, string|array|null $user = null, array $metadata = []): void {}
/**
* Track a user login failure event.
*
* @param string $login is the data used by the user to authenticate
* @param bool $exists Whether the user exists in the system
* @param array $metadata User metadata added to the root span
*/
function track_user_login_failure(string $login, bool $exists, array $metadata = []): void {}
}