Skip to content

Commit 2156c28

Browse files
authored
Vendor customization interface (#19)
* Vendor customizations interface * Change ARM64 runner
1 parent fdd33c5 commit 2156c28

20 files changed

+353
-132
lines changed

.github/workflows/build-native.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
build-native:
3434
name: build-agent-library
35-
runs-on: ${{ matrix.goarch == 'arm64' && 'oracle-4cpu-16gb-arm64' || 'ubuntu-latest' }}
35+
runs-on: ${{ matrix.goarch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
3636
needs: setup-build-matrix
3737
timeout-minutes: 300
3838
strategy:

.github/workflows/native-dev-tools-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
build_arch: ${{ inputs.build_arch }}
3333

3434
build-compiler-image:
35-
runs-on: ${{ matrix.goarch == 'arm64' && 'oracle-4cpu-16gb-arm64' || 'ubuntu-latest' }}
35+
runs-on: ${{ matrix.goarch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
3636
needs: setup-build-matrix
3737
env:
3838
DOCKER_BUILDKIT: 1

prod/native/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ project("opentelemetry-php-distro"
3939
LANGUAGES C CXX
4040
)
4141

42+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
43+
4244
set(RELEASE_BUILD false)
4345
set(DEBUG_BUILD false)
4446
if(CMAKE_BUILD_TYPE STREQUAL "Release")

prod/native/extension/code/ModuleEntry.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include "AutoZval.h"
1414
#include "os/OsUtils.h"
15+
#include "config/OptionValueProvider.h"
16+
1517
#include "CallOnScopeExit.h"
1618
#include "ConfigurationManager.h"
1719
#include "InferredSpans.h"
@@ -29,20 +31,6 @@
2931

3032
ZEND_DECLARE_MODULE_GLOBALS( opentelemetry_distro )
3133

32-
namespace opentelemetry::php {
33-
opentelemetry::php::ConfigurationManager configManager([](std::string_view iniName) -> std::optional<std::string> {
34-
auto val = cfg_get_entry(iniName.data(), iniName.length());
35-
36-
opentelemetry::php::AutoZval autoZval(val);
37-
auto optStringView = autoZval.getOptStringView();
38-
if (!optStringView.has_value()) {
39-
return std::nullopt;
40-
}
41-
42-
return std::string(*optStringView);
43-
});
44-
}
45-
4634
#ifndef ZEND_PARSE_PARAMETERS_NONE
4735
# define ZEND_PARSE_PARAMETERS_NONE() \
4836
ZEND_PARSE_PARAMETERS_START(0, 0) \
@@ -65,7 +53,7 @@ ZEND_RESULT_CODE opentelemetry_distro_request_postdeactivate(void) {
6553
}
6654

6755
PHP_MINFO_FUNCTION(opentelemetry_distro) {
68-
printPhpInfo(zend_module);
56+
opentelemetry::php::printPhpInfo(zend_module);
6957
}
7058

7159

@@ -79,8 +67,6 @@ static PHP_GINIT_FUNCTION(opentelemetry_distro) {
7967

8068
auto logger = std::make_shared<opentelemetry::php::Logger>(std::vector<std::shared_ptr<opentelemetry::php::LoggerSinkInterface>>{logSinkStdErr, logSinkSysLog, logSinkFile});
8169

82-
opentelemetry::php::configManager.attachLogger(logger);
83-
8470
ELOGF_DEBUG(logger, MODULE, "%s: GINIT called; parent PID: %d", __FUNCTION__, static_cast<int>(opentelemetry::osutils::getParentProcessId()));
8571
opentelemetry_distro_globals->globals = nullptr;
8672

@@ -99,7 +85,19 @@ static PHP_GINIT_FUNCTION(opentelemetry_distro) {
9985
});
10086

10187
try {
102-
opentelemetry_distro_globals->globals = new opentelemetry::php::AgentGlobals(logger, std::move(logSinkStdErr), std::move(logSinkSysLog), std::move(logSinkFile), std::move(phpBridge), std::move(hooksStorage), std::move(inferredSpans), [](opentelemetry::php::ConfigurationSnapshot &cfg) { return opentelemetry::php::configManager.updateIfChanged(cfg); });
88+
auto optionValueProvider = std::make_shared<opentelemetry::php::config::OptionValueProvider>([](std::string_view iniName) -> std::optional<std::string> {
89+
auto val = cfg_get_entry(iniName.data(), iniName.length());
90+
91+
opentelemetry::php::AutoZval autoZval(val);
92+
auto optStringView = autoZval.getOptStringView();
93+
if (!optStringView.has_value()) {
94+
return std::nullopt;
95+
}
96+
97+
return std::string(*optStringView);
98+
});
99+
100+
opentelemetry_distro_globals->globals = new opentelemetry::php::AgentGlobals(logger, std::move(logSinkStdErr), std::move(logSinkSysLog), std::move(logSinkFile), std::move(phpBridge), std::move(hooksStorage), std::move(inferredSpans), std::move(optionValueProvider));
103101
} catch (std::exception const &e) {
104102
ELOGF_CRITICAL(logger, MODULE, "Unable to allocate AgentGlobals. '%s'", e.what());
105103
}

prod/native/extension/code/ModuleFunctions.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11

22
#include "ModuleFunctions.h"
3-
#include "ConfigurationStorage.h"
43
#include "LoggerInterface.h"
54
#include "LogFeature.h"
6-
#include "RequestScope.h"
75
#include "ModuleGlobals.h"
86
#include "ModuleFunctionsImpl.h"
97
#include "InternalFunctionInstrumentation.h"
108
#undef snprintf
119
#include "coordinator/CoordinatorProcess.h"
12-
#include "transport/OpAmp.h"
1310
#include "PhpBridge.h"
1411
#include "OtlpExporter/LogsConverter.h"
1512
#include "OtlpExporter/MetricConverter.h"
@@ -226,7 +223,7 @@ PHP_FUNCTION(initialize) {
226223
OTEL_GL(coordinatorProcess_)->getCoordinatorSender().initializeConnection(std::string(ZSTR_VAL(endpoint), ZSTR_LEN(endpoint)), ZSTR_HASH(endpoint), std::string(ZSTR_VAL(contentType), ZSTR_LEN(contentType)), endpointHeaders, std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>(timeout)), static_cast<std::size_t>(maxRetries), std::chrono::milliseconds(retryDelay), sslOptions);
227224
}
228225

229-
ZEND_BEGIN_ARG_INFO_EX(ArgInfoSend, 0, 0, 2)
226+
ZEND_BEGIN_ARG_INFO_EX(enqueue_arginfo, 0, 0, 2)
230227
ZEND_ARG_TYPE_INFO(0, endpoint, IS_STRING, 1)
231228
ZEND_ARG_TYPE_INFO(0, payload, IS_STRING, 1)
232229
ZEND_END_ARG_INFO()
@@ -376,7 +373,7 @@ const zend_function_entry opentelemetry_distro_functions[] = {
376373
ZEND_NS_FE( "OpenTelemetry\\Distro", hook, hook_arginfo)
377374

378375
ZEND_NS_FE( "OpenTelemetry\\Distro\\HttpTransport", initialize, ArgInfoInitialize)
379-
ZEND_NS_FE( "OpenTelemetry\\Distro\\HttpTransport", enqueue, no_params_arginfo)
376+
ZEND_NS_FE( "OpenTelemetry\\Distro\\HttpTransport", enqueue, enqueue_arginfo)
380377
ZEND_NS_FE( "OpenTelemetry\\Distro\\InferredSpans", force_set_object_property_value, set_object_property_value_arginfo)
381378

382379
ZEND_NS_FE( "OpenTelemetry\\Distro\\OtlpExporters", convert_spans, arginfo_convert_spans)

prod/native/extension/code/ModuleFunctionsImpl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
#include "ModuleGlobals.h"
77

88
namespace opentelemetry::php {
9-
extern opentelemetry::php::ConfigurationManager configManager;
109

1110
void getConfigOptionbyName(std::string_view optionName, zval *return_value) {
12-
auto value = opentelemetry::php::configManager.getOptionValue(optionName, OTEL_GL(config_)->get());
11+
auto value = OTEL_GL(configManager_)->getOptionValue(optionName, OTEL_GL(config_)->get());
1312

1413
std::visit([return_value](auto &&arg) {
1514
using T = std::decay_t<decltype(arg)>;
@@ -38,4 +37,4 @@ void getConfigOptionbyName(std::string_view optionName, zval *return_value) {
3837
}, value);
3938
}
4039

41-
}
40+
} // namespace opentelemetry::php

prod/native/extension/code/ModuleInfo.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,33 @@
22
#include "ConfigurationManager.h"
33
#include "ConfigurationStorage.h"
44
#include "ModuleGlobals.h"
5+
#include "VendorCustomizationsInterface.h"
56

67
#include <php.h>
78
#include <ext/standard/info.h>
89

910
#include "otel_distro_version.h"
1011

1112
namespace opentelemetry::php {
12-
extern opentelemetry::php::ConfigurationManager configManager;
13-
}
1413

1514
void printPhpInfo(zend_module_entry *zend_module) {
1615

17-
1816
php_info_print_table_start();
19-
php_info_print_table_header( 1, OTEL_DISTRO_PRODUCT_NAME);
20-
php_info_print_table_end();
17+
if (OTEL_G(globals)->vendorCustomizations_) {
18+
php_info_print_table_header(1, OTEL_G(globals)->vendorCustomizations_->getDistributionName().c_str());
19+
php_info_print_table_row(2, "Version", OTEL_G(globals)->vendorCustomizations_->getDistributionVersion().c_str());
20+
php_info_print_table_row(2, "OpenTelemetry distro base version", OTEL_DISTRO_VERSION);
21+
22+
} else {
23+
php_info_print_table_header(1, OTEL_DISTRO_PRODUCT_NAME);
24+
php_info_print_table_row(2, "Version", OTEL_DISTRO_VERSION);
25+
}
2126

2227
php_info_print_table_colspan_header(2, "Effective configuration");
2328
php_info_print_table_start();
2429
php_info_print_table_header(2, "Configuration option", "Value");
2530

26-
auto const &options = opentelemetry::php::configManager.getOptionMetadata();
31+
auto const &options = OTEL_G(globals)->configManager_->getOptionMetadata();
2732
for (auto const &option : options) {
2833
auto value = opentelemetry::php::ConfigurationManager::accessOptionStringValueByMetadata(option.second, OTEL_GL(config_)->get());
2934
php_info_print_table_row(2, option.first.c_str(), option.second.secret ? "***" : value.c_str());
@@ -32,4 +37,6 @@ void printPhpInfo(zend_module_entry *zend_module) {
3237

3338
php_info_print_table_colspan_header(2, "INI configuration");
3439
display_ini_entries(zend_module);
35-
}
40+
}
41+
42+
} // namespace opentelemetry::php
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
#pragma once
12

23
#include <Zend/zend_modules.h>
34

4-
void printPhpInfo(zend_module_entry *zend_module);
5+
namespace opentelemetry::php {
6+
7+
void printPhpInfo(zend_module_entry *zend_module);
8+
9+
}

prod/native/extension/code/ModuleIniEntries.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#include "ModuleIniEntries.h"
3+
#include "ModuleGlobals.h"
34
#include "ConfigurationManager.h"
45
#include "ConfigurationSnapshot.h"
56
#include "CommonUtils.h"
@@ -42,8 +43,6 @@ OTEL_INI_ENTRY(STRINGIFY_HELPER(OTEL_PHP_INFERRED_SPANS_MIN_DURATION))
4243
PHP_INI_END()
4344

4445
namespace opentelemetry::php {
45-
extern opentelemetry::php::ConfigurationManager configManager;
46-
4746

4847
constexpr const zend_string *iniEntryValue(zend_ini_entry *iniEntry, int type) {
4948
return (type == ZEND_INI_DISPLAY_ORIG) ? (iniEntry->modified ? iniEntry->orig_value : iniEntry->value) : iniEntry->value;
@@ -62,7 +61,7 @@ bool registerIniEntries(opentelemetry::php::LoggerInterface *log, int module_num
6261
}
6362

6463
// register custom displayer for secret options
65-
auto options = configManager.getOptionMetadata();
64+
auto options = OTEL_G(globals)->configManager_->getOptionMetadata();
6665
for (auto const &option : options) {
6766
if (!option.second.secret) {
6867
continue;
@@ -78,4 +77,4 @@ bool registerIniEntries(opentelemetry::php::LoggerInterface *log, int module_num
7877
return true;
7978
}
8079

81-
}
80+
} // namespace opentelemetry::php

prod/native/extension/code/ModuleInit.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
#include "Hooking.h"
1111
#include "InternalFunctionInstrumentation.h"
1212
#include "ModuleIniEntries.h"
13-
#include "ModuleFunctions.h"
1413
#include "ModuleGlobals.h"
15-
#include "PeriodicTaskExecutor.h"
16-
#include "RequestScope.h"
1714
#include "SigSegvHandler.h"
1815
#include "os/OsUtils.h"
19-
#include "transport/OpAmp.h"
2016
#include "coordinator/CoordinatorProcess.h"
17+
#include "VendorCustomizationsInterface.h"
2118

2219
#include <curl/curl.h>
2320
#include <inttypes.h> // PRIu64
@@ -31,15 +28,20 @@
3128

3229
namespace opentelemetry::php {
3330

34-
extern ConfigurationManager configManager;
35-
3631
void logStartupPreamble(opentelemetry::php::LoggerInterface *logger) {
3732
constexpr LogLevel level = LogLevel::logLevel_debug;
3833
constexpr int colWidth = 40;
3934

4035
using namespace std::literals;
41-
ELOGF_NF(logger, level, OTEL_DISTRO_PRODUCT_NAME);
42-
ELOGF_NF(logger, level, "%*s%s", -colWidth, "Native part version:", OTEL_DISTRO_VERSION);
36+
37+
if (OTEL_G(globals)->vendorCustomizations_) {
38+
ELOG_NF(logger, level, "{} version: {}", OTEL_G(globals)->vendorCustomizations_->getDistributionName(), OTEL_G(globals)->vendorCustomizations_->getDistributionVersion());
39+
ELOG_NF(logger, level, "{:<{}}{}", "OpenTelemetry distro base version:", colWidth, OTEL_DISTRO_VERSION);
40+
} else {
41+
ELOG_NF(logger, level, OTEL_DISTRO_PRODUCT_NAME);
42+
ELOGF_NF(logger, level, "%*s%s", -colWidth, "Native part version:", OTEL_DISTRO_VERSION);
43+
}
44+
4345
ELOGF_NF(logger, level, "%*s%s", -colWidth, "Process command line:", opentelemetry::utils::sanitizeKeyValueString("OTEL_EXPORTER_OTLP_HEADERS", opentelemetry::osutils::getCommandLine()).c_str());
4446
ELOGF_NF(logger, level, "%*s%s", -colWidth, "Process environment:", opentelemetry::utils::sanitizeKeyValueString("OTEL_EXPORTER_OTLP_HEADERS", opentelemetry::osutils::getProcessEnvironment()).c_str());
4547
}
@@ -49,7 +51,7 @@ void moduleInit(int moduleType, int moduleNumber) {
4951
auto globals = OTEL_G(globals);
5052

5153
opentelemetry::php::registerIniEntries(OTEL_GL(logger_).get(), moduleNumber);
52-
configManager.update();
54+
globals->configManager_->update();
5355
globals->config_->update();
5456

5557
ELOGF_DEBUG(globals->logger_, MODULE, "%s entered: moduleType: %d, moduleNumber: %d, parent PID: %d, SAPI: %s (%d) is %s", __FUNCTION__, moduleType, moduleNumber, static_cast<int>(opentelemetry::osutils::getParentProcessId()), sapi.getName().data(), static_cast<uint8_t>(sapi.getType()), sapi.isSupported() ? "supported" : "unsupported");
@@ -79,7 +81,7 @@ void moduleInit(int moduleType, int moduleNumber) {
7981
// add config update watcher in worker process
8082
globals->coordinatorConfigProvider_->addConfigUpdateWatcher([globals](opentelemetry::php::coordinator::CoordinatorConfigurationProvider::configFiles_t const &cfgFiles) {
8183
ELOG_DEBUG(globals->logger_, COORDINATOR, "Received config update with {} files. Updating dynamic config and global config storage", cfgFiles.size());
82-
configManager.update(cfgFiles);
84+
globals->configManager_->update(cfgFiles);
8385
});
8486

8587
globals->coordinatorConfigProvider_->triggerUpdateIfChanged();
@@ -123,4 +125,4 @@ void moduleShutdown( int moduleType, int moduleNumber ) {
123125
unregisterSigSegvHandler();
124126
}
125127

126-
}
128+
} // namespace opentelemetry::php

0 commit comments

Comments
 (0)