From f8681900693a237eb421429612dde27d12c2a685 Mon Sep 17 00:00:00 2001 From: Pawel Filipczak Date: Tue, 22 Oct 2024 22:01:23 +0200 Subject: [PATCH 1/2] Selective logging level per feature (#103) --- .gitignore | 1 + NOTICE | 51 ++++++-- composer.json | 2 +- docs/configure.md | 1 + elastic-otel-php.properties | 1 + prod/native/CMakeLists.txt | 1 + .../elastic_set_default_build_options.cmake | 12 +- prod/native/conanfile.txt | 1 + prod/native/extension/code/Hooking.cpp | 10 +- .../code/InternalFunctionInstrumentation.cpp | 58 ++++----- prod/native/extension/code/ModuleEntry.cpp | 8 +- .../native/extension/code/ModuleFunctions.cpp | 56 ++++++++- .../extension/code/ModuleIniEntries.cpp | 2 +- prod/native/extension/code/ModuleInit.cpp | 8 +- prod/native/libcommon/code/AgentGlobals.cpp | 13 ++- prod/native/libcommon/code/CMakeLists.txt | 3 + prod/native/libcommon/code/CommonUtils.cpp | 32 +++++ prod/native/libcommon/code/CommonUtils.h | 7 ++ .../libcommon/code/ConfigurationManager.h | 1 + .../libcommon/code/ConfigurationSnapshot.h | 2 + prod/native/libcommon/code/LogFeature.cpp | 37 ++++++ prod/native/libcommon/code/LogFeature.h.in | 41 +++++++ prod/native/libcommon/code/Logger.cpp | 24 ++++ prod/native/libcommon/code/Logger.h | 6 + prod/native/libcommon/code/LoggerInterface.h | 33 ++++-- prod/native/libcommon/code/RequestScope.h | 26 ++--- .../libcommon/code/transport/CurlSender.cpp | 2 +- .../libcommon/code/transport/HttpEndpoints.h | 2 +- .../code/transport/HttpTransportAsync.h | 34 +++--- .../native/libcommon/test/CommonUtilsTest.cpp | 79 +++++++++++-- prod/native/libphpbridge/code/OpCache.cpp | 8 +- prod/php/ElasticOTel/BootstrapStageLogger.php | 5 +- .../ElasticOTel/Log/LogFeature.php.template | 30 +++++ .../ElasticOTel/PhpPartVersion.php.template | 2 +- tools/build/configure_php_templates.sh | 110 ++++++++++++++++++ tools/build/generate_php_part_version.sh | 39 ------- 36 files changed, 587 insertions(+), 161 deletions(-) create mode 100644 prod/native/libcommon/code/LogFeature.cpp create mode 100644 prod/native/libcommon/code/LogFeature.h.in create mode 100644 prod/php/ElasticOTel/Log/LogFeature.php.template create mode 100755 tools/build/configure_php_templates.sh delete mode 100755 tools/build/generate_php_part_version.sh diff --git a/.gitignore b/.gitignore index af7301a..d086643 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ #generated version file prod/php/ElasticOTel/PhpPartVersion.php +prod/php/ElasticOTel/Log/LogFeature.php # Mac .DS_Store diff --git a/NOTICE b/NOTICE index 8d2edca..e7b1d17 100644 --- a/NOTICE +++ b/NOTICE @@ -9,10 +9,10 @@ This project depends on folliwng packages: -------------------------------------------------------------------------------- Package name: Boost C++ Libraries -Version: 1.83.0 +Version: 1.86.0 Authors: Boost contributors (https://github.com/boostorg/boost/graphs/contributors) Licenses: BSL-1.0 license -URL: https://github.com/boostorg/boost/tree/boost-1.83.0 +URL: https://github.com/boostorg/boost/tree/boost-1.86.0 LICENSE_1.0.txt content: @@ -43,10 +43,10 @@ DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- Package name: libcurl -Version: 8.0.1 +Version: 8.10.1 Authors: Daniel Stenberg, , and many contributors -Licenses: curl (https://github.com/curl/curl/blob/curl-8_0_1/COPYING) -URL: https://github.com/curl/curl/blob/curl-8_0_1/ +Licenses: curl (https://github.com/curl/curl/blob/curl-8_10_1/COPYING) +URL: https://github.com/curl/curl/blob/curl-8_10_1/ curl/COPYING content: @@ -73,13 +73,16 @@ Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder. +Notice: +Curl contains pieces of source code that is Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan. This notice is included here to comply with the distribution terms. + -------------------------------------------------------------------------------- Package name: libunwind -Version: 1.6.2 +Version: 1.8.1 Authors: David Mosberger Licenses: MIT -URL: https://github.com/libunwind/libunwind/tree/b3ca1b59a795a617877c01fe5d299ab7a07ff29d +URL: https://github.com/libunwind/libunwind/tree/9cc4d98b22ae57bc1d8c253988feb85d4298a634 No NOTICE file found LICENSE content: @@ -159,3 +162,37 @@ Copyright notice: -------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +Package name: magic_enum +Version: 0.9.6 +Authors: Jean-loup Gailly and Mark Adler +Licenses: MIT (https://github.com/Neargye/magic_enum/blob/v0.9.6/LICENSE) +URL: https://github.com/Neargye/magic_enum/tree/v0.9.6 + +No NOTICE file found +LICENSE content: +MIT License + +Copyright (c) 2019 - 2024 Daniil Goncharov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +-------------------------------------------------------------------------------- + diff --git a/composer.json b/composer.json index cacf77f..dc2fd54 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ }, "scripts": { "pre-autoload-dump": [ - "./tools/build/generate_php_part_version.sh" + "./tools/build/configure_php_templates.sh" ], "parallel-lint": [ "parallel-lint ./prod/php/ ./tests/ --exclude ./tests/polyfills/" diff --git a/docs/configure.md b/docs/configure.md index 96c4bc1..63131fc 100644 --- a/docs/configure.md +++ b/docs/configure.md @@ -67,4 +67,5 @@ _Currently there are no additional `OTEL_` options waiting to be contributed ups |ELASTIC_OTEL_LOG_LEVEL_FILE|OFF|OFF, CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACE|Log level for file sink. Set to OFF if you don't want to log to file. |ELASTIC_OTEL_LOG_LEVEL_STDERR|OFF|OFF, CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACE|Log level for the stderr sink. Set to OFF if you don't want to log to a file. This sink is recommended when running the application in a container. |ELASTIC_OTEL_LOG_LEVEL_SYSLOG|OFF|OFF, CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACE|Log level for file sink. Set to OFF if you don't want to log to file. This sink is recommended when you don't have write access to file system. +|ELASTIC_OTEL_LOG_FEATURES||Comma separated string with FEATURE=LEVEL pairs.
Supported features:
ALL, MODULE, REQUEST, TRANSPORT, BOOTSTRAP, HOOKS, INSTRUMENTATION|Allows selective setting of log level for features. For example, "ALL=info,TRANSPORT=trace" will result in all other features logging at the info level, while the TRANSPORT feature logs at the trace level. It should be noted that the appropriate log level must be set for the sink - for our example, this would be TRACE. |