In my Laravel's middleware I generate a custom header value.
$correlationId = Uuid::uuid4()->toString();
if ($request->headers->has('Correlation-ID') === false) {
$request->headers->set('Correlation-ID', $correlationId);
}
When I throw an exception I easily get it in Sentry along with my custom header.
But the power of using Sentry and Correlation Id is when you tag something, each tagged value is indexed hence it amplifies the search feature to track issues.
I've found a logic for adding tags:
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
$scope->setTag('correlation_id', app(\Illuminate\Http\Request::class)->headers->get('Correlation-ID'));
});
The problem is that I don't know where to put it. When I add it into the same middleware it doesn't push my new correlation_id tag into sentry. Same when I put this code into boot method in AppServiceProvider class in a destination micro-service.
I can confirm that I get the UUID with no problems app(\Illuminate\Http\Request::class)->headers->get('Correlation-ID') but Sentry displays only the build-in tags:
What am I doing wrong?


