@@ -1316,6 +1316,87 @@ TRACER_CONFIG_TEST("configure 128-bit trace IDs") {
13161316 }
13171317}
13181318
1319+ #ifdef __linux__
1320+ TRACER_CONFIG_TEST (" TracerConfig::correlate_full_host_profiles" ) {
1321+ TracerConfig config;
1322+ config.service = " testsvc" ;
1323+ config.logger = std::make_shared<NullLogger>();
1324+
1325+ SECTION (" default is false" ) {
1326+ {
1327+ auto finalized = finalize_config (config);
1328+ REQUIRE (finalized);
1329+ Tracer tracer{*finalized};
1330+ auto span = tracer.create_span ();
1331+ }
1332+ REQUIRE (elastic_apm_profiling_correlation_process_storage_v1 == nullptr );
1333+ REQUIRE (elastic_apm_profiling_correlation_tls_v1 == nullptr );
1334+ }
1335+
1336+ SECTION (" true enables correlation" ) {
1337+ {
1338+ config.correlate_full_host_profiles = true ;
1339+ auto finalized = finalize_config (config);
1340+ REQUIRE (finalized);
1341+ Tracer tracer{*finalized};
1342+ auto span = tracer.create_span ();
1343+ REQUIRE (elastic_apm_profiling_correlation_tls_v1 != nullptr );
1344+ REQUIRE (elastic_apm_profiling_correlation_tls_v1->trace_present == 1 );
1345+ }
1346+ REQUIRE (elastic_apm_profiling_correlation_process_storage_v1 != nullptr );
1347+ REQUIRE (elastic_apm_profiling_correlation_tls_v1 != nullptr );
1348+ REQUIRE (elastic_apm_profiling_correlation_tls_v1->trace_present == 0 );
1349+ // reset for next tests
1350+ elastic_apm_profiling_correlation_process_storage_v1 = nullptr ;
1351+ elastic_apm_profiling_correlation_tls_v1 = nullptr ;
1352+ }
1353+
1354+ SECTION (" overridden by DD_TRACE_CORRELATE_FULL_HOST_PROFILES" ) {
1355+ struct TestCase {
1356+ std::string name;
1357+ std::string dd_trace_correlate_full_host_profiles;
1358+ bool original_value;
1359+ bool correlate;
1360+ };
1361+
1362+ auto test_case = GENERATE (values<TestCase>({
1363+ {" falsy override ('false')" , " false" , true , false },
1364+ {" falsy override ('0')" , " 0" , true , false },
1365+ {" falsy consistent ('false')" , " false" , false , false },
1366+ {" falsy consistent ('0')" , " 0" , false , false },
1367+ {" truthy override ('true')" , " true" , false , true },
1368+ {" truthy override ('1')" , " 1" , false , true },
1369+ {" truthy consistent ('true')" , " true" , true , true },
1370+ {" truthy consistent ('1')" , " 1" , true , true },
1371+ }));
1372+
1373+ CAPTURE (test_case.name );
1374+ const EnvGuard guard{" DD_TRACE_CORRELATE_FULL_HOST_PROFILES" ,
1375+ test_case.dd_trace_correlate_full_host_profiles };
1376+ config.report_traces = test_case.original_value ;
1377+ {
1378+ auto finalized = finalize_config (config);
1379+ REQUIRE (finalized);
1380+ Tracer tracer{*finalized};
1381+ auto span = tracer.create_span ();
1382+ if (test_case.correlate ) {
1383+ REQUIRE (elastic_apm_profiling_correlation_process_storage_v1 !=
1384+ nullptr );
1385+ REQUIRE (elastic_apm_profiling_correlation_tls_v1 != nullptr );
1386+ REQUIRE (elastic_apm_profiling_correlation_tls_v1->trace_present == 1 );
1387+ // reset for next tests
1388+ elastic_apm_profiling_correlation_process_storage_v1 = nullptr ;
1389+ elastic_apm_profiling_correlation_tls_v1 = nullptr ;
1390+ } else {
1391+ REQUIRE (elastic_apm_profiling_correlation_process_storage_v1 ==
1392+ nullptr );
1393+ REQUIRE (elastic_apm_profiling_correlation_tls_v1 == nullptr );
1394+ }
1395+ }
1396+ }
1397+ }
1398+ #endif
1399+
13191400TRACER_CONFIG_TEST (" baggage" ) {
13201401 TracerConfig config;
13211402
0 commit comments