Skip to content

feat: Allow OTEL_PHP_DEBUG_SCOPES_DISABLED as en environment variable#1237

Merged
brettmc merged 6 commits intoopen-telemetry:mainfrom
PROFeNoM:alex/fix/env-var-scopes-disabled
Feb 29, 2024
Merged

feat: Allow OTEL_PHP_DEBUG_SCOPES_DISABLED as en environment variable#1237
brettmc merged 6 commits intoopen-telemetry:mainfrom
PROFeNoM:alex/fix/env-var-scopes-disabled

Conversation

@PROFeNoM
Copy link
Copy Markdown
Contributor

@PROFeNoM PROFeNoM commented Feb 23, 2024

Hi 👋

While doing some tests and trying to set OTEL_PHP_DEBUG_SCOPES_DISABLED to 1 as an environment variable to disable the use of DebugScope, it wouldn't work. This is because it wasn't considered.

I guess it could have also made sense to use some kind of a ResolverInterface, considering both INIs and env var.

Also, my personal opinion on this env var is that it could make sense to have it enabled by default (in the next major, being a breaking change), considering that the use of debug_backtrace has a non-negligible performance impact.

@welcome
Copy link
Copy Markdown

welcome bot commented Feb 23, 2024

Thanks for opening your first pull request! If you haven't yet signed our Contributor License Agreement (CLA), then please do so that we can accept your contribution. A link should appear shortly in this PR if you have not already signed one.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Feb 23, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@PROFeNoM PROFeNoM marked this pull request as ready for review February 23, 2024 12:37
@PROFeNoM PROFeNoM requested a review from a team February 23, 2024 12:37
@Nevay
Copy link
Copy Markdown
Contributor

Nevay commented Feb 23, 2024

Disabling via environment variable should work as expected (unless variables_order is configured to not populate $_SERVER):

OTEL_PHP_DEBUG_SCOPES_DISABLED=1 php -r 'require "vendor/autoload.php"; echo OpenTelemetry\Context\Context::getCurrent()->activate()::class, PHP_EOL;'

Assuming that you are using putenv() to set the environment variable as done in the testcase - putenv() is not threadsafe, for example vlucas/phpdotenv and symfony/dotenv won't populate it by default:

Using getenv() and putenv() is strongly discouraged due to the fact that these functions are not thread safe, however it is still possible to instruct PHP dotenv to use these functions.

Beware that putenv() is not thread safe, that's why it's not enabled by default
// don't check existence with getenv() because of thread safety issues

If we want to support putenv() / getenv(), we should IMO use the order $_SERVER > getenv() > ini_get().

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.08%. Comparing base (b20c45d) to head (b076c40).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1237      +/-   ##
============================================
- Coverage     83.09%   83.08%   -0.02%     
+ Complexity     2275     2274       -1     
============================================
  Files           285      285              
  Lines          6460     6456       -4     
============================================
- Hits           5368     5364       -4     
  Misses         1092     1092              
Flag Coverage Δ
7.4 81.72% <100.00%> (-0.02%) ⬇️
8.0 82.98% <100.00%> (-0.02%) ⬇️
8.1 83.14% <100.00%> (-0.02%) ⬇️
8.2 83.14% <100.00%> (-0.02%) ⬇️
8.3 83.14% <100.00%> (-0.02%) ⬇️
8.4 83.14% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/Context/Context.php 82.60% <100.00%> (+0.38%) ⬆️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b20c45d...b076c40. Read the comment docs.

Copy link
Copy Markdown
Contributor

@brettmc brettmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with how the SDK checks for variables, can you change the order to be $_SERVER, getenv, ini_get

Comment thread src/Context/Context.php Outdated
Comment thread tests/Unit/Context/ContextTest.php
Comment thread src/Context/Context.php Outdated
@PROFeNoM PROFeNoM changed the title fix: Allow OTEL_PHP_DEBUG_SCOPES_DISABLED as en environment variable feat: Allow OTEL_PHP_DEBUG_SCOPES_DISABLED as en environment variable Feb 29, 2024
@brettmc
Copy link
Copy Markdown
Contributor

brettmc commented Feb 29, 2024

Also, my personal opinion on this env var is that it could make sense to have it enabled by default (in the next major, being a breaking change), considering that the use of debug_backtrace has a non-negligible performance impact.

I think the idea is that because it's inside an assertion, when run with a production configuration that code will not be run. So in effect, you couldn't use DebugScope in a non-assertion environment even if you wanted to.

@brettmc
Copy link
Copy Markdown
Contributor

brettmc commented Feb 29, 2024

Can you add a test to prove what happens if the variable is falsey? I'm assuming that disabled=false === enabled, so there DebugScope should be used in this case.

@brettmc brettmc merged commit cc56628 into open-telemetry:main Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants