Skip to content

Commit

Permalink
Laravel: end span post Command::execute hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLightfootWild committed Sep 19, 2023
1 parent 2c18066 commit 22dd5b0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Instrumentation/Laravel/src/ConsoleInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static function register(CachedInstrumentation $instrumentation): void
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)
->setAttribute(TraceAttributes::CODE_LINENO, $lineno);

$parent = Context::getCurrent();
$span = $builder->startSpan();
Context::storage()->attach($span->storeInContext($parent));
Expand All @@ -42,6 +43,7 @@ public static function register(CachedInstrumentation $instrumentation): void
if (!$scope) {
return;
}

$scope->detach();
$span = Span::fromContext($scope->context());
if ($exception) {
Expand All @@ -68,8 +70,8 @@ public static function register(CachedInstrumentation $instrumentation): void
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)
->setAttribute(TraceAttributes::CODE_LINENO, $lineno);
$parent = Context::getCurrent();

$parent = Context::getCurrent();
$span = $builder->startSpan();
Context::storage()->attach($span->storeInContext($parent));

Expand All @@ -80,6 +82,7 @@ public static function register(CachedInstrumentation $instrumentation): void
if (!$scope) {
return;
}

$scope->detach();
$span = Span::fromContext($scope->context());
$span->addEvent('command finished', [
Expand All @@ -90,6 +93,8 @@ public static function register(CachedInstrumentation $instrumentation): void
$span->recordException($exception, [TraceAttributes::EXCEPTION_ESCAPED => true]);
$span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage());
}

$span->end();
}
);
}
Expand Down

0 comments on commit 22dd5b0

Please sign in to comment.