-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathConfiguration.cpp
777 lines (647 loc) · 22.2 KB
/
Configuration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc.
#include "Configuration.h"
#include "TagsHelper.h"
#include <type_traits>
#include "EnvironmentVariables.h"
#include "OpSysTools.h"
#include "shared/src/native-src/dd_filesystem.hpp"
// namespace fs is an alias defined in "dd_filesystem.hpp"
#include "shared/src/native-src/string.h"
#include "shared/src/native-src/util.h"
std::string const Configuration::DefaultDevSite = "datad0g.com";
std::string const Configuration::DefaultProdSite = "datadoghq.com";
std::string const Configuration::DefaultVersion = "Unspecified-Version";
std::string const Configuration::DefaultEnvironment = "Unspecified-Environment";
std::string const Configuration::DefaultAgentHost = "localhost";
int32_t const Configuration::DefaultAgentPort = 8126;
std::string const Configuration::DefaultEmptyString = "";
std::chrono::seconds const Configuration::DefaultDevUploadInterval = 20s;
std::chrono::seconds const Configuration::DefaultProdUploadInterval = 60s;
std::chrono::milliseconds const Configuration::DefaultCpuProfilingInterval = 9ms;
Configuration::Configuration()
{
_debugLogEnabled = GetEnvironmentValue(EnvironmentVariables::DebugLogEnabled, GetDefaultDebugLogEnabled());
_logDirectory = ExtractLogDirectory();
_pprofDirectory = ExtractPprofDirectory();
_isOperationalMetricsEnabled = GetEnvironmentValue(EnvironmentVariables::OperationalMetricsEnabled, false);
_isNativeFrameEnabled = GetEnvironmentValue(EnvironmentVariables::NativeFramesEnabled, false);
_isCpuProfilingEnabled = GetEnvironmentValue(EnvironmentVariables::CpuProfilingEnabled, true);
_isWallTimeProfilingEnabled = GetEnvironmentValue(EnvironmentVariables::WallTimeProfilingEnabled, true);
_isExceptionProfilingEnabled = GetEnvironmentValue(EnvironmentVariables::ExceptionProfilingEnabled, true);
_isAllocationProfilingEnabled = GetEnvironmentValue(EnvironmentVariables::AllocationProfilingEnabled, false);
_isContentionProfilingEnabled = GetContention();
_isGarbageCollectionProfilingEnabled = GetEnvironmentValue(EnvironmentVariables::GCProfilingEnabled, true);
_isHeapProfilingEnabled = GetEnvironmentValue(EnvironmentVariables::HeapProfilingEnabled, false);
_uploadPeriod = ExtractUploadInterval();
_userTags = ExtractUserTags();
_version = GetEnvironmentValue(EnvironmentVariables::Version, DefaultVersion);
_environmentName = GetEnvironmentValue(EnvironmentVariables::Environment, DefaultEnvironment);
_hostname = GetEnvironmentValue(EnvironmentVariables::Hostname, OpSysTools::GetHostname());
_agentUrl = GetEnvironmentValue(EnvironmentVariables::AgentUrl, DefaultEmptyString);
_agentHost = GetEnvironmentValue(EnvironmentVariables::AgentHost, DefaultAgentHost);
_agentPort = GetEnvironmentValue(EnvironmentVariables::AgentPort, DefaultAgentPort);
_site = ExtractSite();
_apiKey = GetEnvironmentValue(EnvironmentVariables::ApiKey, DefaultEmptyString);
_serviceName = GetEnvironmentValue(EnvironmentVariables::ServiceName, OpSysTools::GetProcessName());
_isAgentLess = GetEnvironmentValue(EnvironmentVariables::Agentless, false);
_exceptionSampleLimit = GetEnvironmentValue(EnvironmentVariables::ExceptionSampleLimit, 500);
_allocationSampleLimit = GetEnvironmentValue(EnvironmentVariables::AllocationSampleLimit, 2000);
_contentionSampleLimit = GetEnvironmentValue(EnvironmentVariables::ContentionSampleLimit, 3000);
_contentionDurationThreshold = GetEnvironmentValue(EnvironmentVariables::ContentionDurationThreshold, 100);
_cpuWallTimeSamplingRate = ExtractCpuWallTimeSamplingRate();
_walltimeThreadsThreshold = ExtractWallTimeThreadsThreshold();
_cpuThreadsThreshold = ExtractCpuThreadsThreshold();
_codeHotspotsThreadsThreshold = ExtractCodeHotspotsThreadsThreshold();
_minimumCores = GetEnvironmentValue<double>(EnvironmentVariables::CoreMinimumOverride, 1.0);
_namedPipeName = GetEnvironmentValue(EnvironmentVariables::NamedPipeName, DefaultEmptyString);
_isTimestampsAsLabelEnabled = GetEnvironmentValue(EnvironmentVariables::TimestampsAsLabelEnabled, true);
_useBacktrace2 = GetEnvironmentValue(EnvironmentVariables::UseBacktrace2, true);
_isAllocationRecorderEnabled = GetEnvironmentValue(EnvironmentVariables::AllocationRecorderEnabled, false);
_isDebugInfoEnabled = GetEnvironmentValue(EnvironmentVariables::DebugInfoEnabled, false);
_isGcThreadsCpuTimeEnabled = GetEnvironmentValue(EnvironmentVariables::GcThreadsCpuTimeEnabled, false);
_isThreadLifetimeEnabled = GetEnvironmentValue(EnvironmentVariables::ThreadLifetimeEnabled, false);
_gitRepositoryUrl = GetEnvironmentValue(EnvironmentVariables::GitRepositoryUrl, DefaultEmptyString);
_gitCommitSha = GetEnvironmentValue(EnvironmentVariables::GitCommitSha, DefaultEmptyString);
_isInternalMetricsEnabled = GetEnvironmentValue(EnvironmentVariables::InternalMetricsEnabled, false);
_isSystemCallsShieldEnabled = GetEnvironmentValue(EnvironmentVariables::SystemCallsShieldEnabled, true);
// Check CI Visibility mode
_isCIVisibilityEnabled = GetEnvironmentValue(EnvironmentVariables::CIVisibilityEnabled, false);
_internalCIVisibilitySpanId = uint64_t{0};
_cpuProfilingInterval = ExtractCpuProfilingInterval();
if (_isCIVisibilityEnabled)
{
// We cannot write 0ull instead of std::uint64_t{0} because on Windows, compiling in x64, std::uint64_t == unsigned long long.
// But on Linux, it's std::uint64_t == unsigned long (=> 0ul)and it fails to compile.
// Here we create a 0 value of type std::uint64_t which will succeed the compilation
_internalCIVisibilitySpanId = GetEnvironmentValue(EnvironmentVariables::InternalCIVisibilitySpanId, uint64_t{0});
// If we detect CI Visibility we allow to reduce the minimum ms in sampling rate down to 1ms.
_cpuWallTimeSamplingRate = ExtractCpuWallTimeSamplingRate(1);
// for timer_create based profiling
_cpuProfilingInterval = ExtractCpuProfilingInterval(1ms);
}
_isEtwEnabled = GetEnvironmentValue(EnvironmentVariables::EtwEnabled, true);
_deploymentMode = GetEnvironmentValue(EnvironmentVariables::SsiDeployed, DeploymentMode::Manual);
_isEtwLoggingEnabled = GetEnvironmentValue(EnvironmentVariables::EtwLoggingEnabled, false);
_etwReplayEndpoint = GetEnvironmentValue(EnvironmentVariables::EtwReplayEndpoint, DefaultEmptyString);
_enablementStatus = ExtractEnablementStatus();
_ssiLongLivedThreshold = ExtractSsiLongLivedThreshold();
_isTelemetryToDiskEnabled = GetEnvironmentValue(EnvironmentVariables::TelemetryToDiskEnabled, false);
_isSsiTelemetryEnabled = GetEnvironmentValue(EnvironmentVariables::SsiTelemetryEnabled, false);
_isHttpProfilingEnabled = GetEnvironmentValue(EnvironmentVariables::HttpProfilingEnabled, false);
_httpRequestDurationThreshold = ExtractHttpRequestDurationThreshold();
_forceHttpSampling = GetEnvironmentValue(EnvironmentVariables::ForceHttpSampling, false);
_cpuProfilerType = GetEnvironmentValue(EnvironmentVariables::CpuProfilerType, CpuProfilerType::ManualCpuTime);
}
fs::path Configuration::ExtractLogDirectory()
{
auto value = shared::GetEnvironmentValue(EnvironmentVariables::LogDirectory);
if (value.empty())
return GetDefaultLogDirectoryPath();
return fs::path(value);
}
fs::path const& Configuration::GetLogDirectory() const
{
return _logDirectory;
}
fs::path Configuration::ExtractPprofDirectory()
{
auto value = shared::GetEnvironmentValue(EnvironmentVariables::ProfilesOutputDir);
if (value.empty())
return fs::path();
return fs::path(value);
}
fs::path const& Configuration::GetProfilesOutputDirectory() const
{
return _pprofDirectory;
}
bool Configuration::IsOperationalMetricsEnabled() const
{
return _isOperationalMetricsEnabled;
}
bool Configuration::IsNativeFramesEnabled() const
{
return _isNativeFrameEnabled;
}
bool Configuration::IsCpuProfilingEnabled() const
{
return _isCpuProfilingEnabled;
}
bool Configuration::IsWallTimeProfilingEnabled() const
{
return _isWallTimeProfilingEnabled;
}
bool Configuration::IsExceptionProfilingEnabled() const
{
return _isExceptionProfilingEnabled;
}
int32_t Configuration::ExceptionSampleLimit() const
{
return _exceptionSampleLimit;
}
bool Configuration::IsAllocationProfilingEnabled() const
{
return _isAllocationProfilingEnabled;
}
int32_t Configuration::AllocationSampleLimit() const
{
return _allocationSampleLimit;
}
bool Configuration::IsContentionProfilingEnabled() const
{
return _isContentionProfilingEnabled;
}
bool Configuration::IsGarbageCollectionProfilingEnabled() const
{
return _isGarbageCollectionProfilingEnabled;
}
bool Configuration::IsGcThreadsCpuTimeEnabled() const
{
return _isGcThreadsCpuTimeEnabled;
}
bool Configuration::IsHeapProfilingEnabled() const
{
return _isHeapProfilingEnabled;
}
bool Configuration::IsThreadLifetimeEnabled() const
{
return _isThreadLifetimeEnabled;
}
int32_t Configuration::ContentionSampleLimit() const
{
return _contentionSampleLimit;
}
int32_t Configuration::ContentionDurationThreshold() const
{
return _contentionDurationThreshold;
}
std::chrono::nanoseconds Configuration::CpuWallTimeSamplingRate() const
{
return _cpuWallTimeSamplingRate;
}
int32_t Configuration::WalltimeThreadsThreshold() const
{
return _walltimeThreadsThreshold;
}
int32_t Configuration::CpuThreadsThreshold() const
{
return _cpuThreadsThreshold;
}
int32_t Configuration::CodeHotspotsThreadsThreshold() const
{
return _codeHotspotsThreadsThreshold;
}
double Configuration::MinimumCores() const
{
return _minimumCores;
}
std::chrono::seconds Configuration::GetUploadInterval() const
{
return _uploadPeriod;
}
tags const& Configuration::GetUserTags() const
{
return _userTags;
}
bool Configuration::IsDebugLogEnabled() const
{
return _debugLogEnabled;
}
std::string const& Configuration::GetVersion() const
{
return _version;
}
std::string const& Configuration::GetEnvironment() const
{
return _environmentName;
}
std::string const& Configuration::GetHostname() const
{
return _hostname;
}
std::string const& Configuration::GetAgentUrl() const
{
return _agentUrl;
}
std::string const& Configuration::GetAgentHost() const
{
return _agentHost;
}
int32_t Configuration::GetAgentPort() const
{
return _agentPort;
}
std::string const& Configuration::GetSite() const
{
return _site;
}
std::string const& Configuration::GetApiKey() const
{
return _apiKey;
}
std::string const& Configuration::GetServiceName() const
{
return _serviceName;
}
bool Configuration::UseBacktrace2() const
{
return _useBacktrace2;
}
bool Configuration::IsAllocationRecorderEnabled() const
{
return _isAllocationRecorderEnabled;
}
bool Configuration::IsInternalMetricsEnabled() const
{
return _isInternalMetricsEnabled;
}
bool Configuration::IsCIVisibilityEnabled() const
{
return _isCIVisibilityEnabled;
}
std::uint64_t Configuration::GetCIVisibilitySpanId() const
{
return _internalCIVisibilitySpanId;
}
fs::path Configuration::GetApmBaseDirectory()
{
#ifdef _WINDOWS
WCHAR output[MAX_PATH] = {0};
auto result = ExpandEnvironmentStrings(WStr("%PROGRAMDATA%"), output, MAX_PATH);
if (result != 0)
{
return fs::path(output);
}
return fs::path();
#else
return fs::path(WStr("/var/log/datadog/"));
#endif
}
fs::path Configuration::GetDefaultLogDirectoryPath()
{
auto baseDirectory = fs::path(GetApmBaseDirectory());
#ifdef _WINDOWS
return baseDirectory / WStr(R"(Datadog .NET Tracer\logs)");
#else
return baseDirectory / WStr("dotnet");
#endif
}
tags Configuration::ExtractUserTags()
{
return TagsHelper::Parse(shared::ToString(shared::GetEnvironmentValue(EnvironmentVariables::Tags)));
}
std::string Configuration::GetDefaultSite()
{
auto isDev = GetEnvironmentValue(EnvironmentVariables::DevelopmentConfiguration, false);
if (isDev)
{
return DefaultDevSite;
}
return DefaultProdSite;
}
std::string Configuration::ExtractSite()
{
auto r = shared::GetEnvironmentValue(EnvironmentVariables::Site);
if (r.empty())
return GetDefaultSite();
return shared::ToString(r);
}
std::chrono::seconds Configuration::GetDefaultUploadInterval()
{
auto r = shared::GetEnvironmentValue(EnvironmentVariables::DevelopmentConfiguration);
bool isDev;
if (shared::TryParseBooleanEnvironmentValue(r, isDev) && isDev)
return DefaultDevUploadInterval;
return DefaultProdUploadInterval;
}
const std::string& Configuration::GetNamedPipeName() const
{
return _namedPipeName;
}
bool Configuration::IsTimestampsAsLabelEnabled() const
{
return _isTimestampsAsLabelEnabled;
}
std::string const& Configuration::GetGitRepositoryUrl() const
{
return _gitRepositoryUrl;
}
std::string const& Configuration::GetGitCommitSha() const
{
return _gitCommitSha;
}
//
// shared::TryParse does not work on Linux
// not found the issue yet.
// For now, replace shared::TryParse by this function
// TODO Once in the Tracer repo:
// - replace shared::TryParse by this implementation
// - add tests
static bool TryParse(shared::WSTRING const& s, int32_t& result)
{
auto r = shared::Trim(s);
if (r.empty())
{
result = 0;
return false;
}
try
{
result = std::stoi(shared::ToString(r));
return true;
}
catch (std::exception const&)
{
// TODO log
}
result = 0;
return false;
}
static bool TryParse(shared::WSTRING const& s, uint64_t& result)
{
auto r = shared::Trim(s);
if (r.empty())
{
result = 0;
return false;
}
try
{
auto str = shared::ToString(r);
result = std::stoull(str);
return true;
}
catch (std::exception const&)
{
// TODO log
}
result = 0;
return false;
}
std::chrono::seconds Configuration::ExtractUploadInterval()
{
auto r = shared::GetEnvironmentValue(EnvironmentVariables::UploadInterval);
int32_t interval;
if (TryParse(r, interval))
{
return std::chrono::seconds(interval);
}
return GetDefaultUploadInterval();
}
std::chrono::milliseconds Configuration::ExtractCpuProfilingInterval(std::chrono::milliseconds minimum)
{
// For normal path (no CI-visibility), 9ms is the default and lowest value we can have
// for CI-Visibility we allow it to be less
auto interval = GetEnvironmentValue(EnvironmentVariables::CpuProfilingInterval, DefaultCpuProfilingInterval);
return std::max(interval, minimum);
}
std::chrono::nanoseconds Configuration::ExtractCpuWallTimeSamplingRate(int minimum)
{
// default sampling rate is 9 ms; could be changed via env vars but down to a minimum of 5 ms
int64_t rate = std::max(GetEnvironmentValue(EnvironmentVariables::CpuWallTimeSamplingRate, 9), minimum);
rate *= 1000000;
return std::chrono::nanoseconds(rate);
}
int32_t Configuration::ExtractWallTimeThreadsThreshold()
{
// default threads to sample for wall time is 5; could be changed via env vars from 5 to 64
int32_t threshold =
std::min(
std::max(GetEnvironmentValue(EnvironmentVariables::WalltimeThreadsThreshold, 5), 5),
64);
return threshold;
}
int32_t Configuration::ExtractCodeHotspotsThreadsThreshold()
{
// default threads to sample for codehotspots is 10; could be changed via env vars but down to 1ms
int32_t threshold = std::max(GetEnvironmentValue(EnvironmentVariables::CodeHotspotsThreadsThreshold, 10), 1);
return threshold;
}
int32_t Configuration::ExtractCpuThreadsThreshold()
{
// default threads to sample for CPU profiling is 64; could be changed via env vars from 5 to 128
int32_t threshold =
std::min(
std::max(GetEnvironmentValue(EnvironmentVariables::CpuTimeThreadsThreshold, 64), 5),
128);
return threshold;
}
bool Configuration::GetContention()
{
// enabled by default
bool lockContentionEnabled = true;
// first look at the supported env var
if (IsEnvironmentValueSet(EnvironmentVariables::LockContentionProfilingEnabled, lockContentionEnabled))
{
return lockContentionEnabled;
}
// if not there, look at the deprecated one
return GetEnvironmentValue(EnvironmentVariables::DeprecatedContentionProfilingEnabled, lockContentionEnabled);
}
bool Configuration::GetDefaultDebugLogEnabled()
{
auto r = shared::GetEnvironmentValue(EnvironmentVariables::DevelopmentConfiguration);
bool isDev;
return shared::TryParseBooleanEnvironmentValue(r, isDev) && isDev;
}
bool Configuration::IsAgentless() const
{
return _isAgentLess;
}
bool Configuration::IsDebugInfoEnabled() const
{
return _isDebugInfoEnabled;
}
bool Configuration::IsSystemCallsShieldEnabled() const
{
#ifdef LINUX
return _isSystemCallsShieldEnabled;
#else
return false;
#endif
}
bool Configuration::IsEtwEnabled() const
{
#ifdef LINUX
return false;
#else
return _isEtwEnabled;
#endif
}
bool Configuration::IsEtwLoggingEnabled() const
{
#ifdef LINUX
return false;
#else
return _isEtwLoggingEnabled;
#endif
}
std::string const& Configuration::GetEtwReplayEndpoint() const
{
#ifdef LINUX
return DefaultEmptyString;
#else
return _etwReplayEndpoint;
#endif
}
EnablementStatus Configuration::GetEnablementStatus() const
{
return _enablementStatus;
}
DeploymentMode Configuration::GetDeploymentMode() const
{
return _deploymentMode;
}
std::chrono::milliseconds Configuration::GetSsiLongLivedThreshold() const
{
return _ssiLongLivedThreshold;
}
CpuProfilerType Configuration::GetCpuProfilerType() const
{
return _cpuProfilerType;
}
std::chrono::milliseconds Configuration::GetCpuProfilingInterval() const
{
return _cpuProfilingInterval;
}
static bool convert_to(shared::WSTRING const& s, bool& result)
{
return shared::TryParseBooleanEnvironmentValue(s, result);
}
static bool convert_to(shared::WSTRING const& s, std::string& result)
{
result = shared::ToString(shared::Trim(s));
return true;
}
static bool convert_to(shared::WSTRING const& s, shared::WSTRING& result)
{
result = shared::Trim(s);
return true;
}
static bool convert_to(shared::WSTRING const& s, int32_t& result)
{
return TryParse(s, result);
}
static bool convert_to(shared::WSTRING const& s, uint64_t& result)
{
return TryParse(s, result);
}
static bool convert_to(shared::WSTRING const& s, double& result)
{
auto str = shared::ToString(shared::Trim(s));
char* endPtr = nullptr;
const char* ptr = str.c_str();
result = strtod(ptr, &endPtr);
// non numeric input
if (ptr == endPtr)
{
return false;
}
// Based on tests, numbers such as "0.1.2" are converted into 0.1 without error
return (errno != ERANGE);
}
static bool convert_to(shared::WSTRING const& s, std::chrono::milliseconds& result)
{
std::uint64_t value;
auto parsed = TryParse(s, value);
if (parsed)
{
result = std::chrono::milliseconds(value);
}
return parsed;
}
static bool convert_to(shared::WSTRING const& s, DeploymentMode& result)
{
// if we reach here it means the env var exists
result = DeploymentMode::SingleStepInstrumentation;
return true;
}
template <typename T>
T Configuration::GetEnvironmentValue(shared::WSTRING const& name, T const& defaultValue)
{
if (!shared::EnvironmentExist(name)) return defaultValue;
T result{};
auto r = shared::GetEnvironmentValue(name);
if (!convert_to(r, result)) return defaultValue;
return result;
}
template <typename T>
bool Configuration::IsEnvironmentValueSet(shared::WSTRING const& name, T& value)
{
auto r = shared::Trim(shared::GetEnvironmentValue(name));
if (r.empty()) return false;
T result{};
if (!convert_to(r, result)) return false;
value = result;
return true;
}
EnablementStatus Configuration::ExtractEnablementStatus()
{
if (shared::EnvironmentExist(EnvironmentVariables::ProfilerEnabled))
{
auto isEnabled = false;
auto enabled = shared::GetEnvironmentValue(EnvironmentVariables::ProfilerEnabled);
auto parsed = shared::TryParseBooleanEnvironmentValue(enabled, isEnabled);
if (parsed)
{
return isEnabled
? EnablementStatus::ManuallyEnabled
: EnablementStatus::ManuallyDisabled;
}
// It is possible that a Single Step Instrumentation deployment was done
// and the profiler was enabled during that step. In that case, the "auto" value
// will be set and profiler should be enabled.
// This should be replaced by adding "profiler" in EnvironmentVariables::SsiDeployed
// later that will take into account heuristics
return !enabled.empty() && enabled == WStr("auto")
? EnablementStatus::Auto
: EnablementStatus::ManuallyDisabled;
}
auto r = shared::GetEnvironmentValue(EnvironmentVariables::SsiDeployed);
auto pos = r.find(WStr("profiler"));
auto ssiEnabled = (pos != shared::WSTRING::npos);
if (ssiEnabled)
{
return EnablementStatus::SsiEnabled;
}
else
{
return EnablementStatus::NotSet;
}
}
std::chrono::milliseconds Configuration::ExtractSsiLongLivedThreshold() const
{
auto const defaultValue = 30'000ms;
auto value = GetEnvironmentValue(EnvironmentVariables::SsiLongLivedThreshold, defaultValue);
if (value < 0ms)
return defaultValue;
return std::chrono::milliseconds(value);
}
bool Configuration::IsTelemetryToDiskEnabled() const
{
return _isTelemetryToDiskEnabled;
}
bool Configuration::IsSsiTelemetryEnabled() const
{
return _isSsiTelemetryEnabled;
}
bool Configuration::IsHttpProfilingEnabled() const
{
return _isHttpProfilingEnabled;
}
bool Configuration::ForceHttpSampling() const
{
return _forceHttpSampling;
}
std::chrono::milliseconds Configuration::ExtractHttpRequestDurationThreshold() const
{
auto const defaultValue = 50ms;
auto value = GetEnvironmentValue(EnvironmentVariables::HttpRequestDurationThreshold, defaultValue);
if (value < 0ms)
return defaultValue;
return std::chrono::milliseconds(value);
}
std::chrono::milliseconds Configuration::GetHttpRequestDurationThreshold() const
{
return _httpRequestDurationThreshold;
}