File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 55namespace OpenTelemetry \Context ;
66
77use function assert ;
8+ use const FILTER_VALIDATE_BOOLEAN ;
9+ use function filter_var ;
10+ use function ini_get ;
811use function spl_object_id ;
912
1013/**
@@ -80,12 +83,19 @@ public static function getCurrent(): ContextInterface
8083 public function activate (): ScopeInterface
8184 {
8285 $ scope = self ::storage ()->attach ($ this );
83- /** @psalm-suppress RedundantCondition */
84- assert (( bool ) $ scope = new DebugScope ($ scope ));
86+ /** @psalm-suppress RedundantCondition @phpstan-ignore-next-line */
87+ assert (self :: debugScopesDisabled () || $ scope = new DebugScope ($ scope ));
8588
8689 return $ scope ;
8790 }
8891
92+ private static function debugScopesDisabled (): bool
93+ {
94+ $ disabled = $ _SERVER ['OTEL_PHP_DEBUG_SCOPES_DISABLED ' ] ?? ini_get ('OTEL_PHP_DEBUG_SCOPES_DISABLED ' );
95+
96+ return filter_var ($ disabled , FILTER_VALIDATE_BOOLEAN );
97+ }
98+
8999 public function withContextValue (ImplicitContextKeyedInterface $ value ): ContextInterface
90100 {
91101 return $ value ->storeInContext ($ this );
Original file line number Diff line number Diff line change 3131
3232It is recommended to use a ` try-finally ` statement after ` ::activate() ` to ensure that the created scope is properly ` ::detach() ` ed.
3333
34+ ### Debug scopes
35+
36+ By default, scopes created by ` ::activate() ` warn on invalid and missing calls to ` ::detach() ` in non-production
37+ environments. This feature can be disabled by setting the environment variable ` OTEL_PHP_DEBUG_SCOPES_DISABLED ` to a
38+ truthy value. Disabling is only recommended for applications using ` exit ` / ` die ` to prevent unavoidable notices.
39+
3440## Async applications
3541
3642### Fiber support
You can’t perform that action at this time.
0 commit comments