1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.parseEnvironment = exports.DEFAULT_ENVIRONMENT = exports.DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT = exports.DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT = exports.DEFAULT_ATTRIBUTE_COUNT_LIMIT = exports.DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT = void 0;
|
19 | const api_1 = require("@opentelemetry/api");
|
20 | const sampling_1 = require("./sampling");
|
21 | const DEFAULT_LIST_SEPARATOR = ',';
|
22 |
|
23 |
|
24 |
|
25 | const ENVIRONMENT_BOOLEAN_KEYS = ['OTEL_SDK_DISABLED'];
|
26 | function isEnvVarABoolean(key) {
|
27 | return (ENVIRONMENT_BOOLEAN_KEYS.indexOf(key) > -1);
|
28 | }
|
29 | const ENVIRONMENT_NUMBERS_KEYS = [
|
30 | 'OTEL_BSP_EXPORT_TIMEOUT',
|
31 | 'OTEL_BSP_MAX_EXPORT_BATCH_SIZE',
|
32 | 'OTEL_BSP_MAX_QUEUE_SIZE',
|
33 | 'OTEL_BSP_SCHEDULE_DELAY',
|
34 | 'OTEL_BLRP_EXPORT_TIMEOUT',
|
35 | 'OTEL_BLRP_MAX_EXPORT_BATCH_SIZE',
|
36 | 'OTEL_BLRP_MAX_QUEUE_SIZE',
|
37 | 'OTEL_BLRP_SCHEDULE_DELAY',
|
38 | 'OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT',
|
39 | 'OTEL_ATTRIBUTE_COUNT_LIMIT',
|
40 | 'OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT',
|
41 | 'OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT',
|
42 | 'OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT',
|
43 | 'OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT',
|
44 | 'OTEL_SPAN_EVENT_COUNT_LIMIT',
|
45 | 'OTEL_SPAN_LINK_COUNT_LIMIT',
|
46 | 'OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT',
|
47 | 'OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT',
|
48 | 'OTEL_EXPORTER_OTLP_TIMEOUT',
|
49 | 'OTEL_EXPORTER_OTLP_TRACES_TIMEOUT',
|
50 | 'OTEL_EXPORTER_OTLP_METRICS_TIMEOUT',
|
51 | 'OTEL_EXPORTER_OTLP_LOGS_TIMEOUT',
|
52 | 'OTEL_EXPORTER_JAEGER_AGENT_PORT',
|
53 | ];
|
54 | function isEnvVarANumber(key) {
|
55 | return (ENVIRONMENT_NUMBERS_KEYS.indexOf(key) > -1);
|
56 | }
|
57 | const ENVIRONMENT_LISTS_KEYS = [
|
58 | 'OTEL_NO_PATCH_MODULES',
|
59 | 'OTEL_PROPAGATORS',
|
60 | ];
|
61 | function isEnvVarAList(key) {
|
62 | return ENVIRONMENT_LISTS_KEYS.indexOf(key) > -1;
|
63 | }
|
64 | exports.DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT = Infinity;
|
65 | exports.DEFAULT_ATTRIBUTE_COUNT_LIMIT = 128;
|
66 | exports.DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT = 128;
|
67 | exports.DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT = 128;
|
68 |
|
69 |
|
70 |
|
71 | exports.DEFAULT_ENVIRONMENT = {
|
72 | OTEL_SDK_DISABLED: false,
|
73 | CONTAINER_NAME: '',
|
74 | ECS_CONTAINER_METADATA_URI_V4: '',
|
75 | ECS_CONTAINER_METADATA_URI: '',
|
76 | HOSTNAME: '',
|
77 | KUBERNETES_SERVICE_HOST: '',
|
78 | NAMESPACE: '',
|
79 | OTEL_BSP_EXPORT_TIMEOUT: 30000,
|
80 | OTEL_BSP_MAX_EXPORT_BATCH_SIZE: 512,
|
81 | OTEL_BSP_MAX_QUEUE_SIZE: 2048,
|
82 | OTEL_BSP_SCHEDULE_DELAY: 5000,
|
83 | OTEL_BLRP_EXPORT_TIMEOUT: 30000,
|
84 | OTEL_BLRP_MAX_EXPORT_BATCH_SIZE: 512,
|
85 | OTEL_BLRP_MAX_QUEUE_SIZE: 2048,
|
86 | OTEL_BLRP_SCHEDULE_DELAY: 5000,
|
87 | OTEL_EXPORTER_JAEGER_AGENT_HOST: '',
|
88 | OTEL_EXPORTER_JAEGER_AGENT_PORT: 6832,
|
89 | OTEL_EXPORTER_JAEGER_ENDPOINT: '',
|
90 | OTEL_EXPORTER_JAEGER_PASSWORD: '',
|
91 | OTEL_EXPORTER_JAEGER_USER: '',
|
92 | OTEL_EXPORTER_OTLP_ENDPOINT: '',
|
93 | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: '',
|
94 | OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: '',
|
95 | OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: '',
|
96 | OTEL_EXPORTER_OTLP_HEADERS: '',
|
97 | OTEL_EXPORTER_OTLP_TRACES_HEADERS: '',
|
98 | OTEL_EXPORTER_OTLP_METRICS_HEADERS: '',
|
99 | OTEL_EXPORTER_OTLP_LOGS_HEADERS: '',
|
100 | OTEL_EXPORTER_OTLP_TIMEOUT: 10000,
|
101 | OTEL_EXPORTER_OTLP_TRACES_TIMEOUT: 10000,
|
102 | OTEL_EXPORTER_OTLP_METRICS_TIMEOUT: 10000,
|
103 | OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: 10000,
|
104 | OTEL_EXPORTER_ZIPKIN_ENDPOINT: 'http://localhost:9411/api/v2/spans',
|
105 | OTEL_LOG_LEVEL: api_1.DiagLogLevel.INFO,
|
106 | OTEL_NO_PATCH_MODULES: [],
|
107 | OTEL_PROPAGATORS: ['tracecontext', 'baggage'],
|
108 | OTEL_RESOURCE_ATTRIBUTES: '',
|
109 | OTEL_SERVICE_NAME: '',
|
110 | OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT: exports.DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT,
|
111 | OTEL_ATTRIBUTE_COUNT_LIMIT: exports.DEFAULT_ATTRIBUTE_COUNT_LIMIT,
|
112 | OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT: exports.DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT,
|
113 | OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT: exports.DEFAULT_ATTRIBUTE_COUNT_LIMIT,
|
114 | OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT: exports.DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT,
|
115 | OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT: exports.DEFAULT_ATTRIBUTE_COUNT_LIMIT,
|
116 | OTEL_SPAN_EVENT_COUNT_LIMIT: 128,
|
117 | OTEL_SPAN_LINK_COUNT_LIMIT: 128,
|
118 | OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT: exports.DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT,
|
119 | OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT: exports.DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT,
|
120 | OTEL_TRACES_EXPORTER: '',
|
121 | OTEL_TRACES_SAMPLER: sampling_1.TracesSamplerValues.ParentBasedAlwaysOn,
|
122 | OTEL_TRACES_SAMPLER_ARG: '',
|
123 | OTEL_LOGS_EXPORTER: '',
|
124 | OTEL_EXPORTER_OTLP_INSECURE: '',
|
125 | OTEL_EXPORTER_OTLP_TRACES_INSECURE: '',
|
126 | OTEL_EXPORTER_OTLP_METRICS_INSECURE: '',
|
127 | OTEL_EXPORTER_OTLP_LOGS_INSECURE: '',
|
128 | OTEL_EXPORTER_OTLP_CERTIFICATE: '',
|
129 | OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE: '',
|
130 | OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE: '',
|
131 | OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE: '',
|
132 | OTEL_EXPORTER_OTLP_COMPRESSION: '',
|
133 | OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: '',
|
134 | OTEL_EXPORTER_OTLP_METRICS_COMPRESSION: '',
|
135 | OTEL_EXPORTER_OTLP_LOGS_COMPRESSION: '',
|
136 | OTEL_EXPORTER_OTLP_CLIENT_KEY: '',
|
137 | OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY: '',
|
138 | OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY: '',
|
139 | OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY: '',
|
140 | OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: '',
|
141 | OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE: '',
|
142 | OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE: '',
|
143 | OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE: '',
|
144 | OTEL_EXPORTER_OTLP_PROTOCOL: 'http/protobuf',
|
145 | OTEL_EXPORTER_OTLP_TRACES_PROTOCOL: 'http/protobuf',
|
146 | OTEL_EXPORTER_OTLP_METRICS_PROTOCOL: 'http/protobuf',
|
147 | OTEL_EXPORTER_OTLP_LOGS_PROTOCOL: 'http/protobuf',
|
148 | OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: 'cumulative',
|
149 | };
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | function parseBoolean(key, environment, values) {
|
156 | if (typeof values[key] === 'undefined') {
|
157 | return;
|
158 | }
|
159 | const value = String(values[key]);
|
160 |
|
161 | environment[key] = value.toLowerCase() === 'true';
|
162 | }
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 | function parseNumber(name, environment, values, min = -Infinity, max = Infinity) {
|
172 | if (typeof values[name] !== 'undefined') {
|
173 | const value = Number(values[name]);
|
174 | if (!isNaN(value)) {
|
175 | if (value < min) {
|
176 | environment[name] = min;
|
177 | }
|
178 | else if (value > max) {
|
179 | environment[name] = max;
|
180 | }
|
181 | else {
|
182 | environment[name] = value;
|
183 | }
|
184 | }
|
185 | }
|
186 | }
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | function parseStringList(name, output, input, separator = DEFAULT_LIST_SEPARATOR) {
|
195 | const givenValue = input[name];
|
196 | if (typeof givenValue === 'string') {
|
197 | output[name] = givenValue.split(separator).map(v => v.trim());
|
198 | }
|
199 | }
|
200 |
|
201 | const logLevelMap = {
|
202 | ALL: api_1.DiagLogLevel.ALL,
|
203 | VERBOSE: api_1.DiagLogLevel.VERBOSE,
|
204 | DEBUG: api_1.DiagLogLevel.DEBUG,
|
205 | INFO: api_1.DiagLogLevel.INFO,
|
206 | WARN: api_1.DiagLogLevel.WARN,
|
207 | ERROR: api_1.DiagLogLevel.ERROR,
|
208 | NONE: api_1.DiagLogLevel.NONE,
|
209 | };
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | function setLogLevelFromEnv(key, environment, values) {
|
217 | const value = values[key];
|
218 | if (typeof value === 'string') {
|
219 | const theLevel = logLevelMap[value.toUpperCase()];
|
220 | if (theLevel != null) {
|
221 | environment[key] = theLevel;
|
222 | }
|
223 | }
|
224 | }
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | function parseEnvironment(values) {
|
230 | const environment = {};
|
231 | for (const env in exports.DEFAULT_ENVIRONMENT) {
|
232 | const key = env;
|
233 | switch (key) {
|
234 | case 'OTEL_LOG_LEVEL':
|
235 | setLogLevelFromEnv(key, environment, values);
|
236 | break;
|
237 | default:
|
238 | if (isEnvVarABoolean(key)) {
|
239 | parseBoolean(key, environment, values);
|
240 | }
|
241 | else if (isEnvVarANumber(key)) {
|
242 | parseNumber(key, environment, values);
|
243 | }
|
244 | else if (isEnvVarAList(key)) {
|
245 | parseStringList(key, environment, values);
|
246 | }
|
247 | else {
|
248 | const value = values[key];
|
249 | if (typeof value !== 'undefined' && value !== null) {
|
250 | environment[key] = String(value);
|
251 | }
|
252 | }
|
253 | }
|
254 | }
|
255 | return environment;
|
256 | }
|
257 | exports.parseEnvironment = parseEnvironment;
|
258 |
|
\ | No newline at end of file |