-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy pathConfig.java
4885 lines (4152 loc) · 175 KB
/
Config.java
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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package datadog.trace.api;
import static datadog.trace.api.ConfigDefaults.*;
import static datadog.trace.api.DDTags.*;
import static datadog.trace.api.config.AppSecConfig.*;
import static datadog.trace.api.config.CiVisibilityConfig.*;
import static datadog.trace.api.config.CrashTrackingConfig.*;
import static datadog.trace.api.config.CwsConfig.CWS_ENABLED;
import static datadog.trace.api.config.CwsConfig.CWS_TLS_REFRESH;
import static datadog.trace.api.config.DebuggerConfig.*;
import static datadog.trace.api.config.GeneralConfig.*;
import static datadog.trace.api.config.GeneralConfig.SERVICE_NAME;
import static datadog.trace.api.config.IastConfig.*;
import static datadog.trace.api.config.JmxFetchConfig.*;
import static datadog.trace.api.config.LlmObsConfig.*;
import static datadog.trace.api.config.ProfilingConfig.*;
import static datadog.trace.api.config.RemoteConfigConfig.*;
import static datadog.trace.api.config.TraceInstrumentationConfig.*;
import static datadog.trace.api.config.TracerConfig.*;
import static datadog.trace.api.iast.IastDetectionMode.DEFAULT;
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
import static datadog.trace.util.CollectionUtils.tryMakeImmutableList;
import static datadog.trace.util.CollectionUtils.tryMakeImmutableSet;
import static datadog.trace.util.Strings.propertyNameToEnvironmentVariableName;
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags;
import datadog.trace.api.config.GeneralConfig;
import datadog.trace.api.config.ProfilingConfig;
import datadog.trace.api.config.TracerConfig;
import datadog.trace.api.iast.IastContext;
import datadog.trace.api.iast.IastDetectionMode;
import datadog.trace.api.iast.telemetry.Verbosity;
import datadog.trace.api.naming.SpanNaming;
import datadog.trace.api.profiling.ProfilingEnablement;
import datadog.trace.bootstrap.config.provider.CapturedEnvironmentConfigSource;
import datadog.trace.bootstrap.config.provider.ConfigProvider;
import datadog.trace.bootstrap.config.provider.SystemPropertiesConfigSource;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.context.TraceScope;
import datadog.trace.util.PidHelper;
import datadog.trace.util.RandomUtils;
import datadog.trace.util.Strings;
import datadog.trace.util.throwable.FatalAgentMisconfigurationError;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Config reads values with the following priority:
*
* <p>1) system properties
*
* <p>2) environment variables,
*
* <p>3) optional configuration file
*
* <p>4) platform dependant properties. It also includes default values to ensure a valid config.
*
* <p>System properties are {@link Config#PREFIX}'ed. Environment variables are the same as the
* system property, but uppercased and '.' is replaced with '_'.
*
* @see ConfigProvider for details on how configs are processed
* @see InstrumenterConfig for pre-instrumentation configurations
* @see DynamicConfig for configuration that can be dynamically updated via remote-config
*/
public class Config {
private static final Logger log = LoggerFactory.getLogger(Config.class);
private static final Pattern COLON = Pattern.compile(":");
private final InstrumenterConfig instrumenterConfig;
private final long startTimeMillis = System.currentTimeMillis();
private final boolean timelineEventsEnabled;
/**
* this is a random UUID that gets generated on JVM start up and is attached to every root span
* and every JMX metric that is sent out.
*/
static class RuntimeIdHolder {
static final String runtimeId = RandomUtils.randomUUID().toString();
}
static class HostNameHolder {
static final String hostName = initHostName();
public static String getHostName() {
return hostName;
}
}
private final boolean runtimeIdEnabled;
/** This is the version of the runtime, ex: 1.8.0_332, 11.0.15, 17.0.3 */
private final String runtimeVersion;
private final String applicationKey;
/**
* Note: this has effect only on profiling site. Traces are sent to Datadog agent and are not
* affected by this setting. If CI Visibility is used with agentless mode, api key is used when
* sending data (including traces) to backend
*/
private final String apiKey;
/**
* Note: this has effect only on profiling site. Traces are sent to Datadog agent and are not
* affected by this setting.
*/
private final String site;
private final String serviceName;
private final boolean serviceNameSetByUser;
private final String rootContextServiceName;
private final boolean integrationSynapseLegacyOperationName;
private final String writerType;
private final boolean injectBaggageAsTagsEnabled;
private final boolean agentConfiguredUsingDefault;
private final String agentUrl;
private final String agentHost;
private final int agentPort;
private final String agentUnixDomainSocket;
private final String agentNamedPipe;
private final int agentTimeout;
private final Set<String> noProxyHosts;
private final boolean prioritySamplingEnabled;
private final String prioritySamplingForce;
private final boolean traceResolverEnabled;
private final int spanAttributeSchemaVersion;
private final boolean peerHostNameEnabled;
private final boolean peerServiceDefaultsEnabled;
private final Map<String, String> peerServiceComponentOverrides;
private final boolean removeIntegrationServiceNamesEnabled;
private final Map<String, String> peerServiceMapping;
private final Map<String, String> serviceMapping;
private final Map<String, String> tags;
private final Map<String, String> spanTags;
private final Map<String, String> jmxTags;
private final Map<String, String> requestHeaderTags;
private final Map<String, String> responseHeaderTags;
private final Map<String, String> baggageMapping;
private final boolean requestHeaderTagsCommaAllowed;
private final BitSet httpServerErrorStatuses;
private final BitSet httpClientErrorStatuses;
private final boolean httpServerTagQueryString;
private final boolean httpServerRawQueryString;
private final boolean httpServerRawResource;
private final boolean httpServerDecodedResourcePreserveSpaces;
private final boolean httpServerRouteBasedNaming;
private final Map<String, String> httpServerPathResourceNameMapping;
private final Map<String, String> httpClientPathResourceNameMapping;
private final boolean httpResourceRemoveTrailingSlash;
private final boolean httpClientTagQueryString;
private final boolean httpClientTagHeaders;
private final boolean httpClientSplitByDomain;
private final boolean dbClientSplitByInstance;
private final boolean dbClientSplitByInstanceTypeSuffix;
private final boolean dbClientSplitByHost;
private final Set<String> splitByTags;
private final boolean jeeSplitByDeployment;
private final int scopeDepthLimit;
private final boolean scopeStrictMode;
private final int scopeIterationKeepAlive;
private final int partialFlushMinSpans;
private final int traceKeepLatencyThreshold;
private final boolean traceKeepLatencyThresholdEnabled;
private final boolean traceStrictWritesEnabled;
private final boolean logExtractHeaderNames;
private final Set<PropagationStyle> propagationStylesToExtract;
private final Set<PropagationStyle> propagationStylesToInject;
private final boolean tracePropagationStyleB3PaddingEnabled;
private final Set<TracePropagationStyle> tracePropagationStylesToExtract;
private final Set<TracePropagationStyle> tracePropagationStylesToInject;
private final TracePropagationBehaviorExtract tracePropagationBehaviorExtract;
private final boolean tracePropagationExtractFirst;
private final int traceBaggageMaxItems;
private final int traceBaggageMaxBytes;
private final int clockSyncPeriod;
private final boolean logsInjectionEnabled;
private final String dogStatsDNamedPipe;
private final int dogStatsDStartDelay;
private final Integer statsDClientQueueSize;
private final Integer statsDClientSocketBuffer;
private final Integer statsDClientSocketTimeout;
private final boolean runtimeMetricsEnabled;
private final boolean jmxFetchEnabled;
private final String jmxFetchConfigDir;
private final List<String> jmxFetchConfigs;
@Deprecated private final List<String> jmxFetchMetricsConfigs;
private final Integer jmxFetchCheckPeriod;
private final Integer jmxFetchInitialRefreshBeansPeriod;
private final Integer jmxFetchRefreshBeansPeriod;
private final String jmxFetchStatsdHost;
private final Integer jmxFetchStatsdPort;
private final boolean jmxFetchMultipleRuntimeServicesEnabled;
private final int jmxFetchMultipleRuntimeServicesLimit;
// These values are default-ed to those of jmx fetch values as needed
private final boolean healthMetricsEnabled;
private final String healthMetricsStatsdHost;
private final Integer healthMetricsStatsdPort;
private final boolean perfMetricsEnabled;
private final boolean tracerMetricsEnabled;
private final boolean tracerMetricsBufferingEnabled;
private final int tracerMetricsMaxAggregates;
private final int tracerMetricsMaxPending;
private final boolean reportHostName;
private final boolean traceAnalyticsEnabled;
private final String traceClientIpHeader;
private final boolean traceClientIpResolverEnabled;
private final boolean traceGitMetadataEnabled;
private final Map<String, String> traceSamplingServiceRules;
private final Map<String, String> traceSamplingOperationRules;
private final String traceSamplingRules;
private final Double traceSampleRate;
private final int traceRateLimit;
private final String spanSamplingRules;
private final String spanSamplingRulesFile;
private final ProfilingEnablement profilingEnabled;
private final boolean profilingAgentless;
private final boolean isDatadogProfilerEnabled;
@Deprecated private final String profilingUrl;
private final Map<String, String> profilingTags;
private final int profilingStartDelay;
private final boolean profilingStartForceFirst;
private final int profilingUploadPeriod;
private final String profilingTemplateOverrideFile;
private final int profilingUploadTimeout;
private final String profilingUploadCompression;
private final String profilingProxyHost;
private final int profilingProxyPort;
private final String profilingProxyUsername;
private final String profilingProxyPassword;
private final int profilingExceptionSampleLimit;
private final int profilingBackPressureSampleLimit;
private final boolean profilingBackPressureEnabled;
private final int profilingDirectAllocationSampleLimit;
private final int profilingExceptionHistogramTopItems;
private final int profilingExceptionHistogramMaxCollectionSize;
private final boolean profilingExcludeAgentThreads;
private final boolean profilingUploadSummaryOn413Enabled;
private final boolean profilingRecordExceptionMessage;
private final boolean crashTrackingAgentless;
private final Map<String, String> crashTrackingTags;
private final boolean clientIpEnabled;
private final boolean appSecReportingInband;
private final String appSecRulesFile;
private final int appSecReportMinTimeout;
private final int appSecReportMaxTimeout;
private final int appSecTraceRateLimit;
private final boolean appSecWafMetrics;
private final int appSecWafTimeout;
private final String appSecObfuscationParameterKeyRegexp;
private final String appSecObfuscationParameterValueRegexp;
private final String appSecHttpBlockedTemplateHtml;
private final String appSecHttpBlockedTemplateJson;
private final UserIdCollectionMode appSecUserIdCollectionMode;
private final Boolean appSecScaEnabled;
private final boolean appSecRaspEnabled;
private final boolean appSecStackTraceEnabled;
private final int appSecMaxStackTraces;
private final int appSecMaxStackTraceDepth;
private final boolean apiSecurityEnabled;
private final float apiSecuritySampleDelay;
private final boolean apiSecurityEndpointCollectionEnabled;
private final int apiSecurityEndpointCollectionMessageLimit;
private final IastDetectionMode iastDetectionMode;
private final int iastMaxConcurrentRequests;
private final int iastVulnerabilitiesPerRequest;
private final float iastRequestSampling;
private final boolean iastDebugEnabled;
private final Verbosity iastTelemetryVerbosity;
private final boolean iastRedactionEnabled;
private final String iastRedactionNamePattern;
private final String iastRedactionValuePattern;
private final int iastMaxRangeCount;
private final int iastTruncationMaxValueLength;
private final boolean iastStacktraceLeakSuppress;
private final IastContext.Mode iastContextMode;
private final boolean iastHardcodedSecretEnabled;
private final boolean iastAnonymousClassesEnabled;
private final boolean iastSourceMappingEnabled;
private final int iastSourceMappingMaxSize;
private final boolean iastStackTraceEnabled;
private final boolean iastExperimentalPropagationEnabled;
private final String iastSecurityControlsConfiguration;
private final int iastDbRowsToTaint;
private final boolean llmObsAgentlessEnabled;
private final String llmObsMlApp;
private final boolean ciVisibilityTraceSanitationEnabled;
private final boolean ciVisibilityAgentlessEnabled;
private final String ciVisibilityAgentlessUrl;
private final boolean ciVisibilitySourceDataEnabled;
private final boolean ciVisibilityBuildInstrumentationEnabled;
private final String ciVisibilityAgentJarUri;
private final boolean ciVisibilityAutoConfigurationEnabled;
private final String ciVisibilityAdditionalChildProcessJvmArgs;
private final boolean ciVisibilityCompilerPluginAutoConfigurationEnabled;
private final boolean ciVisibilityCodeCoverageEnabled;
private final Boolean ciVisibilityCoverageLinesEnabled;
private final String ciVisibilityCodeCoverageReportDumpDir;
private final String ciVisibilityCompilerPluginVersion;
private final String ciVisibilityJacocoPluginVersion;
private final boolean ciVisibilityJacocoPluginVersionProvided;
private final List<String> ciVisibilityCodeCoverageIncludes;
private final List<String> ciVisibilityCodeCoverageExcludes;
private final String[] ciVisibilityCodeCoverageIncludedPackages;
private final String[] ciVisibilityCodeCoverageExcludedPackages;
private final List<String> ciVisibilityJacocoGradleSourceSets;
private final Integer ciVisibilityDebugPort;
private final boolean ciVisibilityGitClientEnabled;
private final boolean ciVisibilityGitUploadEnabled;
private final boolean ciVisibilityGitUnshallowEnabled;
private final boolean ciVisibilityGitUnshallowDefer;
private final long ciVisibilityGitCommandTimeoutMillis;
private final String ciVisibilityGitRemoteName;
private final long ciVisibilityBackendApiTimeoutMillis;
private final long ciVisibilityGitUploadTimeoutMillis;
private final String ciVisibilitySignalServerHost;
private final int ciVisibilitySignalServerPort;
private final int ciVisibilitySignalClientTimeoutMillis;
private final boolean ciVisibilityItrEnabled;
private final boolean ciVisibilityTestSkippingEnabled;
private final boolean ciVisibilityCiProviderIntegrationEnabled;
private final boolean ciVisibilityRepoIndexDuplicateKeyCheckEnabled;
private final int ciVisibilityExecutionSettingsCacheSize;
private final int ciVisibilityJvmInfoCacheSize;
private final int ciVisibilityCoverageRootPackagesLimit;
private final String ciVisibilityInjectedTracerVersion;
private final List<String> ciVisibilityResourceFolderNames;
private final boolean ciVisibilityFlakyRetryEnabled;
private final boolean ciVisibilityImpactedTestsDetectionEnabled;
private final boolean ciVisibilityImpactedTestsBackendRequestEnabled;
private final boolean ciVisibilityKnownTestsRequestEnabled;
private final boolean ciVisibilityFlakyRetryOnlyKnownFlakes;
private final int ciVisibilityFlakyRetryCount;
private final int ciVisibilityTotalFlakyRetryCount;
private final boolean ciVisibilityEarlyFlakeDetectionEnabled;
private final int ciVisibilityEarlyFlakeDetectionLowerLimit;
private final String ciVisibilitySessionName;
private final String ciVisibilityModuleName;
private final String ciVisibilityTestCommand;
private final boolean ciVisibilityTelemetryEnabled;
private final long ciVisibilityRumFlushWaitMillis;
private final boolean ciVisibilityAutoInjected;
private final String ciVisibilityRemoteEnvVarsProviderUrl;
private final String ciVisibilityRemoteEnvVarsProviderKey;
private final String ciVisibilityTestOrder;
private final boolean ciVisibilityTestManagementEnabled;
private final Integer ciVisibilityTestManagementAttemptToFixRetries;
private final boolean remoteConfigEnabled;
private final boolean remoteConfigIntegrityCheckEnabled;
private final String remoteConfigUrl;
private final float remoteConfigPollIntervalSeconds;
private final long remoteConfigMaxPayloadSize;
private final String remoteConfigTargetsKeyId;
private final String remoteConfigTargetsKey;
private final int remoteConfigMaxExtraServices;
private final String DBMPropagationMode;
private final boolean DBMTracePreparedStatements;
private final boolean dynamicInstrumentationEnabled;
private final int dynamicInstrumentationUploadTimeout;
private final int dynamicInstrumentationUploadFlushInterval;
private final boolean dynamicInstrumentationClassFileDumpEnabled;
private final int dynamicInstrumentationPollInterval;
private final int dynamicInstrumentationDiagnosticsInterval;
private final boolean dynamicInstrumentationMetricEnabled;
private final String dynamicInstrumentationProbeFile;
private final int dynamicInstrumentationUploadBatchSize;
private final long dynamicInstrumentationMaxPayloadSize;
private final boolean dynamicInstrumentationVerifyByteCode;
private final boolean dynamicInstrumentationInstrumentTheWorld;
private final String dynamicInstrumentationExcludeFiles;
private final String dynamicInstrumentationIncludeFiles;
private final int dynamicInstrumentationCaptureTimeout;
private final String dynamicInstrumentationRedactedIdentifiers;
private final Set<String> dynamicInstrumentationRedactionExcludedIdentifiers;
private final String dynamicInstrumentationRedactedTypes;
private final boolean dynamicInstrumentationHoistLocalVarsEnabled;
private final boolean symbolDatabaseEnabled;
private final boolean symbolDatabaseForceUpload;
private final int symbolDatabaseFlushThreshold;
private final boolean symbolDatabaseCompressed;
private final boolean debuggerExceptionEnabled;
private final int debuggerMaxExceptionPerSecond;
@Deprecated private final boolean debuggerExceptionOnlyLocalRoot;
private final boolean debuggerExceptionCaptureIntermediateSpansEnabled;
private final int debuggerExceptionMaxCapturedFrames;
private final int debuggerExceptionCaptureInterval;
private final boolean debuggerCodeOriginEnabled;
private final int debuggerCodeOriginMaxUserFrames;
private final boolean distributedDebuggerEnabled;
private final Set<String> debuggerThirdPartyIncludes;
private final Set<String> debuggerThirdPartyExcludes;
private final Set<String> debuggerShadingIdentifiers;
private final boolean awsPropagationEnabled;
private final boolean sqsPropagationEnabled;
private final boolean sqsBodyPropagationEnabled;
private final boolean kafkaClientPropagationEnabled;
private final Set<String> kafkaClientPropagationDisabledTopics;
private final boolean kafkaClientBase64DecodingEnabled;
private final boolean jmsPropagationEnabled;
private final Set<String> jmsPropagationDisabledTopics;
private final Set<String> jmsPropagationDisabledQueues;
private final int jmsUnacknowledgedMaxAge;
private final boolean rabbitPropagationEnabled;
private final Set<String> rabbitPropagationDisabledQueues;
private final Set<String> rabbitPropagationDisabledExchanges;
private final boolean rabbitIncludeRoutingKeyInResource;
private final boolean messageBrokerSplitByDestination;
private final boolean hystrixTagsEnabled;
private final boolean hystrixMeasuredEnabled;
private final boolean igniteCacheIncludeKeys;
private final String obfuscationQueryRegexp;
// TODO: remove at a future point.
private final boolean playReportHttpStatus;
private final boolean servletPrincipalEnabled;
private final boolean servletAsyncTimeoutError;
private final boolean springDataRepositoryInterfaceResourceName;
private final int xDatadogTagsMaxLength;
private final boolean traceAgentV05Enabled;
private final String logLevel;
private final boolean debugEnabled;
private final boolean triageEnabled;
private final String triageReportTrigger;
private final String triageReportDir;
private final boolean startupLogsEnabled;
private final String configFileStatus;
private final IdGenerationStrategy idGenerationStrategy;
private final boolean secureRandom;
private final boolean trace128bitTraceIdGenerationEnabled;
private final boolean logs128bitTraceIdEnabled;
private final Set<String> grpcIgnoredInboundMethods;
private final Set<String> grpcIgnoredOutboundMethods;
private final boolean grpcServerTrimPackageResource;
private final BitSet grpcServerErrorStatuses;
private final BitSet grpcClientErrorStatuses;
private final boolean cwsEnabled;
private final int cwsTlsRefresh;
private final boolean dataJobsEnabled;
private final String dataJobsCommandPattern;
private final boolean dataStreamsEnabled;
private final float dataStreamsBucketDurationSeconds;
private final Set<String> iastWeakHashAlgorithms;
private final Pattern iastWeakCipherAlgorithms;
private final boolean iastDeduplicationEnabled;
private final float telemetryHeartbeatInterval;
private final long telemetryExtendedHeartbeatInterval;
private final float telemetryMetricsInterval;
private final boolean isTelemetryDependencyServiceEnabled;
private final boolean telemetryMetricsEnabled;
private final boolean isTelemetryLogCollectionEnabled;
private final int telemetryDependencyResolutionQueueSize;
private final boolean azureAppServices;
private final boolean azureFunctions;
private final String traceAgentPath;
private final List<String> traceAgentArgs;
private final String dogStatsDPath;
private final List<String> dogStatsDArgs;
private String env;
private String version;
private final String primaryTag;
private final ConfigProvider configProvider;
private final boolean longRunningTraceEnabled;
private final long longRunningTraceInitialFlushInterval;
private final long longRunningTraceFlushInterval;
private final boolean cassandraKeyspaceStatementExtractionEnabled;
private final boolean couchbaseInternalSpansEnabled;
private final boolean elasticsearchBodyEnabled;
private final boolean elasticsearchParamsEnabled;
private final boolean elasticsearchBodyAndParamsEnabled;
private final boolean sparkTaskHistogramEnabled;
private final boolean sparkAppNameAsService;
private final boolean jaxRsExceptionAsErrorsEnabled;
private final boolean websocketMessagesInheritSampling;
private final boolean websocketMessagesSeparateTraces;
private final boolean websocketTagSessionId;
private final boolean axisPromoteResourceName;
private final float traceFlushIntervalSeconds;
private final long tracePostProcessingTimeout;
private final boolean telemetryDebugRequestsEnabled;
private final boolean agentlessLogSubmissionEnabled;
private final int agentlessLogSubmissionQueueSize;
private final String agentlessLogSubmissionLevel;
private final String agentlessLogSubmissionUrl;
private final String agentlessLogSubmissionProduct;
private final Set<String> cloudPayloadTaggingServices;
@Nullable private final List<String> cloudRequestPayloadTagging;
@Nullable private final List<String> cloudResponsePayloadTagging;
private final int cloudPayloadTaggingMaxDepth;
private final int cloudPayloadTaggingMaxTags;
private final long dependecyResolutionPeriodMillis;
private final boolean apmTracingEnabled;
private final Set<String> experimentalFeaturesEnabled;
private final boolean jdkSocketEnabled;
// Read order: System Properties -> Env Variables, [-> properties file], [-> default value]
private Config() {
this(ConfigProvider.createDefault());
}
private Config(final ConfigProvider configProvider) {
this(configProvider, new InstrumenterConfig(configProvider));
}
private Config(final ConfigProvider configProvider, final InstrumenterConfig instrumenterConfig) {
this.configProvider = configProvider;
this.instrumenterConfig = instrumenterConfig;
configFileStatus = configProvider.getConfigFileStatus();
runtimeIdEnabled = configProvider.getBoolean(RUNTIME_ID_ENABLED, true);
runtimeVersion = System.getProperty("java.version", "unknown");
// Note: We do not want APiKey to be loaded from property for security reasons
// Note: we do not use defined default here
// FIXME: We should use better authentication mechanism
final String apiKeyFile = configProvider.getString(API_KEY_FILE);
String tmpApiKey =
configProvider.getStringExcludingSource(API_KEY, null, SystemPropertiesConfigSource.class);
if (apiKeyFile != null) {
try {
tmpApiKey =
new String(Files.readAllBytes(Paths.get(apiKeyFile)), StandardCharsets.UTF_8).trim();
} catch (final IOException e) {
log.error(
"Cannot read API key from file {}, skipping. Exception {}", apiKeyFile, e.getMessage());
}
}
site = configProvider.getString(SITE, DEFAULT_SITE);
String tmpApplicationKey =
configProvider.getStringExcludingSource(
APPLICATION_KEY, null, SystemPropertiesConfigSource.class);
String applicationKeyFile = configProvider.getString(APPLICATION_KEY_FILE);
if (applicationKeyFile != null) {
try {
tmpApplicationKey =
new String(Files.readAllBytes(Paths.get(applicationKeyFile)), StandardCharsets.UTF_8)
.trim();
} catch (final IOException e) {
log.error("Cannot read API key from file {}, skipping", applicationKeyFile, e);
}
}
applicationKey = tmpApplicationKey;
String userProvidedServiceName =
configProvider.getStringExcludingSource(
SERVICE, null, CapturedEnvironmentConfigSource.class, SERVICE_NAME);
if (userProvidedServiceName == null) {
serviceNameSetByUser = false;
serviceName = configProvider.getString(SERVICE, DEFAULT_SERVICE_NAME, SERVICE_NAME);
} else {
serviceNameSetByUser = true;
serviceName = userProvidedServiceName;
}
rootContextServiceName =
configProvider.getString(
SERVLET_ROOT_CONTEXT_SERVICE_NAME, DEFAULT_SERVLET_ROOT_CONTEXT_SERVICE_NAME);
experimentalFeaturesEnabled =
configProvider.getString(TRACE_EXPERIMENTAL_FEATURES_ENABLED, "").equals("all")
? DEFAULT_TRACE_EXPERIMENTAL_FEATURES_ENABLED
: configProvider.getSet(TRACE_EXPERIMENTAL_FEATURES_ENABLED, new HashSet<>());
integrationSynapseLegacyOperationName =
configProvider.getBoolean(INTEGRATION_SYNAPSE_LEGACY_OPERATION_NAME, false);
writerType = configProvider.getString(WRITER_TYPE, DEFAULT_AGENT_WRITER_TYPE);
injectBaggageAsTagsEnabled =
configProvider.getBoolean(WRITER_BAGGAGE_INJECT, DEFAULT_WRITER_BAGGAGE_INJECT);
String lambdaInitType = getEnv("AWS_LAMBDA_INITIALIZATION_TYPE");
if (lambdaInitType != null && lambdaInitType.equals("snap-start")) {
secureRandom = true;
} else {
secureRandom = configProvider.getBoolean(SECURE_RANDOM, DEFAULT_SECURE_RANDOM);
}
cassandraKeyspaceStatementExtractionEnabled =
configProvider.getBoolean(
CASSANDRA_KEYSPACE_STATEMENT_EXTRACTION_ENABLED,
DEFAULT_CASSANDRA_KEYSPACE_STATEMENT_EXTRACTION_ENABLED);
couchbaseInternalSpansEnabled =
configProvider.getBoolean(
COUCHBASE_INTERNAL_SPANS_ENABLED, DEFAULT_COUCHBASE_INTERNAL_SPANS_ENABLED);
elasticsearchBodyEnabled =
configProvider.getBoolean(ELASTICSEARCH_BODY_ENABLED, DEFAULT_ELASTICSEARCH_BODY_ENABLED);
elasticsearchParamsEnabled =
configProvider.getBoolean(
ELASTICSEARCH_PARAMS_ENABLED, DEFAULT_ELASTICSEARCH_PARAMS_ENABLED);
elasticsearchBodyAndParamsEnabled =
configProvider.getBoolean(
ELASTICSEARCH_BODY_AND_PARAMS_ENABLED, DEFAULT_ELASTICSEARCH_BODY_AND_PARAMS_ENABLED);
String strategyName = configProvider.getString(ID_GENERATION_STRATEGY);
trace128bitTraceIdGenerationEnabled =
configProvider.getBoolean(
TRACE_128_BIT_TRACEID_GENERATION_ENABLED,
DEFAULT_TRACE_128_BIT_TRACEID_GENERATION_ENABLED);
logs128bitTraceIdEnabled =
configProvider.getBoolean(
TRACE_128_BIT_TRACEID_LOGGING_ENABLED, DEFAULT_TRACE_128_BIT_TRACEID_LOGGING_ENABLED);
if (secureRandom) {
strategyName = "SECURE_RANDOM";
}
if (strategyName == null) {
strategyName = "RANDOM";
}
IdGenerationStrategy strategy =
IdGenerationStrategy.fromName(strategyName, trace128bitTraceIdGenerationEnabled);
if (strategy == null) {
log.warn(
"*** you are trying to use an unknown id generation strategy {} - falling back to RANDOM",
strategyName);
strategyName = "RANDOM";
strategy = IdGenerationStrategy.fromName(strategyName, trace128bitTraceIdGenerationEnabled);
}
if (!strategyName.equals("RANDOM") && !strategyName.equals("SECURE_RANDOM")) {
log.warn(
"*** you are using an unsupported id generation strategy {} - this can impact correctness of traces",
strategyName);
}
idGenerationStrategy = strategy;
String agentHostFromEnvironment = null;
int agentPortFromEnvironment = -1;
String unixSocketFromEnvironment = null;
boolean rebuildAgentUrl = false;
final String agentUrlFromEnvironment = configProvider.getString(TRACE_AGENT_URL);
if (agentUrlFromEnvironment != null) {
try {
final URI parsedAgentUrl = new URI(agentUrlFromEnvironment);
agentHostFromEnvironment = parsedAgentUrl.getHost();
agentPortFromEnvironment = parsedAgentUrl.getPort();
if ("unix".equals(parsedAgentUrl.getScheme())) {
unixSocketFromEnvironment = parsedAgentUrl.getPath();
}
} catch (URISyntaxException e) {
log.warn("{} not configured correctly: {}. Ignoring", TRACE_AGENT_URL, e.getMessage());
}
}
// avoid merging in supplementary host/port settings when dealing with unix: URLs
if (unixSocketFromEnvironment == null) {
if (agentHostFromEnvironment == null) {
agentHostFromEnvironment = configProvider.getString(AGENT_HOST);
rebuildAgentUrl = true;
}
if (agentPortFromEnvironment < 0) {
agentPortFromEnvironment =
configProvider.getInteger(TRACE_AGENT_PORT, -1, AGENT_PORT_LEGACY);
rebuildAgentUrl = true;
}
}
if (agentHostFromEnvironment == null) {
agentHost = DEFAULT_AGENT_HOST;
} else if (agentHostFromEnvironment.charAt(0) == '[') {
agentHost = agentHostFromEnvironment.substring(1, agentHostFromEnvironment.length() - 1);
} else {
agentHost = agentHostFromEnvironment;
}
if (agentPortFromEnvironment < 0) {
agentPort = DEFAULT_TRACE_AGENT_PORT;
} else {
agentPort = agentPortFromEnvironment;
}
if (rebuildAgentUrl) { // check if agenthost contains ':'
if (agentHost.indexOf(':') != -1) { // Checking to see whether host address is IPv6 vs IPv4
agentUrl = "http://[" + agentHost + "]:" + agentPort;
} else {
agentUrl = "http://" + agentHost + ":" + agentPort;
}
} else {
agentUrl = agentUrlFromEnvironment;
}
if (unixSocketFromEnvironment == null) {
unixSocketFromEnvironment = configProvider.getString(AGENT_UNIX_DOMAIN_SOCKET);
String unixPrefix = "unix://";
// handle situation where someone passes us a unix:// URL instead of a socket path
if (unixSocketFromEnvironment != null && unixSocketFromEnvironment.startsWith(unixPrefix)) {
unixSocketFromEnvironment = unixSocketFromEnvironment.substring(unixPrefix.length());
}
}
agentUnixDomainSocket = unixSocketFromEnvironment;
agentNamedPipe = configProvider.getString(AGENT_NAMED_PIPE);
agentConfiguredUsingDefault =
agentHostFromEnvironment == null
&& agentPortFromEnvironment < 0
&& unixSocketFromEnvironment == null
&& agentNamedPipe == null;
agentTimeout = configProvider.getInteger(AGENT_TIMEOUT, DEFAULT_AGENT_TIMEOUT);
// DD_PROXY_NO_PROXY is specified as a space-separated list of hosts
noProxyHosts = tryMakeImmutableSet(configProvider.getSpacedList(PROXY_NO_PROXY));
prioritySamplingEnabled =
configProvider.getBoolean(PRIORITY_SAMPLING, DEFAULT_PRIORITY_SAMPLING_ENABLED);
prioritySamplingForce =
configProvider.getString(PRIORITY_SAMPLING_FORCE, DEFAULT_PRIORITY_SAMPLING_FORCE);
traceResolverEnabled =
configProvider.getBoolean(TRACE_RESOLVER_ENABLED, DEFAULT_TRACE_RESOLVER_ENABLED);
serviceMapping = configProvider.getMergedMap(SERVICE_MAPPING);
{
final Map<String, String> tags = new HashMap<>(configProvider.getMergedMap(GLOBAL_TAGS));
if (experimentalFeaturesEnabled.contains("DD_TAGS")) {
tags.putAll(configProvider.getMergedTagsMap(TRACE_TAGS, TAGS));
} else {
tags.putAll(configProvider.getMergedMap(TRACE_TAGS, TAGS));
}
if (serviceNameSetByUser) { // prioritize service name set by DD_SERVICE over DD_TAGS config
tags.remove("service");
}
this.tags = getMapWithPropertiesDefinedByEnvironment(tags, ENV, VERSION);
}
spanTags = configProvider.getMergedMap(SPAN_TAGS);
jmxTags = configProvider.getMergedMap(JMX_TAGS);
primaryTag = configProvider.getString(PRIMARY_TAG);
if (isEnabled(false, HEADER_TAGS, ".legacy.parsing.enabled")) {
requestHeaderTags = configProvider.getMergedMap(HEADER_TAGS);
responseHeaderTags = Collections.emptyMap();
if (configProvider.isSet(REQUEST_HEADER_TAGS)) {
logIgnoredSettingWarning(REQUEST_HEADER_TAGS, HEADER_TAGS, ".legacy.parsing.enabled");
}
if (configProvider.isSet(RESPONSE_HEADER_TAGS)) {
logIgnoredSettingWarning(RESPONSE_HEADER_TAGS, HEADER_TAGS, ".legacy.parsing.enabled");
}
} else {
requestHeaderTags =
configProvider.getMergedMapWithOptionalMappings(
"http.request.headers.", true, HEADER_TAGS, REQUEST_HEADER_TAGS);
responseHeaderTags =
configProvider.getMergedMapWithOptionalMappings(
"http.response.headers.", true, HEADER_TAGS, RESPONSE_HEADER_TAGS);
}
requestHeaderTagsCommaAllowed =
configProvider.getBoolean(REQUEST_HEADER_TAGS_COMMA_ALLOWED, true);
baggageMapping = configProvider.getMergedMapWithOptionalMappings(null, true, BAGGAGE_MAPPING);
azureFunctions =
getEnv("FUNCTIONS_WORKER_RUNTIME") != null && getEnv("FUNCTIONS_EXTENSION_VERSION") != null;
spanAttributeSchemaVersion = schemaVersionFromConfig();
peerHostNameEnabled = configProvider.getBoolean(TRACE_PEER_HOSTNAME_ENABLED, true);
// following two only used in v0.
// in v1+ defaults are always calculated regardless this feature flag
peerServiceDefaultsEnabled =
configProvider.getBoolean(TRACE_PEER_SERVICE_DEFAULTS_ENABLED, false);
peerServiceComponentOverrides =
configProvider.getMergedMap(TRACE_PEER_SERVICE_COMPONENT_OVERRIDES);
// feature flag to remove fake services in v0
removeIntegrationServiceNamesEnabled =
configProvider.getBoolean(TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED, false);
peerServiceMapping = configProvider.getMergedMap(TRACE_PEER_SERVICE_MAPPING);
httpServerPathResourceNameMapping =
configProvider.getOrderedMap(TRACE_HTTP_SERVER_PATH_RESOURCE_NAME_MAPPING);
httpClientPathResourceNameMapping =
configProvider.getOrderedMap(TRACE_HTTP_CLIENT_PATH_RESOURCE_NAME_MAPPING);
httpResourceRemoveTrailingSlash =
configProvider.getBoolean(
TRACE_HTTP_RESOURCE_REMOVE_TRAILING_SLASH,
DEFAULT_TRACE_HTTP_RESOURCE_REMOVE_TRAILING_SLASH);
httpServerErrorStatuses =
configProvider.getIntegerRange(
TRACE_HTTP_SERVER_ERROR_STATUSES,
DEFAULT_HTTP_SERVER_ERROR_STATUSES,
HTTP_SERVER_ERROR_STATUSES);
httpClientErrorStatuses =
configProvider.getIntegerRange(
TRACE_HTTP_CLIENT_ERROR_STATUSES,
DEFAULT_HTTP_CLIENT_ERROR_STATUSES,
HTTP_CLIENT_ERROR_STATUSES);
httpServerTagQueryString =
configProvider.getBoolean(
HTTP_SERVER_TAG_QUERY_STRING, DEFAULT_HTTP_SERVER_TAG_QUERY_STRING);
httpServerRawQueryString = configProvider.getBoolean(HTTP_SERVER_RAW_QUERY_STRING, true);
httpServerRawResource = configProvider.getBoolean(HTTP_SERVER_RAW_RESOURCE, false);
httpServerDecodedResourcePreserveSpaces =
configProvider.getBoolean(HTTP_SERVER_DECODED_RESOURCE_PRESERVE_SPACES, true);
httpServerRouteBasedNaming =
configProvider.getBoolean(
HTTP_SERVER_ROUTE_BASED_NAMING, DEFAULT_HTTP_SERVER_ROUTE_BASED_NAMING);
httpClientTagQueryString =
configProvider.getBoolean(
TRACE_HTTP_CLIENT_TAG_QUERY_STRING,
DEFAULT_HTTP_CLIENT_TAG_QUERY_STRING,
HTTP_CLIENT_TAG_QUERY_STRING);
httpClientTagHeaders = configProvider.getBoolean(HTTP_CLIENT_TAG_HEADERS, true);
httpClientSplitByDomain =
configProvider.getBoolean(
HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, DEFAULT_HTTP_CLIENT_SPLIT_BY_DOMAIN);
dbClientSplitByInstance =
configProvider.getBoolean(
DB_CLIENT_HOST_SPLIT_BY_INSTANCE, DEFAULT_DB_CLIENT_HOST_SPLIT_BY_INSTANCE);
dbClientSplitByInstanceTypeSuffix =
configProvider.getBoolean(
DB_CLIENT_HOST_SPLIT_BY_INSTANCE_TYPE_SUFFIX,
DEFAULT_DB_CLIENT_HOST_SPLIT_BY_INSTANCE_TYPE_SUFFIX);
dbClientSplitByHost =
configProvider.getBoolean(
DB_CLIENT_HOST_SPLIT_BY_HOST, DEFAULT_DB_CLIENT_HOST_SPLIT_BY_HOST);
DBMPropagationMode =
configProvider.getString(
DB_DBM_PROPAGATION_MODE_MODE, DEFAULT_DB_DBM_PROPAGATION_MODE_MODE);
DBMTracePreparedStatements =
configProvider.getBoolean(
DB_DBM_TRACE_PREPARED_STATEMENTS, DEFAULT_DB_DBM_TRACE_PREPARED_STATEMENTS);
splitByTags = tryMakeImmutableSet(configProvider.getList(SPLIT_BY_TAGS));
jeeSplitByDeployment =
configProvider.getBoolean(
EXPERIMENTATAL_JEE_SPLIT_BY_DEPLOYMENT, DEFAULT_EXPERIMENTATAL_JEE_SPLIT_BY_DEPLOYMENT);
springDataRepositoryInterfaceResourceName =
configProvider.getBoolean(SPRING_DATA_REPOSITORY_INTERFACE_RESOURCE_NAME, true);
scopeDepthLimit = configProvider.getInteger(SCOPE_DEPTH_LIMIT, DEFAULT_SCOPE_DEPTH_LIMIT);
scopeStrictMode = configProvider.getBoolean(SCOPE_STRICT_MODE, false);
scopeIterationKeepAlive =
configProvider.getInteger(SCOPE_ITERATION_KEEP_ALIVE, DEFAULT_SCOPE_ITERATION_KEEP_ALIVE);
boolean partialFlushEnabled = configProvider.getBoolean(PARTIAL_FLUSH_ENABLED, true);
partialFlushMinSpans =
!partialFlushEnabled
? 0
: configProvider.getInteger(PARTIAL_FLUSH_MIN_SPANS, DEFAULT_PARTIAL_FLUSH_MIN_SPANS);
traceKeepLatencyThreshold =
configProvider.getInteger(
TRACE_KEEP_LATENCY_THRESHOLD_MS, DEFAULT_TRACE_KEEP_LATENCY_THRESHOLD_MS);
traceKeepLatencyThresholdEnabled = !partialFlushEnabled && (traceKeepLatencyThreshold > 0);
traceStrictWritesEnabled = configProvider.getBoolean(TRACE_STRICT_WRITES_ENABLED, false);
logExtractHeaderNames =
configProvider.getBoolean(
PROPAGATION_EXTRACT_LOG_HEADER_NAMES_ENABLED,
DEFAULT_PROPAGATION_EXTRACT_LOG_HEADER_NAMES_ENABLED);
tracePropagationStyleB3PaddingEnabled =
isEnabled(true, TRACE_PROPAGATION_STYLE, ".b3.padding.enabled");
TracePropagationBehaviorExtract tmpTracePropagationBehaviorExtract;
try {
tmpTracePropagationBehaviorExtract =
TracePropagationBehaviorExtract.valueOf(
configProvider
.getString(
TRACE_PROPAGATION_BEHAVIOR_EXTRACT,
DEFAULT_TRACE_PROPAGATION_BEHAVIOR_EXTRACT.toString())
.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
tmpTracePropagationBehaviorExtract = TracePropagationBehaviorExtract.CONTINUE;
log.warn("Error while parsing TRACE_PROPAGATION_BEHAVIOR_EXTRACT, defaulting to `continue`");
}
tracePropagationBehaviorExtract = tmpTracePropagationBehaviorExtract;
{
// The dd.propagation.style.(extract|inject) settings have been deprecated in
// favor of dd.trace.propagation.style(|.extract|.inject) settings.
// The different propagation settings when set will be applied in the following order of
// precedence, and warnings will be logged for both deprecation and overrides.
// * dd.trace.propagation.style.(extract|inject)
// * dd.trace.propagation.style
// * dd.propagation.style.(extract|inject)
Set<PropagationStyle> deprecatedExtract =
getSettingsSetFromEnvironment(
PROPAGATION_STYLE_EXTRACT, PropagationStyle::valueOfConfigName, true);
Set<PropagationStyle> deprecatedInject =
getSettingsSetFromEnvironment(
PROPAGATION_STYLE_INJECT, PropagationStyle::valueOfConfigName, true);
Set<TracePropagationStyle> common =
getSettingsSetFromEnvironment(
TRACE_PROPAGATION_STYLE, TracePropagationStyle::valueOfDisplayName, false);
Set<TracePropagationStyle> extract =
getSettingsSetFromEnvironment(
TRACE_PROPAGATION_STYLE_EXTRACT, TracePropagationStyle::valueOfDisplayName, false);
Set<TracePropagationStyle> inject =
getSettingsSetFromEnvironment(
TRACE_PROPAGATION_STYLE_INJECT, TracePropagationStyle::valueOfDisplayName, false);
String extractOrigin = TRACE_PROPAGATION_STYLE_EXTRACT;
String injectOrigin = TRACE_PROPAGATION_STYLE_INJECT;
// Check if we should use the common setting for extraction
if (extract.isEmpty()) {
extract = common;