Describe your environment - php 8.2
Context
I am not sure how it works under the hood, yet OpenTelemetry is trying to guess if given scope is closed correctly from my understanding.
1. Notice when result of $span->activate() is assigned to variable, yet not used
Having such code:
$span = $tracer->spanBuilder('test');
$context = $span->activate();
If we don't close the $context within current PHP function scope it will throw an notice:
Notice: Scope: missing call to Scope::detach() for scope #352, created
at OpenTelemetry.Context.Context.activate(Context.php:84)
at OpenTelemetry.API.Trace.Span.activate(Span.php:51)
The scenario for this is where we don't want to close the context within the current PHP function scope is for separate Before and After method, where we will close the current scope by accessing scope and context in following way:
$currentContext = Context::storage()->scope();
$currentRelatedSpan = Span::getCurrent();
$currentContext->detach();
$currentRelatedSpan->end();
2. Exception when result of $span->activate() is not assigned to variable
Having such code:
$span = $tracer->spanBuilder('test');
$span->activate();
If we don't assign activate span, exception will be thrown.
Scope: unexpected call to Scope::detach() for scope #785, scope successfully detached but another scope should have been detached first
/data/app/vendor/open-telemetry/context/DebugScope.php:43
The scenario for this is the same as above. OpenTelemetry tries to guess something which works correctly, yet using singleton instances, to get and close the scopes correctly.
Describe your environment -
php 8.2Context
I am not sure how it works under the hood, yet OpenTelemetry is trying to guess if given scope is closed correctly from my understanding.
1. Notice when result of $span->activate() is assigned to variable, yet not used
Having such code:
If we don't close the $context within current PHP function scope it will throw an notice:
The scenario for this is where we don't want to close the context within the current PHP function scope is for separate Before and After method, where we will close the current scope by accessing scope and context in following way:
2. Exception when result of $span->activate() is not assigned to variable
Having such code:
If we don't assign activate span, exception will be thrown.
The scenario for this is the same as above. OpenTelemetry tries to guess something which works correctly, yet using singleton instances, to get and close the scopes correctly.