Skip to content

Commit 844b1e4

Browse files
feat: add mask
1 parent 2751f70 commit 844b1e4

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/Aspect/GuzzleClientAspect.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint): mixed
6565

6666
if ($this->isTracingEnabled) {
6767
$scope = $this->instrumentation->startSpan(
68-
name: $method . ' ' . Uri::sanitize($request->getUri()->getPath()),
68+
name: $method . ' ' . Uri::sanitize($request->getUri()->getPath(), $this->config->get('open-telemetry.traces.uri_mask', [])),
6969
spanKind: SpanKind::KIND_CLIENT,
7070
attributes: [
7171
HttpAttributes::HTTP_REQUEST_METHOD => $method,
@@ -128,9 +128,12 @@ private function onFullFilled(?SpanScope $scope, RequestInterface $request, floa
128128
->createHistogram('http.client.request.duration', 'ms')
129129
->record($duration, [
130130
ServerAttributes::SERVER_ADDRESS => $request->getUri()->getHost(),
131-
UrlIncubatingAttributes::URL_TEMPLATE => Uri::sanitize($request->getUri()->getPath()),
132131
HttpAttributes::HTTP_REQUEST_METHOD => $request->getMethod(),
133132
HttpAttributes::HTTP_RESPONSE_STATUS_CODE => $response->getStatusCode(),
133+
UrlIncubatingAttributes::URL_TEMPLATE => Uri::sanitize(
134+
$request->getUri()->getPath(),
135+
$this->config->get('open-telemetry.metrics.uri_mask', []),
136+
),
134137
]);
135138
}
136139

@@ -156,8 +159,11 @@ private function onRejected(?SpanScope $scope, RequestInterface $request, float
156159
ServerAttributes::SERVER_ADDRESS => $request->getUri()->getHost(),
157160
HttpAttributes::HTTP_REQUEST_METHOD => $request->getMethod(),
158161
HttpAttributes::HTTP_RESPONSE_STATUS_CODE => 0,
159-
UrlIncubatingAttributes::URL_TEMPLATE => Uri::sanitize($request->getUri()->getPath()),
160162
ErrorAttributes::ERROR_TYPE => get_class($throwable),
163+
UrlIncubatingAttributes::URL_TEMPLATE => Uri::sanitize(
164+
$request->getUri()->getPath(),
165+
$this->config->get('open-telemetry.traces.uri_mask', []),
166+
),
161167
]
162168
);
163169
}

src/Middleware/MetricMiddleware.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
3030
$startTime = microtime(true);
3131

3232
$attributes = [
33-
HttpAttributes::HTTP_ROUTE => Uri::sanitize($request->getUri()->getPath()),
3433
HttpAttributes::HTTP_REQUEST_METHOD => $request->getMethod(),
34+
HttpAttributes::HTTP_ROUTE => Uri::sanitize(
35+
$request->getUri()->getPath(),
36+
$this->config->get('open-telemetry.metrics.uri_mask', [])
37+
),
3538
];
3639

3740
try {

src/Middleware/TraceMiddleware.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
4545
attributes: [
4646
HttpAttributes::HTTP_REQUEST_METHOD => $request->getMethod(),
4747
UrlAttributes::URL_FULL => (string) $request->getUri(),
48-
UrlAttributes::URL_PATH => $request->getUri()->getPath(),
48+
UrlAttributes::URL_PATH => Uri::sanitize(
49+
$request->getUri()->getPath(),
50+
$this->config->get('open-telemetry.traces.uri_mask', [])
51+
),
4952
UrlAttributes::URL_SCHEME => $request->getUri()->getScheme(),
5053
UrlAttributes::URL_QUERY => $request->getUri()->getQuery(),
5154
ServerAttributes::SERVER_ADDRESS => $request->getUri()->getHost(),

0 commit comments

Comments
 (0)