|
111 | 111 | import static datadog.trace.api.ConfigDefaults.DEFAULT_JMX_FETCH_MULTIPLE_RUNTIME_SERVICES_LIMIT; |
112 | 112 | import static datadog.trace.api.ConfigDefaults.DEFAULT_LLM_OBS_AGENTLESS_ENABLED; |
113 | 113 | import static datadog.trace.api.ConfigDefaults.DEFAULT_LOGS_INJECTION_ENABLED; |
| 114 | +import static datadog.trace.api.ConfigDefaults.DEFAULT_METRICS_OTEL_ENABLED; |
| 115 | +import static datadog.trace.api.ConfigDefaults.DEFAULT_OTEL_EXPORTER_OTLP_METRICS_PROTOCOL; |
| 116 | +import static datadog.trace.api.ConfigDefaults.DEFAULT_OTEL_EXPORTER_OTLP_METRICS_TIMEOUT; |
| 117 | +import static datadog.trace.api.ConfigDefaults.DEFAULT_OTEL_METRICS_EXPORTER; |
| 118 | +import static datadog.trace.api.ConfigDefaults.DEFAULT_OTEL_METRIC_EXPORT_INTERVAL; |
| 119 | +import static datadog.trace.api.ConfigDefaults.DEFAULT_OTEL_METRIC_EXPORT_TIMEOUT; |
114 | 120 | import static datadog.trace.api.ConfigDefaults.DEFAULT_PARTIAL_FLUSH_MIN_SPANS; |
115 | 121 | import static datadog.trace.api.ConfigDefaults.DEFAULT_PERF_METRICS_ENABLED; |
116 | 122 | import static datadog.trace.api.ConfigDefaults.DEFAULT_PRIORITY_SAMPLING_ENABLED; |
|
433 | 439 | import static datadog.trace.api.config.JmxFetchConfig.JMX_TAGS; |
434 | 440 | import static datadog.trace.api.config.LlmObsConfig.LLMOBS_AGENTLESS_ENABLED; |
435 | 441 | import static datadog.trace.api.config.LlmObsConfig.LLMOBS_ML_APP; |
| 442 | +import static datadog.trace.api.config.OtelConfig.METRICS_OTEL_ENABLED; |
| 443 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_ENDPOINT; |
| 444 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_HEADERS; |
| 445 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT; |
| 446 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_METRICS_HEADERS; |
| 447 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL; |
| 448 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE; |
| 449 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_METRICS_TIMEOUT; |
| 450 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_PROTOCOL; |
| 451 | +import static datadog.trace.api.config.OtelConfig.OTEL_EXPORTER_OTLP_TIMEOUT; |
| 452 | +import static datadog.trace.api.config.OtelConfig.OTEL_METRICS_EXPORTER; |
| 453 | +import static datadog.trace.api.config.OtelConfig.OTEL_METRIC_ENDPOINT_GRPC_PORT; |
| 454 | +import static datadog.trace.api.config.OtelConfig.OTEL_METRIC_ENDPOINT_HTTP_PORT; |
| 455 | +import static datadog.trace.api.config.OtelConfig.OTEL_METRIC_ENDPOINT_SUFFIX; |
| 456 | +import static datadog.trace.api.config.OtelConfig.OTEL_METRIC_EXPORT_INTERVAL; |
| 457 | +import static datadog.trace.api.config.OtelConfig.OTEL_METRIC_EXPORT_TIMEOUT; |
| 458 | +import static datadog.trace.api.config.OtelConfig.OTEL_RESOURCE_ATTRIBUTES; |
436 | 459 | import static datadog.trace.api.config.ProfilingConfig.PROFILING_AGENTLESS; |
437 | 460 | import static datadog.trace.api.config.ProfilingConfig.PROFILING_AGENTLESS_DEFAULT; |
438 | 461 | import static datadog.trace.api.config.ProfilingConfig.PROFILING_API_KEY_FILE_OLD; |
|
660 | 683 | import datadog.environment.SystemProperties; |
661 | 684 | import datadog.trace.api.civisibility.CiVisibilityWellKnownTags; |
662 | 685 | import datadog.trace.api.config.GeneralConfig; |
| 686 | +import datadog.trace.api.config.OtelConfig; |
663 | 687 | import datadog.trace.api.config.ProfilingConfig; |
664 | 688 | import datadog.trace.api.config.TracerConfig; |
665 | 689 | import datadog.trace.api.iast.IastContext; |
@@ -883,6 +907,17 @@ public static String getHostName() { |
883 | 907 | private final boolean jmxFetchMultipleRuntimeServicesEnabled; |
884 | 908 | private final int jmxFetchMultipleRuntimeServicesLimit; |
885 | 909 |
|
| 910 | + private final boolean metricsOtelEnabled; |
| 911 | + private final Map<String, String> otelResourceAttributes; |
| 912 | + private final OtelConfig.Exporter otelMetricsExporter; |
| 913 | + private final Integer otelMetricExportInterval; |
| 914 | + private final Integer otelMetricExportTimeout; |
| 915 | + private final String otelExporterOtlpMetricsEndpoint; |
| 916 | + private final Map<String, String> otelExporterOtlpMetricsHeaders; |
| 917 | + private final OtelConfig.Protocol otelExporterOtlpMetricsProtocol; |
| 918 | + private final Integer otelExporterOtlpMetricsTimeout; |
| 919 | + private final OtelConfig.Temporality otelExporterOtlpMetricsTemporalityPreference; |
| 920 | + |
886 | 921 | // These values are default-ed to those of jmx fetch values as needed |
887 | 922 | private final boolean healthMetricsEnabled; |
888 | 923 | private final String healthMetricsStatsdHost; |
@@ -1818,7 +1853,103 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins |
1818 | 1853 | statsDClientSocketBuffer = configProvider.getInteger(STATSD_CLIENT_SOCKET_BUFFER); |
1819 | 1854 | statsDClientSocketTimeout = configProvider.getInteger(STATSD_CLIENT_SOCKET_TIMEOUT); |
1820 | 1855 |
|
1821 | | - runtimeMetricsEnabled = configProvider.getBoolean(RUNTIME_METRICS_ENABLED, true); |
| 1856 | + metricsOtelEnabled = |
| 1857 | + configProvider.getBoolean(METRICS_OTEL_ENABLED, DEFAULT_METRICS_OTEL_ENABLED); |
| 1858 | + otelResourceAttributes = |
| 1859 | + getHashMap(configProvider.getList(OTEL_RESOURCE_ATTRIBUTES), OTEL_RESOURCE_ATTRIBUTES, "="); |
| 1860 | + otelMetricsExporter = |
| 1861 | + configProvider.getEnum( |
| 1862 | + OTEL_METRICS_EXPORTER, OtelConfig.Exporter.class, DEFAULT_OTEL_METRICS_EXPORTER, false); |
| 1863 | + |
| 1864 | + int tmpOtelMetricExportTimeout = |
| 1865 | + configProvider.getInteger(OTEL_METRIC_EXPORT_TIMEOUT, DEFAULT_OTEL_METRIC_EXPORT_TIMEOUT); |
| 1866 | + otelMetricExportTimeout = |
| 1867 | + (tmpOtelMetricExportTimeout < 0) |
| 1868 | + ? DEFAULT_OTEL_METRIC_EXPORT_TIMEOUT |
| 1869 | + : tmpOtelMetricExportTimeout; |
| 1870 | + |
| 1871 | + int tmpOtelMetricExportInterval = |
| 1872 | + configProvider.getInteger(OTEL_METRIC_EXPORT_INTERVAL, DEFAULT_OTEL_METRIC_EXPORT_INTERVAL); |
| 1873 | + otelMetricExportInterval = |
| 1874 | + (tmpOtelMetricExportInterval < 0) |
| 1875 | + ? DEFAULT_OTEL_METRIC_EXPORT_INTERVAL |
| 1876 | + : tmpOtelMetricExportInterval; |
| 1877 | + |
| 1878 | + List<String> tmpOtelExporterOtlpMetricsHeaders = |
| 1879 | + configProvider.getList(OTEL_EXPORTER_OTLP_METRICS_HEADERS); |
| 1880 | + otelExporterOtlpMetricsHeaders = |
| 1881 | + tmpOtelExporterOtlpMetricsHeaders.isEmpty() |
| 1882 | + ? getHashMap( |
| 1883 | + configProvider.getList(OTEL_EXPORTER_OTLP_HEADERS), OTEL_EXPORTER_OTLP_HEADERS, "=") |
| 1884 | + : getHashMap( |
| 1885 | + tmpOtelExporterOtlpMetricsHeaders, OTEL_EXPORTER_OTLP_METRICS_HEADERS, "="); |
| 1886 | + |
| 1887 | + OtelConfig.Protocol tmpOtelExporterOtlpMetricsProtocol = |
| 1888 | + configProvider.getEnum( |
| 1889 | + OTEL_EXPORTER_OTLP_METRICS_PROTOCOL, OtelConfig.Protocol.class, null, false, "/", "_"); |
| 1890 | + if (tmpOtelExporterOtlpMetricsProtocol == null) { |
| 1891 | + tmpOtelExporterOtlpMetricsProtocol = |
| 1892 | + configProvider.getEnum( |
| 1893 | + OTEL_EXPORTER_OTLP_PROTOCOL, |
| 1894 | + OtelConfig.Protocol.class, |
| 1895 | + DEFAULT_OTEL_EXPORTER_OTLP_METRICS_PROTOCOL, |
| 1896 | + false, |
| 1897 | + "/", |
| 1898 | + "_"); |
| 1899 | + } |
| 1900 | + otelExporterOtlpMetricsProtocol = tmpOtelExporterOtlpMetricsProtocol; |
| 1901 | + // TO DO |
| 1902 | + // Add some error log and switch the protocol to the default value if we don't support the |
| 1903 | + // selected protocol |
| 1904 | + |
| 1905 | + String tmpOtelExporterOtlpMetricsEndpoint = |
| 1906 | + configProvider.getString(OTEL_EXPORTER_OTLP_METRICS_ENDPOINT); |
| 1907 | + if (tmpOtelExporterOtlpMetricsEndpoint == null) { |
| 1908 | + boolean isHttp = !otelExporterOtlpMetricsProtocol.equals(OtelConfig.Protocol.GRPC); |
| 1909 | + String tmpOtelExporterOtlpEndpoint = configProvider.getString(OTEL_EXPORTER_OTLP_ENDPOINT); |
| 1910 | + if (null == tmpOtelExporterOtlpEndpoint) { |
| 1911 | + String endpointHost = agentHost.isEmpty() ? DEFAULT_AGENT_HOST : agentHost; |
| 1912 | + tmpOtelExporterOtlpMetricsEndpoint = |
| 1913 | + isHttp |
| 1914 | + ? "http://" |
| 1915 | + + endpointHost |
| 1916 | + + ":" |
| 1917 | + + OTEL_METRIC_ENDPOINT_HTTP_PORT |
| 1918 | + + "/" |
| 1919 | + + OTEL_METRIC_ENDPOINT_SUFFIX |
| 1920 | + : "http://" + endpointHost + ":" + OTEL_METRIC_ENDPOINT_GRPC_PORT; |
| 1921 | + } else { |
| 1922 | + tmpOtelExporterOtlpMetricsEndpoint = |
| 1923 | + isHttp |
| 1924 | + ? tmpOtelExporterOtlpEndpoint.concat(OTEL_METRIC_ENDPOINT_SUFFIX) |
| 1925 | + : tmpOtelExporterOtlpEndpoint; |
| 1926 | + } |
| 1927 | + } |
| 1928 | + otelExporterOtlpMetricsEndpoint = tmpOtelExporterOtlpMetricsEndpoint; |
| 1929 | + |
| 1930 | + Integer tmpOtelExporterOtlpMetricsTimeout = |
| 1931 | + configProvider.getInteger(OTEL_EXPORTER_OTLP_METRICS_TIMEOUT); |
| 1932 | + if (null == tmpOtelExporterOtlpMetricsTimeout) { |
| 1933 | + tmpOtelExporterOtlpMetricsTimeout = |
| 1934 | + configProvider.getInteger( |
| 1935 | + OTEL_EXPORTER_OTLP_TIMEOUT, DEFAULT_OTEL_EXPORTER_OTLP_METRICS_TIMEOUT); |
| 1936 | + } |
| 1937 | + otelExporterOtlpMetricsTimeout = |
| 1938 | + tmpOtelExporterOtlpMetricsTimeout < 0 |
| 1939 | + ? DEFAULT_OTEL_EXPORTER_OTLP_METRICS_TIMEOUT |
| 1940 | + : tmpOtelExporterOtlpMetricsTimeout; |
| 1941 | + |
| 1942 | + otelExporterOtlpMetricsTemporalityPreference = |
| 1943 | + configProvider.getEnum( |
| 1944 | + OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, |
| 1945 | + OtelConfig.Temporality.class, |
| 1946 | + OtelConfig.Temporality.DELTA, |
| 1947 | + false); |
| 1948 | + |
| 1949 | + // Runtime metrics are disabled if Otel metrics are enabled and the metrics exporter is none |
| 1950 | + runtimeMetricsEnabled = |
| 1951 | + (!metricsOtelEnabled || !otelMetricsExporter.equals(OtelConfig.Exporter.NONE)) |
| 1952 | + && configProvider.getBoolean(RUNTIME_METRICS_ENABLED, true); |
1822 | 1953 |
|
1823 | 1954 | jmxFetchEnabled = |
1824 | 1955 | runtimeMetricsEnabled |
@@ -4936,6 +5067,46 @@ public boolean isJmxFetchIntegrationEnabled( |
4936 | 5067 | return configProvider.isEnabled(integrationNames, "jmxfetch.", ".enabled", defaultEnabled); |
4937 | 5068 | } |
4938 | 5069 |
|
| 5070 | + public boolean isMetricsOtelEnabled() { |
| 5071 | + return metricsOtelEnabled; |
| 5072 | + } |
| 5073 | + |
| 5074 | + public Map<String, String> getOtelResourceAttributes() { |
| 5075 | + return otelResourceAttributes; |
| 5076 | + } |
| 5077 | + |
| 5078 | + public OtelConfig.Exporter getOtelMetricsExporter() { |
| 5079 | + return otelMetricsExporter; |
| 5080 | + } |
| 5081 | + |
| 5082 | + public Integer getOtelMetricExportInterval() { |
| 5083 | + return otelMetricExportInterval; |
| 5084 | + } |
| 5085 | + |
| 5086 | + public Integer getOtelMetricExportTimeout() { |
| 5087 | + return otelMetricExportTimeout; |
| 5088 | + } |
| 5089 | + |
| 5090 | + public String getOtelExporterOtlpMetricsEndpoint() { |
| 5091 | + return otelExporterOtlpMetricsEndpoint; |
| 5092 | + } |
| 5093 | + |
| 5094 | + public Map<String, String> getOtelExporterOtlpMetricsHeaders() { |
| 5095 | + return otelExporterOtlpMetricsHeaders; |
| 5096 | + } |
| 5097 | + |
| 5098 | + public OtelConfig.Protocol getOtelExporterOtlpMetricsProtocol() { |
| 5099 | + return otelExporterOtlpMetricsProtocol; |
| 5100 | + } |
| 5101 | + |
| 5102 | + public Integer getOtelExporterOtlpMetricsTimeout() { |
| 5103 | + return otelExporterOtlpMetricsTimeout; |
| 5104 | + } |
| 5105 | + |
| 5106 | + public OtelConfig.Temporality getOtelExporterOtlpMetricsTemporalityPreference() { |
| 5107 | + return otelExporterOtlpMetricsTemporalityPreference; |
| 5108 | + } |
| 5109 | + |
4939 | 5110 | public boolean isRuleEnabled(final String name) { |
4940 | 5111 | return isRuleEnabled(name, true); |
4941 | 5112 | } |
@@ -5322,6 +5493,30 @@ private static <T> Set<T> convertStringSetToSet( |
5322 | 5493 | return Collections.unmodifiableSet(result); |
5323 | 5494 | } |
5324 | 5495 |
|
| 5496 | + private static Map<String, String> getHashMap( |
| 5497 | + List<String> inputAsList, String key, String delimiter) { |
| 5498 | + Map<String, String> finalValue = new HashMap<>(); |
| 5499 | + if (!inputAsList.isEmpty()) { |
| 5500 | + boolean error = false; |
| 5501 | + for (String keyvalue : inputAsList) { |
| 5502 | + int indexOfSplit = keyvalue.indexOf(delimiter); |
| 5503 | + if (indexOfSplit < 0) { |
| 5504 | + error = true; |
| 5505 | + continue; |
| 5506 | + } |
| 5507 | + finalValue.put(keyvalue.substring(0, indexOfSplit), keyvalue.substring(indexOfSplit + 1)); |
| 5508 | + } |
| 5509 | + if (error) { |
| 5510 | + log.debug( |
| 5511 | + "Parsing error occurs for {}, value provided: {}; value taken into account: {}", |
| 5512 | + key, |
| 5513 | + inputAsList, |
| 5514 | + finalValue); |
| 5515 | + } |
| 5516 | + } |
| 5517 | + return finalValue; |
| 5518 | + } |
| 5519 | + |
5325 | 5520 | /** Returns the detected hostname. First tries locally, then using DNS */ |
5326 | 5521 | static String initHostName() { |
5327 | 5522 | String possibleHostname; |
@@ -5916,6 +6111,26 @@ public String toString() { |
5916 | 6111 | + aiGuardEnabled |
5917 | 6112 | + ", aiGuardEndpoint=" |
5918 | 6113 | + aiGuardEndpoint |
| 6114 | + + ", metricsOtelEnabled=" |
| 6115 | + + metricsOtelEnabled |
| 6116 | + + ", otelResourceAttributes=" |
| 6117 | + + otelResourceAttributes |
| 6118 | + + ", otelMetricsExporter=" |
| 6119 | + + otelMetricsExporter |
| 6120 | + + ", otelMetricExportInterval=" |
| 6121 | + + otelMetricExportInterval |
| 6122 | + + ", otelMetricExportTimeout=" |
| 6123 | + + otelMetricExportTimeout |
| 6124 | + + ", otelExporterOtlpMetricsEndpoint=" |
| 6125 | + + otelExporterOtlpMetricsEndpoint |
| 6126 | + + ", otelExporterOtlpMetricsHeaders=" |
| 6127 | + + otelExporterOtlpMetricsHeaders |
| 6128 | + + ", otelExporterOtlpMetricsProtocol=" |
| 6129 | + + otelExporterOtlpMetricsProtocol |
| 6130 | + + ", otelExporterOtlpMetricsTimeout=" |
| 6131 | + + otelExporterOtlpMetricsTimeout |
| 6132 | + + ", otelExporterOtlpMetricsTemporalityPreference=" |
| 6133 | + + otelExporterOtlpMetricsTemporalityPreference |
5919 | 6134 | + '}'; |
5920 | 6135 | } |
5921 | 6136 | } |
0 commit comments