Line data Source code
1 : // Licensed under the Apache License, Version 2.0
2 : // Copyright 2025, Michael Bushe, All rights reserved.
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 73 : 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 73 : case otelSdkDisabled:
19 : return const String.fromEnvironment(otelSdkDisabled);
20 73 : case otelResourceAttributes:
21 : return const String.fromEnvironment(otelResourceAttributes);
22 73 : case otelServiceName:
23 : return const String.fromEnvironment(otelServiceName);
24 73 : case otelLogLevel:
25 : return const String.fromEnvironment(otelLogLevel);
26 73 : case otelPropagators:
27 : return const String.fromEnvironment(otelPropagators);
28 73 : case otelTracesSampler:
29 : return const String.fromEnvironment(otelTracesSampler);
30 73 : case otelTracesSamplerArg:
31 : return const String.fromEnvironment(otelTracesSamplerArg);
32 :
33 : // Logging Configuration
34 73 : case otelLogMetrics:
35 : return const String.fromEnvironment(otelLogMetrics);
36 73 : case otelLogSpans:
37 : return const String.fromEnvironment(otelLogSpans);
38 73 : case otelLogExport:
39 : return const String.fromEnvironment(otelLogExport);
40 :
41 : // General OTLP Configuration
42 73 : case otelExporterOtlpEndpoint:
43 : return const String.fromEnvironment(otelExporterOtlpEndpoint);
44 73 : case otelExporterOtlpProtocol:
45 : return const String.fromEnvironment(otelExporterOtlpProtocol);
46 73 : case otelExporterOtlpHeaders:
47 : return const String.fromEnvironment(otelExporterOtlpHeaders);
48 73 : case otelExporterOtlpInsecure:
49 : return const String.fromEnvironment(otelExporterOtlpInsecure);
50 73 : case otelExporterOtlpTimeout:
51 : return const String.fromEnvironment(otelExporterOtlpTimeout);
52 73 : case otelExporterOtlpCompression:
53 : return const String.fromEnvironment(otelExporterOtlpCompression);
54 73 : case otelExporterOtlpCertificate:
55 : return const String.fromEnvironment(otelExporterOtlpCertificate);
56 73 : case otelExporterOtlpClientKey:
57 : return const String.fromEnvironment(otelExporterOtlpClientKey);
58 73 : case otelExporterOtlpClientCertificate:
59 : return const String.fromEnvironment(otelExporterOtlpClientCertificate);
60 :
61 : // Traces-specific Configuration
62 73 : case otelTracesExporter:
63 : return const String.fromEnvironment(otelTracesExporter);
64 73 : case otelExporterOtlpTracesEndpoint:
65 : return const String.fromEnvironment(otelExporterOtlpTracesEndpoint);
66 73 : case otelExporterOtlpTracesProtocol:
67 : return const String.fromEnvironment(otelExporterOtlpTracesProtocol);
68 73 : case otelExporterOtlpTracesHeaders:
69 : return const String.fromEnvironment(otelExporterOtlpTracesHeaders);
70 73 : case otelExporterOtlpTracesInsecure:
71 : return const String.fromEnvironment(otelExporterOtlpTracesInsecure);
72 73 : case otelExporterOtlpTracesTimeout:
73 : return const String.fromEnvironment(otelExporterOtlpTracesTimeout);
74 73 : case otelExporterOtlpTracesCompression:
75 : return const String.fromEnvironment(otelExporterOtlpTracesCompression);
76 73 : case otelExporterOtlpTracesCertificate:
77 : return const String.fromEnvironment(otelExporterOtlpTracesCertificate);
78 73 : case otelExporterOtlpTracesClientKey:
79 : return const String.fromEnvironment(otelExporterOtlpTracesClientKey);
80 73 : case otelExporterOtlpTracesClientCertificate:
81 : return const String.fromEnvironment(
82 : otelExporterOtlpTracesClientCertificate);
83 :
84 : // Metrics-specific Configuration
85 0 : case otelMetricsExporter:
86 : return const String.fromEnvironment(otelMetricsExporter);
87 0 : case otelExporterOtlpMetricsEndpoint:
88 : return const String.fromEnvironment(otelExporterOtlpMetricsEndpoint);
89 0 : case otelExporterOtlpMetricsProtocol:
90 : return const String.fromEnvironment(otelExporterOtlpMetricsProtocol);
91 0 : case otelExporterOtlpMetricsHeaders:
92 : return const String.fromEnvironment(otelExporterOtlpMetricsHeaders);
93 0 : case otelExporterOtlpMetricsInsecure:
94 : return const String.fromEnvironment(otelExporterOtlpMetricsInsecure);
95 0 : case otelExporterOtlpMetricsTimeout:
96 : return const String.fromEnvironment(otelExporterOtlpMetricsTimeout);
97 0 : case otelExporterOtlpMetricsCompression:
98 : return const String.fromEnvironment(otelExporterOtlpMetricsCompression);
99 0 : case otelExporterOtlpMetricsCertificate:
100 : return const String.fromEnvironment(otelExporterOtlpMetricsCertificate);
101 0 : case otelExporterOtlpMetricsClientKey:
102 : return const String.fromEnvironment(otelExporterOtlpMetricsClientKey);
103 0 : case otelExporterOtlpMetricsClientCertificate:
104 : return const String.fromEnvironment(
105 : otelExporterOtlpMetricsClientCertificate);
106 :
107 : // Logs-specific Configuration
108 0 : case otelLogsExporter:
109 : return const String.fromEnvironment(otelLogsExporter);
110 0 : case otelExporterOtlpLogsEndpoint:
111 : return const String.fromEnvironment(otelExporterOtlpLogsEndpoint);
112 0 : case otelExporterOtlpLogsProtocol:
113 : return const String.fromEnvironment(otelExporterOtlpLogsProtocol);
114 0 : case otelExporterOtlpLogsHeaders:
115 : return const String.fromEnvironment(otelExporterOtlpLogsHeaders);
116 0 : case otelExporterOtlpLogsInsecure:
117 : return const String.fromEnvironment(otelExporterOtlpLogsInsecure);
118 0 : case otelExporterOtlpLogsTimeout:
119 : return const String.fromEnvironment(otelExporterOtlpLogsTimeout);
120 0 : case otelExporterOtlpLogsCompression:
121 : return const String.fromEnvironment(otelExporterOtlpLogsCompression);
122 0 : case otelExporterOtlpLogsCertificate:
123 : return const String.fromEnvironment(otelExporterOtlpLogsCertificate);
124 0 : case otelExporterOtlpLogsClientKey:
125 : return const String.fromEnvironment(otelExporterOtlpLogsClientKey);
126 0 : case otelExporterOtlpLogsClientCertificate:
127 : return const String.fromEnvironment(
128 : otelExporterOtlpLogsClientCertificate);
129 :
130 : // Batch Span Processor
131 0 : case otelBspScheduleDelay:
132 : return const String.fromEnvironment(otelBspScheduleDelay);
133 0 : case otelBspExportTimeout:
134 : return const String.fromEnvironment(otelBspExportTimeout);
135 0 : case otelBspMaxQueueSize:
136 : return const String.fromEnvironment(otelBspMaxQueueSize);
137 0 : case otelBspMaxExportBatchSize:
138 : return const String.fromEnvironment(otelBspMaxExportBatchSize);
139 :
140 : // Batch LogRecord Processor
141 0 : case otelBlrpScheduleDelay:
142 : return const String.fromEnvironment(otelBlrpScheduleDelay);
143 0 : case otelBlrpExportTimeout:
144 : return const String.fromEnvironment(otelBlrpExportTimeout);
145 0 : case otelBlrpMaxQueueSize:
146 : return const String.fromEnvironment(otelBlrpMaxQueueSize);
147 0 : case otelBlrpMaxExportBatchSize:
148 : return const String.fromEnvironment(otelBlrpMaxExportBatchSize);
149 :
150 : // Attribute Limits
151 0 : case otelAttributeValueLengthLimit:
152 : return const String.fromEnvironment(otelAttributeValueLengthLimit);
153 0 : case otelAttributeCountLimit:
154 : return const String.fromEnvironment(otelAttributeCountLimit);
155 :
156 : // Span Limits
157 0 : case otelSpanAttributeValueLengthLimit:
158 : return const String.fromEnvironment(otelSpanAttributeValueLengthLimit);
159 0 : case otelSpanAttributeCountLimit:
160 : return const String.fromEnvironment(otelSpanAttributeCountLimit);
161 0 : case otelSpanEventCountLimit:
162 : return const String.fromEnvironment(otelSpanEventCountLimit);
163 0 : case otelSpanLinkCountLimit:
164 : return const String.fromEnvironment(otelSpanLinkCountLimit);
165 0 : case otelEventAttributeCountLimit:
166 : return const String.fromEnvironment(otelEventAttributeCountLimit);
167 0 : case otelLinkAttributeCountLimit:
168 : return const String.fromEnvironment(otelLinkAttributeCountLimit);
169 :
170 : // LogRecord Limits
171 0 : case otelLogrecordAttributeValueLengthLimit:
172 : return const String.fromEnvironment(
173 : otelLogrecordAttributeValueLengthLimit);
174 0 : case otelLogrecordAttributeCountLimit:
175 : return const String.fromEnvironment(otelLogrecordAttributeCountLimit);
176 :
177 : // Metrics SDK Configuration
178 0 : case otelMetricsExemplarFilter:
179 : return const String.fromEnvironment(otelMetricsExemplarFilter);
180 0 : case otelMetricExportInterval:
181 : return const String.fromEnvironment(otelMetricExportInterval);
182 0 : case otelMetricExportTimeout:
183 : return const String.fromEnvironment(otelMetricExportTimeout);
184 :
185 : // Zipkin Exporter
186 0 : case otelExporterZipkinEndpoint:
187 : return const String.fromEnvironment(otelExporterZipkinEndpoint);
188 0 : case otelExporterZipkinTimeout:
189 : return const String.fromEnvironment(otelExporterZipkinTimeout);
190 :
191 : // Prometheus Exporter
192 0 : case otelExporterPrometheusHost:
193 : return const String.fromEnvironment(otelExporterPrometheusHost);
194 0 : case otelExporterPrometheusPort:
195 : return const String.fromEnvironment(otelExporterPrometheusPort);
196 :
197 : // Deprecated but supported
198 0 : case otelExporterOtlpSpanInsecure:
199 : return const String.fromEnvironment(otelExporterOtlpSpanInsecure);
200 0 : case otelExporterOtlpMetricInsecure:
201 : return const String.fromEnvironment(otelExporterOtlpMetricInsecure);
202 :
203 : default:
204 : return null;
205 : }
206 : }
|