Line data Source code
1 : // Copyright The OpenTelemetry Authors
2 : // SPDX-License-Identifier: Apache-2.0
3 :
4 : import 'env_constants.dart';
5 :
6 : /// Helper function to retrieve String.fromEnvironment values.
7 : ///
8 : /// Since String.fromEnvironment requires compile-time constants, we must
9 : /// explicitly check each possible variable in a switch statement.
10 : ///
11 : /// @param key The environment variable name
12 : /// @return The value from String.fromEnvironment, or null if empty
13 142 : String? getFromEnvironment(String key) {
14 : // We use a switch statement because String.fromEnvironment requires
15 : // compile-time constants. Each case must be explicitly listed.
16 : switch (key) {
17 : // General SDK Configuration
18 142 : case otelSdkDisabled:
19 : return const String.fromEnvironment(otelSdkDisabled);
20 142 : case otelResourceAttributes:
21 : return const String.fromEnvironment(otelResourceAttributes);
22 142 : case otelServiceName:
23 : return const String.fromEnvironment(otelServiceName);
24 141 : case otelLogLevel:
25 : return const String.fromEnvironment(otelLogLevel);
26 141 : case otelDartLogMetrics:
27 : return const String.fromEnvironment(otelDartLogMetrics);
28 141 : case otelDartLogSpans:
29 : return const String.fromEnvironment(otelDartLogSpans);
30 141 : case otelDartLogExport:
31 : return const String.fromEnvironment(otelDartLogExport);
32 141 : case otelPropagators:
33 : return const String.fromEnvironment(otelPropagators);
34 141 : case otelTracesSampler:
35 : return const String.fromEnvironment(otelTracesSampler);
36 141 : case otelTracesSamplerArg:
37 : return const String.fromEnvironment(otelTracesSamplerArg);
38 :
39 : // Logging Configuration
40 :
41 : // General OTLP Configuration
42 141 : case otelExporterOtlpEndpoint:
43 : return const String.fromEnvironment(otelExporterOtlpEndpoint);
44 141 : case otelExporterOtlpProtocol:
45 : return const String.fromEnvironment(otelExporterOtlpProtocol);
46 141 : case otelExporterOtlpHeaders:
47 : return const String.fromEnvironment(otelExporterOtlpHeaders);
48 141 : case otelExporterOtlpInsecure:
49 : return const String.fromEnvironment(otelExporterOtlpInsecure);
50 141 : case otelExporterOtlpTimeout:
51 : return const String.fromEnvironment(otelExporterOtlpTimeout);
52 141 : case otelExporterOtlpCompression:
53 : return const String.fromEnvironment(otelExporterOtlpCompression);
54 141 : case otelExporterOtlpCertificate:
55 : return const String.fromEnvironment(otelExporterOtlpCertificate);
56 141 : case otelExporterOtlpClientKey:
57 : return const String.fromEnvironment(otelExporterOtlpClientKey);
58 141 : case otelExporterOtlpClientCertificate:
59 : return const String.fromEnvironment(otelExporterOtlpClientCertificate);
60 :
61 : // Traces-specific Configuration
62 141 : case otelTracesExporter:
63 : return const String.fromEnvironment(otelTracesExporter);
64 141 : case otelExporterOtlpTracesEndpoint:
65 : return const String.fromEnvironment(otelExporterOtlpTracesEndpoint);
66 141 : case otelExporterOtlpTracesProtocol:
67 : return const String.fromEnvironment(otelExporterOtlpTracesProtocol);
68 141 : case otelExporterOtlpTracesHeaders:
69 : return const String.fromEnvironment(otelExporterOtlpTracesHeaders);
70 141 : case otelExporterOtlpTracesInsecure:
71 : return const String.fromEnvironment(otelExporterOtlpTracesInsecure);
72 141 : case otelExporterOtlpTracesTimeout:
73 : return const String.fromEnvironment(otelExporterOtlpTracesTimeout);
74 141 : case otelExporterOtlpTracesCompression:
75 : return const String.fromEnvironment(otelExporterOtlpTracesCompression);
76 141 : case otelExporterOtlpTracesCertificate:
77 : return const String.fromEnvironment(otelExporterOtlpTracesCertificate);
78 141 : case otelExporterOtlpTracesClientKey:
79 : return const String.fromEnvironment(otelExporterOtlpTracesClientKey);
80 141 : case otelExporterOtlpTracesClientCertificate:
81 : return const String.fromEnvironment(
82 : otelExporterOtlpTracesClientCertificate,
83 : );
84 :
85 : // Metrics-specific Configuration
86 141 : case otelMetricsExporter:
87 : return const String.fromEnvironment(otelMetricsExporter);
88 141 : case otelExporterOtlpMetricsEndpoint:
89 : return const String.fromEnvironment(otelExporterOtlpMetricsEndpoint);
90 141 : case otelExporterOtlpMetricsProtocol:
91 : return const String.fromEnvironment(otelExporterOtlpMetricsProtocol);
92 141 : case otelExporterOtlpMetricsHeaders:
93 : return const String.fromEnvironment(otelExporterOtlpMetricsHeaders);
94 141 : case otelExporterOtlpMetricsInsecure:
95 : return const String.fromEnvironment(otelExporterOtlpMetricsInsecure);
96 141 : case otelExporterOtlpMetricsTimeout:
97 : return const String.fromEnvironment(otelExporterOtlpMetricsTimeout);
98 141 : case otelExporterOtlpMetricsCompression:
99 : return const String.fromEnvironment(otelExporterOtlpMetricsCompression);
100 141 : case otelExporterOtlpMetricsCertificate:
101 : return const String.fromEnvironment(otelExporterOtlpMetricsCertificate);
102 141 : case otelExporterOtlpMetricsClientKey:
103 : return const String.fromEnvironment(otelExporterOtlpMetricsClientKey);
104 141 : case otelExporterOtlpMetricsClientCertificate:
105 : return const String.fromEnvironment(
106 : otelExporterOtlpMetricsClientCertificate,
107 : );
108 :
109 : // Logs-specific Configuration
110 141 : case otelLogsExporter:
111 : return const String.fromEnvironment(otelLogsExporter);
112 141 : case otelExporterOtlpLogsEndpoint:
113 : return const String.fromEnvironment(otelExporterOtlpLogsEndpoint);
114 141 : case otelExporterOtlpLogsProtocol:
115 : return const String.fromEnvironment(otelExporterOtlpLogsProtocol);
116 141 : case otelExporterOtlpLogsHeaders:
117 : return const String.fromEnvironment(otelExporterOtlpLogsHeaders);
118 141 : case otelExporterOtlpLogsInsecure:
119 : return const String.fromEnvironment(otelExporterOtlpLogsInsecure);
120 141 : case otelExporterOtlpLogsTimeout:
121 : return const String.fromEnvironment(otelExporterOtlpLogsTimeout);
122 141 : case otelExporterOtlpLogsCompression:
123 : return const String.fromEnvironment(otelExporterOtlpLogsCompression);
124 141 : case otelExporterOtlpLogsCertificate:
125 : return const String.fromEnvironment(otelExporterOtlpLogsCertificate);
126 141 : case otelExporterOtlpLogsClientKey:
127 : return const String.fromEnvironment(otelExporterOtlpLogsClientKey);
128 141 : case otelExporterOtlpLogsClientCertificate:
129 : return const String.fromEnvironment(
130 : otelExporterOtlpLogsClientCertificate,
131 : );
132 :
133 : // Batch Span Processor
134 140 : case otelBspScheduleDelay:
135 : return const String.fromEnvironment(otelBspScheduleDelay);
136 140 : case otelBspExportTimeout:
137 : return const String.fromEnvironment(otelBspExportTimeout);
138 140 : case otelBspMaxQueueSize:
139 : return const String.fromEnvironment(otelBspMaxQueueSize);
140 140 : case otelBspMaxExportBatchSize:
141 : return const String.fromEnvironment(otelBspMaxExportBatchSize);
142 :
143 : // Batch LogRecord Processor
144 132 : case otelBlrpScheduleDelay:
145 : return const String.fromEnvironment(otelBlrpScheduleDelay);
146 132 : case otelBlrpExportTimeout:
147 : return const String.fromEnvironment(otelBlrpExportTimeout);
148 132 : case otelBlrpMaxQueueSize:
149 : return const String.fromEnvironment(otelBlrpMaxQueueSize);
150 132 : case otelBlrpMaxExportBatchSize:
151 : return const String.fromEnvironment(otelBlrpMaxExportBatchSize);
152 :
153 : // Attribute Limits
154 123 : case otelAttributeValueLengthLimit:
155 : return const String.fromEnvironment(otelAttributeValueLengthLimit);
156 123 : case otelAttributeCountLimit:
157 : return const String.fromEnvironment(otelAttributeCountLimit);
158 :
159 : // Span Limits
160 123 : case otelSpanAttributeValueLengthLimit:
161 : return const String.fromEnvironment(otelSpanAttributeValueLengthLimit);
162 123 : case otelSpanAttributeCountLimit:
163 : return const String.fromEnvironment(otelSpanAttributeCountLimit);
164 123 : case otelSpanEventCountLimit:
165 : return const String.fromEnvironment(otelSpanEventCountLimit);
166 123 : case otelSpanLinkCountLimit:
167 : return const String.fromEnvironment(otelSpanLinkCountLimit);
168 123 : case otelEventAttributeCountLimit:
169 : return const String.fromEnvironment(otelEventAttributeCountLimit);
170 123 : case otelLinkAttributeCountLimit:
171 : return const String.fromEnvironment(otelLinkAttributeCountLimit);
172 :
173 : // LogRecord Limits
174 123 : case otelLogrecordAttributeValueLengthLimit:
175 : return const String.fromEnvironment(
176 : otelLogrecordAttributeValueLengthLimit,
177 : );
178 123 : case otelLogrecordAttributeCountLimit:
179 : return const String.fromEnvironment(otelLogrecordAttributeCountLimit);
180 :
181 : // Metrics SDK Configuration
182 123 : case otelMetricsExemplarFilter:
183 : return const String.fromEnvironment(otelMetricsExemplarFilter);
184 123 : case otelMetricExportInterval:
185 : return const String.fromEnvironment(otelMetricExportInterval);
186 123 : case otelMetricExportTimeout:
187 : return const String.fromEnvironment(otelMetricExportTimeout);
188 :
189 : // Zipkin Exporter
190 1 : case otelExporterZipkinEndpoint:
191 : return const String.fromEnvironment(otelExporterZipkinEndpoint);
192 1 : case otelExporterZipkinTimeout:
193 : return const String.fromEnvironment(otelExporterZipkinTimeout);
194 :
195 : // Prometheus Exporter
196 1 : case otelExporterPrometheusHost:
197 : return const String.fromEnvironment(otelExporterPrometheusHost);
198 1 : case otelExporterPrometheusPort:
199 : return const String.fromEnvironment(otelExporterPrometheusPort);
200 :
201 : // Deprecated but supported
202 1 : case otelExporterOtlpSpanInsecure:
203 : return const String.fromEnvironment(otelExporterOtlpSpanInsecure);
204 1 : case otelExporterOtlpMetricInsecure:
205 : return const String.fromEnvironment(otelExporterOtlpMetricInsecure);
206 :
207 : default:
208 : return null;
209 : }
210 : }
|