13
13
use Sentry \SentryBundle \EventListener \RequestListenerTerminateEvent ;
14
14
use Sentry \SentryBundle \EventListener \TracingRequestListener ;
15
15
use Sentry \State \HubInterface ;
16
+ use Sentry \Tracing \DynamicSamplingContext ;
16
17
use Sentry \Tracing \SpanId ;
17
18
use Sentry \Tracing \SpanStatus ;
18
19
use Sentry \Tracing \TraceId ;
19
20
use Sentry \Tracing \Transaction ;
20
21
use Sentry \Tracing \TransactionContext ;
22
+ use Sentry \Tracing \TransactionSource ;
21
23
use Symfony \Bridge \PhpUnit \ClockMock ;
22
24
use Symfony \Component \HttpFoundation \Request ;
23
25
use Symfony \Component \HttpFoundation \Response ;
@@ -85,11 +87,15 @@ public function testHandleKernelRequestEvent(Options $options, Request $request,
85
87
*/
86
88
public function handleKernelRequestEventDataProvider (): \Generator
87
89
{
90
+ $ samplingContext = DynamicSamplingContext::fromHeader ('' );
91
+ $ samplingContext ->freeze ();
92
+
88
93
$ transactionContext = new TransactionContext ();
89
94
$ transactionContext ->setTraceId (new TraceId ('566e3688a61d4bc888951642d6f14a19 ' ));
90
95
$ transactionContext ->setParentSpanId (new SpanId ('566e3688a61d4bc8 ' ));
91
96
$ transactionContext ->setParentSampled (true );
92
97
$ transactionContext ->setName ('GET http://www.example.com/ ' );
98
+ $ transactionContext ->setSource (TransactionSource::url ());
93
99
$ transactionContext ->setOp ('http.server ' );
94
100
$ transactionContext ->setStartTimestamp (1613493597.010275 );
95
101
$ transactionContext ->setTags ([
@@ -100,6 +106,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
100
106
'route ' => '<unknown> ' ,
101
107
'net.host.name ' => 'www.example.com ' ,
102
108
]);
109
+ $ transactionContext ->getMetadata ()->setDynamicSamplingContext ($ samplingContext );
103
110
104
111
yield 'request.headers.sentry-trace EXISTS ' => [
105
112
new Options (),
@@ -117,8 +124,47 @@ public function handleKernelRequestEventDataProvider(): \Generator
117
124
$ transactionContext ,
118
125
];
119
126
127
+ $ samplingContext = DynamicSamplingContext::fromHeader ('sentry-trace_id=566e3688a61d4bc888951642d6f14a19,sentry-public_key=public,sentry-sample_rate=1 ' );
128
+ $ samplingContext ->freeze ();
129
+
130
+ $ transactionContext = new TransactionContext ();
131
+ $ transactionContext ->setTraceId (new TraceId ('566e3688a61d4bc888951642d6f14a19 ' ));
132
+ $ transactionContext ->setParentSpanId (new SpanId ('566e3688a61d4bc8 ' ));
133
+ $ transactionContext ->setParentSampled (true );
134
+ $ transactionContext ->setName ('GET http://www.example.com/ ' );
135
+ $ transactionContext ->setSource (TransactionSource::url ());
136
+ $ transactionContext ->setOp ('http.server ' );
137
+ $ transactionContext ->setStartTimestamp (1613493597.010275 );
138
+ $ transactionContext ->setTags ([
139
+ 'net.host.port ' => '80 ' ,
140
+ 'http.method ' => 'GET ' ,
141
+ 'http.url ' => 'http://www.example.com/ ' ,
142
+ 'http.flavor ' => '1.1 ' ,
143
+ 'route ' => '<unknown> ' ,
144
+ 'net.host.name ' => 'www.example.com ' ,
145
+ ]);
146
+ $ transactionContext ->getMetadata ()->setDynamicSamplingContext ($ samplingContext );
147
+
148
+ yield 'request.headers.sentry-trace and headers.baggage EXISTS ' => [
149
+ new Options (),
150
+ Request::create (
151
+ 'http://www.example.com ' ,
152
+ 'GET ' ,
153
+ [],
154
+ [],
155
+ [],
156
+ [
157
+ 'REQUEST_TIME_FLOAT ' => 1613493597.010275 ,
158
+ 'HTTP_sentry-trace ' => '566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-1 ' ,
159
+ 'HTTP_baggage ' => 'sentry-trace_id=566e3688a61d4bc888951642d6f14a19,sentry-public_key=public,sentry-sample_rate=1 ' ,
160
+ ]
161
+ ),
162
+ $ transactionContext ,
163
+ ];
164
+
120
165
$ transactionContext = new TransactionContext ();
121
166
$ transactionContext ->setName ('GET http://www.example.com/ ' );
167
+ $ transactionContext ->setSource (TransactionSource::url ());
122
168
$ transactionContext ->setOp ('http.server ' );
123
169
$ transactionContext ->setStartTimestamp (1613493597.010275 );
124
170
$ transactionContext ->setTags ([
@@ -141,6 +187,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
141
187
142
188
$ transactionContext = new TransactionContext ();
143
189
$ transactionContext ->setName ('GET http://127.0.0.1/ ' );
190
+ $ transactionContext ->setSource (TransactionSource::url ());
144
191
$ transactionContext ->setOp ('http.server ' );
145
192
$ transactionContext ->setStartTimestamp (1613493597.010275 );
146
193
$ transactionContext ->setTags ([
@@ -171,6 +218,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
171
218
172
219
$ transactionContext = new TransactionContext ();
173
220
$ transactionContext ->setName ('GET http://www.example.com/path ' );
221
+ $ transactionContext ->setSource (TransactionSource::url ());
174
222
$ transactionContext ->setOp ('http.server ' );
175
223
$ transactionContext ->setStartTimestamp (1613493597.010275 );
176
224
$ transactionContext ->setTags ([
@@ -194,6 +242,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
194
242
195
243
$ transactionContext = new TransactionContext ();
196
244
$ transactionContext ->setName ('GET http://www.example.com/path ' );
245
+ $ transactionContext ->setSource (TransactionSource::url ());
197
246
$ transactionContext ->setOp ('http.server ' );
198
247
$ transactionContext ->setStartTimestamp (1613493597.010275 );
199
248
$ transactionContext ->setTags ([
@@ -217,6 +266,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
217
266
218
267
$ transactionContext = new TransactionContext ();
219
268
$ transactionContext ->setName ('GET http://www.example.com/ ' );
269
+ $ transactionContext ->setSource (TransactionSource::url ());
220
270
$ transactionContext ->setOp ('http.server ' );
221
271
$ transactionContext ->setStartTimestamp (1613493597.010275 );
222
272
$ transactionContext ->setTags ([
@@ -240,6 +290,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
240
290
241
291
$ transactionContext = new TransactionContext ();
242
292
$ transactionContext ->setName ('GET http://www.example.com/ ' );
293
+ $ transactionContext ->setSource (TransactionSource::url ());
243
294
$ transactionContext ->setOp ('http.server ' );
244
295
$ transactionContext ->setStartTimestamp (1613493597.010275 );
245
296
$ transactionContext ->setTags ([
@@ -263,6 +314,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
263
314
264
315
$ transactionContext = new TransactionContext ();
265
316
$ transactionContext ->setName ('GET http://www.example.com/ ' );
317
+ $ transactionContext ->setSource (TransactionSource::url ());
266
318
$ transactionContext ->setOp ('http.server ' );
267
319
$ transactionContext ->setStartTimestamp (1613493597.010275 );
268
320
$ transactionContext ->setTags ([
@@ -286,6 +338,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
286
338
287
339
$ transactionContext = new TransactionContext ();
288
340
$ transactionContext ->setName ('GET http://www.example.com/ ' );
341
+ $ transactionContext ->setSource (TransactionSource::url ());
289
342
$ transactionContext ->setOp ('http.server ' );
290
343
$ transactionContext ->setStartTimestamp (1613493597.010275 );
291
344
$ transactionContext ->setTags ([
@@ -309,6 +362,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
309
362
310
363
$ transactionContext = new TransactionContext ();
311
364
$ transactionContext ->setName ('GET http://www.example.com/ ' );
365
+ $ transactionContext ->setSource (TransactionSource::url ());
312
366
$ transactionContext ->setOp ('http.server ' );
313
367
$ transactionContext ->setStartTimestamp (1613493597.010275 );
314
368
$ transactionContext ->setTags ([
@@ -332,6 +386,7 @@ public function handleKernelRequestEventDataProvider(): \Generator
332
386
333
387
$ transactionContext = new TransactionContext ();
334
388
$ transactionContext ->setName ('GET http://:/ ' );
389
+ $ transactionContext ->setSource (TransactionSource::url ());
335
390
$ transactionContext ->setOp ('http.server ' );
336
391
$ transactionContext ->setStartTimestamp (1613493597.010275 );
337
392
$ transactionContext ->setTags ([
0 commit comments