From 3090ecf8796669928b7058ae782a286925642bd6 Mon Sep 17 00:00:00 2001 From: Alejandro Estringana Ruiz Date: Mon, 21 Oct 2024 16:49:24 +0200 Subject: [PATCH] Avoid reporting filesytem integration on telemetry --- ext/integrations/integrations.c | 9 +- ext/integrations/integrations.h | 3 +- tests/ext/telemetry/integration.phpt | 15 ++- .../ext/telemetry/integration_filesystem.phpt | 105 ++++++++++++++++++ 4 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 tests/ext/telemetry/integration_filesystem.phpt diff --git a/ext/integrations/integrations.c b/ext/integrations/integrations.c index 3ebb02a30cd..eaee9d0dd1d 100644 --- a/ext/integrations/integrations.c +++ b/ext/integrations/integrations.c @@ -7,6 +7,9 @@ #include #include #undef INTEGRATION +#undef INTEGRATION_CUSTOM_ENABLED + +static bool is_filesystem_enabled() { return get_DD_TRACE_FILESYSTEM_ENABLED() && get_DD_APPSEC_RASP_ENABLED(); } #define DDTRACE_DEFERRED_INTEGRATION_LOADER(class, fname, integration_name) \ dd_hook_method_and_unhook_on_first_call((zai_str)ZAI_STRL(class), (zai_str)ZAI_STRL(fname), \ @@ -24,13 +27,15 @@ dd_set_up_deferred_loading_by_method(name, (zai_str)ZAI_STR_EMPTY, (zai_str)ZAI_STRL(fname), \ (zai_str)ZAI_STRL(integration), false) -#define INTEGRATION(id, lcname, ...) \ +#define INTEGRATION(id, lcname, ...) INTEGRATION_AUX(id, lcname, get_DD_TRACE_##id##_ENABLED) +#define INTEGRATION_CUSTOM_ENABLED(id, lcname, is_enabled_func, ...) INTEGRATION_AUX(id, lcname, is_enabled_func) +#define INTEGRATION_AUX(id, lcname, is_enabled_func) \ { \ .name = DDTRACE_INTEGRATION_##id, \ .name_ucase = #id, \ .name_lcase = (lcname), \ .name_len = sizeof(lcname) - 1, \ - .is_enabled = get_DD_TRACE_##id##_ENABLED, \ + .is_enabled = is_enabled_func, \ .is_analytics_enabled = get_DD_TRACE_##id##_ANALYTICS_ENABLED, \ .get_sample_rate = get_DD_TRACE_##id##_ANALYTICS_SAMPLE_RATE, \ .aux = {0}, \ diff --git a/ext/integrations/integrations.h b/ext/integrations/integrations.h index 997a2be1eb5..6d66ce22bf4 100644 --- a/ext/integrations/integrations.h +++ b/ext/integrations/integrations.h @@ -20,7 +20,7 @@ INTEGRATION(DRUPAL, "drupal") \ INTEGRATION(ELASTICSEARCH, "elasticsearch") \ INTEGRATION(ELOQUENT, "eloquent") \ - INTEGRATION(FILESYSTEM, "filesystem") \ + INTEGRATION_CUSTOM_ENABLED(FILESYSTEM, "filesystem", is_filesystem_enabled) \ INTEGRATION(FRANKENPHP, "frankenphp") \ INTEGRATION(GOOGLESPANNER, "googlespanner") \ INTEGRATION(GUZZLE, "guzzle") \ @@ -54,6 +54,7 @@ INTEGRATION(ZENDFRAMEWORK, "zendframework") #define INTEGRATION(id, ...) DDTRACE_INTEGRATION_##id, +#define INTEGRATION_CUSTOM_ENABLED(id, ...) INTEGRATION(id) typedef enum { DD_INTEGRATIONS } ddtrace_integration_name; #undef INTEGRATION diff --git a/tests/ext/telemetry/integration.phpt b/tests/ext/telemetry/integration.phpt index 5c1672acd33..b95e114edf9 100644 --- a/tests/ext/telemetry/integration.phpt +++ b/tests/ext/telemetry/integration.phpt @@ -69,7 +69,7 @@ PUBLIC STATIC METHOD test_access hook array(1) { ["integrations"]=> - array(2) { + array(3) { [0]=> array(5) { ["name"]=> @@ -84,6 +84,19 @@ array(1) { NULL } [1]=> + array(5) { + ["name"]=> + string(10) "filesystem" + ["enabled"]=> + bool(false) + ["version"]=> + string(0) "" + ["compatible"]=> + NULL + ["auto_enabled"]=> + NULL + } + [2]=> array(5) { ["name"]=> string(4) "logs" diff --git a/tests/ext/telemetry/integration_filesystem.phpt b/tests/ext/telemetry/integration_filesystem.phpt new file mode 100644 index 00000000000..2c965a652f1 --- /dev/null +++ b/tests/ext/telemetry/integration_filesystem.phpt @@ -0,0 +1,105 @@ +--TEST-- +Filesystem integration depends on RASP. If RASP enabled, integration is enabled +--SKIPIF-- + +--ENV-- +DD_TRACE_GENERATE_ROOT_SPAN=0 +_DD_LOAD_TEST_INTEGRATIONS=1 +DD_INSTRUMENTATION_TELEMETRY_ENABLED=1 +DD_APPSEC_RASP_ENABLED=1 +--INI-- +datadog.trace.agent_url="file://{PWD}/integration-telemetry.out" +--FILE-- + +--EXPECT-- +PUBLIC STATIC METHOD +test_access hook +array(1) { + ["integrations"]=> + array(2) { + [0]=> + array(5) { + ["name"]=> + string(37) "ddtrace\test\testsandboxedintegration" + ["enabled"]=> + bool(true) + ["version"]=> + NULL + ["compatible"]=> + NULL + ["auto_enabled"]=> + NULL + } + [1]=> + array(5) { + ["name"]=> + string(4) "logs" + ["enabled"]=> + bool(false) + ["version"]=> + string(0) "" + ["compatible"]=> + NULL + ["auto_enabled"]=> + NULL + } + } +} +--CLEAN-- +