Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selective logging level per feature (#103) #112

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-php-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ jobs:
path: |
prod/php/vendor_*
prod/php/ElasticOTel/PhpPartVersion.php
prod/php/ElasticOTel/Log/LogFeature.php
NOTICE
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#generated version file
prod/php/ElasticOTel/PhpPartVersion.php
prod/php/ElasticOTel/Log/LogFeature.php

# Mac
.DS_Store
Expand Down
51 changes: 44 additions & 7 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -43,10 +43,10 @@ DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------

Package name: libcurl
Version: 8.0.1
Version: 8.10.1
Authors: Daniel Stenberg, <[email protected]>, 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:

Expand All @@ -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 <[email protected]>
Licenses: MIT
URL: https://github.com/libunwind/libunwind/tree/b3ca1b59a795a617877c01fe5d299ab7a07ff29d
URL: https://github.com/libunwind/libunwind/tree/9cc4d98b22ae57bc1d8c253988feb85d4298a634

No NOTICE file found
LICENSE content:
Expand Down Expand Up @@ -159,3 +162,37 @@ Copyright notice:

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

Package name: magic_enum
Version: 0.9.6
Authors: Jean-loup Gailly <[email protected]> and Mark Adler <[email protected]>
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.

--------------------------------------------------------------------------------

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
1 change: 1 addition & 0 deletions docs/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>Supported features:<br>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.
| <option> | <default value> | <description> |
1 change: 1 addition & 0 deletions elastic-otel-php.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version=0.2.0
supported_php_versions=(80 81 82 83)
php_headers_version=2.0
logger_features_enum_values=ALL=0,MODULE=1,REQUEST=2,TRANSPORT=3,BOOTSTRAP=4,HOOKS=5,INSTRUMENTATION=6
1 change: 1 addition & 0 deletions prod/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ find_package(CURL 8.10.1 REQUIRED)
find_package(libunwind 1.8.1 REQUIRED)
find_package(Boost 1.86 REQUIRED CONFIG)
find_package(GTest 1.15.0 REQUIRED)
find_package(magic_enum 0.9.6 REQUIRED)

foreach(_php_version ${_supported_php_versions})
find_package(php-headers-${_php_version} ${_PROJECT_PROPERTIES_PHP_HEADERS_VERSION} REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(_ELASTIC_FAIL_ON_ERROR true)
set(_ELASTIC_WARN_ON_UNINITIALIZED true)


# determine build type and set
# determine build type and set
set(MUSL_BUILD false)

set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_NO_CYCLES ON) # https://cmake.org/cmake/help/latest/prop_gbl/GLOBAL_DEPENDS_NO_CYCLES.html
Expand All @@ -15,7 +15,7 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) # https://github.com/ComputationalRadiat
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_CXX_EXTENSIONS OFF) # https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html#prop_tgt:CXX_EXTENSIONS
set(CMAKE_CXX_STANDARD_REQUIRED ON) # https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD_REQUIRED.html#prop_tgt:CXX_STANDARD_REQUIRED
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
intuibase marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_INCLUDE_CURRENT_DIR ON) # https://cmake.org/cmake/help/latest/variable/CMAKE_INCLUDE_CURRENT_DIR.html

set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) # include runtime search path for shared libs
Expand All @@ -33,8 +33,8 @@ find_package(Threads REQUIRED)


# Keep output small as possible and manually control what we want to link with binaries
set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "")
set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "")

# Workaround to enable globally staticaly linked libgcc and libstdc++ - don't need to be enabled foreach target
# linking with libdl and libpthreads
Expand All @@ -45,7 +45,7 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-lib
add_compile_options("-pipe") # don't use temporary files but pipe data to linker

# Set up optimizations
if(RELEASE_BUILD)
if(RELEASE_BUILD)
add_compile_options("-O2"
"-g"
)
Expand Down Expand Up @@ -86,7 +86,7 @@ endif()
# C++ only switches
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-register>")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-fdiagnostics-show-template-tree>") # print template mismatch as tree - much more user friendly
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-fdiagnostics-show-template-tree>") # print template mismatch as tree - much more user friendly

