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