@@ -19,50 +19,90 @@ $tests = [
19
19
["f*o*e " , "fooname " , true ],
20
20
["f*o*m? " , "fooname " , true ],
21
21
["f*x*m? " , "fooname " , false ],
22
-
22
+ ["fooname " , "FOONAME " , true ],
23
+ ["fooNAME " , "FOOname " , true ],
24
+ ["fooNAME " , "FOOname " , true ],
25
+ ["[ooNAM] " , "{OOnam} " , false ],
26
+ ["{ooNAM} " , "[OOnam] " , false ],
27
+ ["* " , 1.2 , true ],
28
+ ["**** " , 1.2 , true ],
29
+ ["" , 1.2 , false ],
30
+ ["1.2 " , 1.2 , false ],
31
+ ["" , 1 , false ],
32
+ ["1 " , 1 , true ],
33
+ ["1 " , 1.0 , true ],
34
+ ["1* " , 1.0 , true ],
35
+ ["1* " , 1 , true ],
36
+ ["1* " , 10 , true ],
37
+ ["1* " , 0 , false ],
38
+ ["true " , true , true ],
39
+ ["truee " , true , false ],
40
+ ["* " , true , true ],
41
+ ["FALSE " , false , true ],
42
+ ["FALS " , false , false ],
43
+ ["" , null , true ],
44
+ ["* " , null , true ],
45
+ ["? " , null , false ],
23
46
];
24
47
25
48
foreach ($ tests as list ($ pattern , $ name , $ matches )) {
26
- ini_set ("datadog.trace.sampling_rules " , '[{"name":" ' . $ pattern . '","sample_rate":0.7},{"sample_rate": 0.3}] ' );
49
+ if (\is_string ($ name )) {
50
+ ini_set ("datadog.trace.sampling_rules " , '[{"name":" ' . $ pattern . '","sample_rate":0.7},{"sample_rate": 0.3}] ' );
27
51
28
- $ root = DDTrace \root_span ();
29
- $ root ->name = $ name ;
52
+ $ root = DDTrace \root_span ();
53
+ $ root ->name = $ name ;
30
54
31
- DDTrace \get_priority_sampling ();
55
+ DDTrace \get_priority_sampling ();
32
56
33
- if ($ root ->metrics ["_dd.rule_psr " ] == ($ matches ? 0.7 : 0.3 )) {
34
- echo "As expected, $ pattern " . ($ matches ? "matches " : "doesn't match " ) . " $ name (name) \n" ;
35
- } else {
36
- echo "$ pattern " . ($ matches ? "should have matched " : "shouldn't have matched " ) . " $ name (service). Metrics found were: \n" ;
37
- var_dump ($ root ->metrics );
38
- }
57
+ if ($ root ->metrics ["_dd.rule_psr " ] == ($ matches ? 0.7 : 0.3 )) {
58
+ echo "As expected, $ pattern " . ($ matches ? "matches " : "doesn't match " ) . " $ name (name) \n" ;
59
+ } else {
60
+ echo "$ pattern " . ($ matches ? "should have matched " : "shouldn't have matched " ) . " $ name (service). Metrics found were: \n" ;
61
+ var_dump ($ root ->metrics );
62
+ }
39
63
40
- ini_set ("datadog.trace_sampling_rules " , '[{"service":" ' . $ pattern . '","sample_rate":0.7},{"sample_rate": 0.3] ' );
64
+ ini_set ("datadog.trace.sampling_rules " , '[{"service":" ' . $ pattern . '","sample_rate":0.7},{"sample_rate": 0.3} ] ' );
41
65
42
- $ root = \DDTrace \root_span ();
43
- $ root ->service = $ name ;
66
+ $ root = \DDTrace \root_span ();
67
+ $ root ->service = $ name ;
44
68
45
- \DDTrace \get_priority_sampling ();
69
+ \DDTrace \get_priority_sampling ();
46
70
47
- if ($ root ->metrics ["_dd.rule_psr " ] == ($ matches ? 0.7 : 0.3 )) {
48
- echo "As expected, $ pattern " . ($ matches ? "matches " : "doesn't match " ) . " $ name (service) \n" ;
49
- } else {
50
- echo "$ pattern " . ($ matches ? "should have matched " : "shouldn't have matched " ) . " $ name (service). Metrics found were: \n" ;
51
- var_dump ($ root ->metrics );
52
- }
71
+ if ($ root ->metrics ["_dd.rule_psr " ] == ($ matches ? 0.7 : 0.3 )) {
72
+ echo "As expected, $ pattern " . ($ matches ? "matches " : "doesn't match " ) . " $ name (service) \n" ;
73
+ } else {
74
+ echo "$ pattern " . ($ matches ? "should have matched " : "shouldn't have matched " ) . " $ name (service). Metrics found were: \n" ;
75
+ var_dump ($ root ->metrics );
76
+ }
53
77
54
- ini_set ("datadog.trace_sampling_rules " , '[{"resource":" ' . $ pattern . '","sample_rate":0.7},{"sample_rate": 0.3] ' );
78
+ ini_set ("datadog.trace.sampling_rules " , '[{"resource":" ' . $ pattern . '","sample_rate":0.7},{"sample_rate": 0.3} ] ' );
55
79
56
- $ root = \DDTrace \root_span ();
57
- $ root ->resource = $ name ;
80
+ $ root = \DDTrace \root_span ();
81
+ $ root ->resource = $ name ;
58
82
59
- \DDTrace \get_priority_sampling ();
83
+ \DDTrace \get_priority_sampling ();
60
84
61
- if ($ root ->metrics ["_dd.rule_psr " ] == ($ matches ? 0.7 : 0.3 )) {
62
- echo "As expected, $ pattern " . ($ matches ? "matches " : "doesn't match " ) . " $ name (resource) \n" ;
85
+ if ($ root ->metrics ["_dd.rule_psr " ] == ($ matches ? 0.7 : 0.3 )) {
86
+ echo "As expected, $ pattern " . ($ matches ? "matches " : "doesn't match " ) . " $ name (resource) \n" ;
87
+ } else {
88
+ echo "$ pattern " . ($ matches ? "should have matched " : "shouldn't have matched " ) . " $ name (resource). Metrics found were: \n" ;
89
+ var_dump ($ root ->metrics );
90
+ }
63
91
} else {
64
- echo "$ pattern " . ($ matches ? "should have matched " : "shouldn't have matched " ) . " $ name (resource). Metrics found were: \n" ;
65
- var_dump ($ root ->metrics );
92
+ ini_set ("datadog.trace.sampling_rules " , '[{"tags":{"foo":" ' . $ pattern . '"},"sample_rate":0.7},{"sample_rate": 0.3}] ' );
93
+
94
+ $ root = \DDTrace \root_span ();
95
+ $ root ->meta ["foo " ] = $ name ;
96
+
97
+ \DDTrace \get_priority_sampling ();
98
+
99
+ $ name = var_export ($ name , true );
100
+ if ($ root ->metrics ["_dd.rule_psr " ] == ($ matches ? 0.7 : 0.3 )) {
101
+ echo "As expected, $ pattern " . ($ matches ? "matches " : "doesn't match " ) . " $ name (tag) \n" ;
102
+ } else {
103
+ echo "$ pattern " . ($ matches ? "should have matched " : "shouldn't have matched " ) . " $ name (tag). Metrics found were: \n" ;
104
+ var_dump ($ root ->metrics );
105
+ }
66
106
}
67
107
}
68
108
?>
@@ -104,3 +144,37 @@ As expected, f*o*m? matches fooname (resource)
104
144
As expected, f*x*m? doesn't match fooname (name)
105
145
As expected, f*x*m? doesn't match fooname (service)
106
146
As expected, f*x*m? doesn't match fooname (resource)
147
+ As expected, fooname matches FOONAME (name)
148
+ As expected, fooname matches FOONAME (service)
149
+ As expected, fooname matches FOONAME (resource)
150
+ As expected, fooNAME matches FOOname (name)
151
+ As expected, fooNAME matches FOOname (service)
152
+ As expected, fooNAME matches FOOname (resource)
153
+ As expected, fooNAME matches FOOname (name)
154
+ As expected, fooNAME matches FOOname (service)
155
+ As expected, fooNAME matches FOOname (resource)
156
+ As expected, [ooNAM] doesn't match {OOnam} (name)
157
+ As expected, [ooNAM] doesn't match {OOnam} (service)
158
+ As expected, [ooNAM] doesn't match {OOnam} (resource)
159
+ As expected, {ooNAM} doesn't match [OOnam] (name)
160
+ As expected, {ooNAM} doesn't match [OOnam] (service)
161
+ As expected, {ooNAM} doesn't match [OOnam] (resource)
162
+ As expected, * matches 1.2 (tag)
163
+ As expected, **** matches 1.2 (tag)
164
+ As expected, doesn't match 1.2 (tag)
165
+ As expected, 1.2 doesn't match 1.2 (tag)
166
+ As expected, doesn't match 1 (tag)
167
+ As expected, 1 matches 1 (tag)
168
+ As expected, 1 matches 1.0 (tag)
169
+ As expected, 1* matches 1.0 (tag)
170
+ As expected, 1* matches 1 (tag)
171
+ As expected, 1* matches 10 (tag)
172
+ As expected, 1* doesn't match 0 (tag)
173
+ As expected, true matches true (tag)
174
+ As expected, truee doesn't match true (tag)
175
+ As expected, * matches true (tag)
176
+ As expected, FALSE matches false (tag)
177
+ As expected, FALS doesn't match false (tag)
178
+ As expected, matches NULL (tag)
179
+ As expected, * matches NULL (tag)
180
+ As expected, ? doesn't match NULL (tag)
0 commit comments