# C only switches
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>")
1 change: 1 addition & 0 deletions prod/native/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[requires]
libcurl/8.10.1
libunwind/1.8.1
magic_enum/0.9.6
intuibase marked this conversation as resolved.
Show resolved Hide resolved
boost/1.86.0
gtest/1.15.0
php-headers-80/2.0
Expand Down
10 changes: 5 additions & 5 deletions prod/native/extension/code/Hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ void elastic_observer_error_cb(int type, zend_string *error_filename, uint32_t e
#endif
std::string_view msg = message && ZSTR_VAL(message) ? std::string_view{ZSTR_VAL(message), ZSTR_LEN(message)} : std::string_view{};

ELOG_DEBUG(ELASTICAPM_G(globals)->logger_, "elastic_observer_error_cb type: %d, fn: " PRsv ":%d, msg: " PRsv " ED: %p", type, PRsvArg(fileName), error_lineno, PRsvArg(msg), EG(current_execute_data));
ELOGF_DEBUG(ELASTICAPM_G(globals)->logger_, HOOKS, "elastic_observer_error_cb type: %d, fn: " PRsv ":%d, msg: " PRsv " ED: %p", type, PRsvArg(fileName), error_lineno, PRsvArg(msg), EG(current_execute_data));
static bool errorHandling = false;
if (errorHandling) {
ELOG_WARNING(ELASTICAPM_G(globals)->logger_, "elastic_observer_error_cb detected error handler loop, skipping error handler");
ELOGF_WARNING(ELASTICAPM_G(globals)->logger_, HOOKS, "elastic_observer_error_cb detected error handler loop, skipping error handler");
return;
}

Expand All @@ -61,16 +61,16 @@ void elastic_observer_error_cb(int type, zend_string *error_filename, uint32_t e
if (hash) {
if (ELASTICAPM_G(globals)->logger_ && ELASTICAPM_G(globals)->logger_->doesMeetsLevelCondition(LogLevel::logLevel_debug)) {
auto [cls, fun] = getClassAndFunctionName(EG(current_execute_data));
ELOG_DEBUG(ELASTICAPM_G(globals)->logger_, "elastic_observer_error_cb currentED: %p currentEXception: %p hash: 0x%X " PRsv "::" PRsv, EG(current_execute_data), EG(exception), hash, PRsvArg(cls), PRsvArg(fun));
ELOGF_DEBUG(ELASTICAPM_G(globals)->logger_, HOOKS, "elastic_observer_error_cb currentED: %p currentEXception: %p hash: 0x%X " PRsv "::" PRsv, EG(current_execute_data), EG(exception), hash, PRsvArg(cls), PRsvArg(fun));
}

auto callbacks = reinterpret_cast<InstrumentedFunctionHooksStorage_t *>(EAPM_GL(hooksStorage_).get())->find(hash);
if (callbacks) {
ELOG_DEBUG(ELASTICAPM_G(globals)->logger_, "elastic_observer_error_cb type: %d, fn: " PRsv ":%d, msg: " PRsv ". Skipping default error instrumentation because function is instrumented and error will be passed to posthook", type, PRsvArg(fileName), error_lineno, PRsvArg(msg));
ELOGF_DEBUG(ELASTICAPM_G(globals)->logger_, HOOKS, "elastic_observer_error_cb type: %d, fn: " PRsv ":%d, msg: " PRsv ". Skipping default error instrumentation because function is instrumented and error will be passed to posthook", type, PRsvArg(fileName), error_lineno, PRsvArg(msg));
return;
}
} else {
ELOG_WARNING(ELASTICAPM_G(globals)->logger_, "elastic_observer_error_cb currentED: %p currentEXception: %p func null, msg: " PRsv, EG(current_execute_data), EG(exception), PRsvArg(msg));
ELOGF_WARNING(ELASTICAPM_G(globals)->logger_, HOOKS, "elastic_observer_error_cb currentED: %p currentEXception: %p func null, msg: " PRsv, EG(current_execute_data), EG(exception), PRsvArg(msg));
}
}

Expand Down
Loading