Skip to content

Commit 64ff9db

Browse files
committed
fix: skip otlp tracing at test env
chore: disabled autodiscover keepsuit/laravel-opentelemetry fix: add LaravelOpenTelemetryServiceProvider only if env is not testing Signed-off-by: [email protected] <[email protected]>
1 parent 692fbea commit 64ff9db

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

app/Http/Middleware/TrackRequestMiddleware.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function __construct(LogManager $logger)
4646
*/
4747
public function handle(Request $request, Closure $next)
4848
{
49+
if(env('APP_ENV') === 'testing') {
50+
// Skip tracking in testing environment
51+
return $next($request);
52+
}
4953
try {
5054
// generating dynamic id for span with configurable prefix
5155
$spanId = env('TRACE_SPAN_PREFIX', 'SPAN') . '_' . Str::uuid();
@@ -73,6 +77,10 @@ public function handle(Request $request, Closure $next)
7377
*/
7478
public function terminate(Request $request, Response $response): void
7579
{
80+
if(env('APP_ENV') === 'testing') {
81+
// Skip tracking in testing environment
82+
return;
83+
}
7684
try {
7785
$endTime = microtime(true);
7886
$responseTime = intval(($endTime - $this->startTime) * 1000);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"extra": {
9292
"laravel": {
9393
"dont-discover": [
94+
"keepsuit/laravel-opentelemetry"
9495
]
9596
}
9697
},

config/app.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@
171171
LaravelDoctrine\Migrations\MigrationsServiceProvider::class,
172172
SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class,
173173
\App\Providers\DoctrineWorkerServiceProvider::class,
174+
// only register OpenTelemetry if we're NOT in the "testing" env:
175+
env('APP_ENV') !== 'testing'
176+
? \Keepsuit\LaravelOpenTelemetry\LaravelOpenTelemetryServiceProvider::class
177+
: null,
174178
],
175179

176180
/*

0 commit comments

Comments
 (0)