@@ -86,6 +86,8 @@ protected function setUp(): void
8686 ['open-telemetry.metrics.exporters.otlp_http.options.endpoint ' , 'localhost ' , 'http://collector:4318 ' ],
8787 ['open-telemetry.instrumentation.features.guzzle.options.headers.request ' , ['* ' ], ['* ' ]],
8888 ['open-telemetry.instrumentation.features.guzzle.options.headers.response ' , ['* ' ], ['* ' ]],
89+ ['open-telemetry.traces.uri_mask ' , [], ['/P2P[0-9A-Za-z]+/ ' => '{identifier} ' ]],
90+ ['open-telemetry.metrics.uri_mask ' , [], ['/P2P[0-9A-Za-z]+/ ' => '{identifier} ' ]],
8991 ]);
9092
9193 $ this ->proceedingJoinPoint ->arguments = ['keys ' => ['request ' => $ this ->request ]];
@@ -215,6 +217,95 @@ public function testProcessWithSuccessRequest(): void
215217
216218 $ this ->assertEquals ($ this ->promise , $ result );
217219 }
220+ public function testProcessWithUriMaskAndSuccessRequest (): void
221+ {
222+ $ this ->configureRequestMock (
223+ 'GET ' ,
224+ 'https://api.example.com/v1/users/P2P123/transactions?page=1 ' ,
225+ ['User-Agent ' => ['TestAgent/1.0 ' ]]
226+ );
227+
228+ $ this ->configureResponseMock ();
229+
230+ $ aspect = new GuzzleClientAspect (
231+ $ this ->config ,
232+ $ this ->instrumentation ,
233+ $ this ->switcher
234+ );
235+
236+ $ this ->promise ->expects ($ this ->once ())
237+ ->method ('then ' )
238+ ->willReturnCallback (function ($ fullFilled , $ rejected ) {
239+ $ this ->assertIsCallable ($ fullFilled );
240+ $ this ->assertIsCallable ($ rejected );
241+
242+ $ fullFilled ($ this ->response );
243+
244+ return $ this ->promise ;
245+ });
246+
247+ // Span
248+ $ this ->instrumentation
249+ ->expects ($ this ->once ())
250+ ->method ('startSpan ' )
251+ ->with (
252+ $ this ->equalTo ('GET /v1/users/{identifier}/transactions ' ),
253+ $ this ->equalTo (SpanKind::KIND_CLIENT ),
254+ [
255+ HttpAttributes::HTTP_REQUEST_METHOD => 'GET ' ,
256+ UrlAttributes::URL_FULL => 'https://api.example.com/v1/users/P2P123/transactions?page=1 ' ,
257+ UrlAttributes::URL_PATH => '/v1/users/P2P123/transactions ' ,
258+ UrlAttributes::URL_SCHEME => 'https ' ,
259+ UrlAttributes::URL_QUERY => 'page=1 ' ,
260+ ServerAttributes::SERVER_ADDRESS => 'api.example.com ' ,
261+ ServerAttributes::SERVER_PORT => 443 ,
262+ UserAgentAttributes::USER_AGENT_ORIGINAL => 'TestAgent/1.0 ' ,
263+ 'http.request.header.user-agent ' => 'TestAgent/1.0 ' ,
264+ ]
265+ )
266+ ->willReturn ($ this ->spanScope );
267+
268+ $ this ->propagator ->expects ($ this ->once ())
269+ ->method ('inject ' )
270+ ->with ($ this ->request , $ this ->anything (), $ this ->spanScope ->getContext ());
271+
272+ $ this ->spanScope ->expects ($ this ->once ())->method ('detach ' );
273+
274+ $ this ->spanScope ->expects ($ this ->never ())->method ('setStatus ' );
275+
276+ $ this ->spanScope ->expects ($ this ->once ())
277+ ->method ('setAttributes ' )
278+ ->with ([
279+ HttpAttributes::HTTP_RESPONSE_STATUS_CODE => 200 ,
280+ HttpIncubatingAttributes::HTTP_RESPONSE_BODY_SIZE => '1024 ' ,
281+ 'http.response.header.content-type ' => 'application/json ' ,
282+ 'http.response.header.content-length ' => '1024 ' ,
283+ ]);
284+
285+ $ this ->spanScope ->expects ($ this ->once ())->method ('end ' );
286+
287+ // Metric
288+ $ this ->meter ->expects ($ this ->once ())
289+ ->method ('createHistogram ' )
290+ ->with ('http.client.request.duration ' , 'ms ' )
291+ ->willReturn ($ this ->histogram );
292+
293+ $ this ->histogram ->expects ($ this ->once ())
294+ ->method ('record ' )
295+ ->with (
296+ $ this ->isType ('float ' ),
297+ [
298+ ServerAttributes::SERVER_ADDRESS => 'api.example.com ' ,
299+ UrlIncubatingAttributes::URL_TEMPLATE => '/v1/users/{identifier}/transactions ' ,
300+ HttpAttributes::HTTP_REQUEST_METHOD => 'GET ' ,
301+ HttpAttributes::HTTP_RESPONSE_STATUS_CODE => 200 ,
302+ ]
303+ );
304+
305+ $ result = $ aspect ->process ($ this ->proceedingJoinPoint );
306+
307+ $ this ->assertEquals ($ this ->promise , $ result );
308+ }
218309
219310 public function testProcessWithBadRequest (): void
220311 {
0 commit comments