@depup/elastic-apm-node 4.15.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/NOTICE.md +442 -0
- package/README.md +48 -0
- package/changes.json +78 -0
- package/index.d.ts +398 -0
- package/index.js +11 -0
- package/lib/InflightEventSet.js +53 -0
- package/lib/activation-method.js +119 -0
- package/lib/agent.js +941 -0
- package/lib/apm-client/apm-client.js +313 -0
- package/lib/apm-client/http-apm-client/CHANGELOG.md +271 -0
- package/lib/apm-client/http-apm-client/README.md +485 -0
- package/lib/apm-client/http-apm-client/central-config.js +41 -0
- package/lib/apm-client/http-apm-client/container-info.js +111 -0
- package/lib/apm-client/http-apm-client/detect-hostname.js +96 -0
- package/lib/apm-client/http-apm-client/index.js +1975 -0
- package/lib/apm-client/http-apm-client/logging.js +31 -0
- package/lib/apm-client/http-apm-client/ndjson.js +20 -0
- package/lib/apm-client/http-apm-client/truncate.js +434 -0
- package/lib/apm-client/noop-apm-client.js +73 -0
- package/lib/async-hooks-polyfill.js +58 -0
- package/lib/cloud-metadata/aws.js +175 -0
- package/lib/cloud-metadata/azure.js +123 -0
- package/lib/cloud-metadata/callback-coordination.js +159 -0
- package/lib/cloud-metadata/gcp.js +133 -0
- package/lib/cloud-metadata/index.js +175 -0
- package/lib/config/config.js +458 -0
- package/lib/config/normalizers.js +701 -0
- package/lib/config/schema.js +1007 -0
- package/lib/constants.js +35 -0
- package/lib/errors.js +303 -0
- package/lib/filters/sanitize-field-names.js +69 -0
- package/lib/http-request.js +249 -0
- package/lib/instrumentation/azure-functions.js +519 -0
- package/lib/instrumentation/context.js +56 -0
- package/lib/instrumentation/dropped-spans-stats.js +112 -0
- package/lib/instrumentation/elasticsearch-shared.js +63 -0
- package/lib/instrumentation/express-utils.js +91 -0
- package/lib/instrumentation/generic-span.js +322 -0
- package/lib/instrumentation/http-shared.js +424 -0
- package/lib/instrumentation/ids.js +39 -0
- package/lib/instrumentation/index.js +1127 -0
- package/lib/instrumentation/modules/@apollo/server.js +30 -0
- package/lib/instrumentation/modules/@aws-sdk/client-dynamodb.js +143 -0
- package/lib/instrumentation/modules/@aws-sdk/client-s3.js +230 -0
- package/lib/instrumentation/modules/@aws-sdk/client-sns.js +197 -0
- package/lib/instrumentation/modules/@aws-sdk/client-sqs.js +336 -0
- package/lib/instrumentation/modules/@elastic/elasticsearch.js +343 -0
- package/lib/instrumentation/modules/@hapi/hapi.js +221 -0
- package/lib/instrumentation/modules/@opentelemetry/api.js +86 -0
- package/lib/instrumentation/modules/@opentelemetry/sdk-metrics.js +79 -0
- package/lib/instrumentation/modules/@redis/client/dist/lib/client/commands-queue.js +178 -0
- package/lib/instrumentation/modules/@redis/client/dist/lib/client/index.js +49 -0
- package/lib/instrumentation/modules/@smithy/smithy-client.js +198 -0
- package/lib/instrumentation/modules/_lambda-handler.js +40 -0
- package/lib/instrumentation/modules/apollo-server-core.js +49 -0
- package/lib/instrumentation/modules/aws-sdk/dynamodb.js +155 -0
- package/lib/instrumentation/modules/aws-sdk/s3.js +184 -0
- package/lib/instrumentation/modules/aws-sdk/sns.js +232 -0
- package/lib/instrumentation/modules/aws-sdk/sqs.js +361 -0
- package/lib/instrumentation/modules/aws-sdk.js +76 -0
- package/lib/instrumentation/modules/bluebird.js +93 -0
- package/lib/instrumentation/modules/cassandra-driver.js +280 -0
- package/lib/instrumentation/modules/elasticsearch.js +191 -0
- package/lib/instrumentation/modules/express-graphql.js +66 -0
- package/lib/instrumentation/modules/express-queue.js +28 -0
- package/lib/instrumentation/modules/express.js +162 -0
- package/lib/instrumentation/modules/fastify.js +172 -0
- package/lib/instrumentation/modules/finalhandler.js +41 -0
- package/lib/instrumentation/modules/generic-pool.js +85 -0
- package/lib/instrumentation/modules/graphql.js +256 -0
- package/lib/instrumentation/modules/handlebars.js +22 -0
- package/lib/instrumentation/modules/http.js +112 -0
- package/lib/instrumentation/modules/http2.js +320 -0
- package/lib/instrumentation/modules/https.js +68 -0
- package/lib/instrumentation/modules/ioredis.js +94 -0
- package/lib/instrumentation/modules/jade.js +18 -0
- package/lib/instrumentation/modules/kafkajs.js +476 -0
- package/lib/instrumentation/modules/knex.js +91 -0
- package/lib/instrumentation/modules/koa-router.js +74 -0
- package/lib/instrumentation/modules/koa.js +15 -0
- package/lib/instrumentation/modules/memcached.js +99 -0
- package/lib/instrumentation/modules/mimic-response.js +45 -0
- package/lib/instrumentation/modules/mongodb/lib/cmap/connection_pool.js +40 -0
- package/lib/instrumentation/modules/mongodb-core.js +206 -0
- package/lib/instrumentation/modules/mongodb.js +259 -0
- package/lib/instrumentation/modules/mysql.js +200 -0
- package/lib/instrumentation/modules/mysql2.js +140 -0
- package/lib/instrumentation/modules/pg.js +148 -0
- package/lib/instrumentation/modules/pug.js +18 -0
- package/lib/instrumentation/modules/redis.js +176 -0
- package/lib/instrumentation/modules/restify.js +52 -0
- package/lib/instrumentation/modules/tedious.js +159 -0
- package/lib/instrumentation/modules/undici.js +270 -0
- package/lib/instrumentation/modules/ws.js +59 -0
- package/lib/instrumentation/noop-transaction.js +81 -0
- package/lib/instrumentation/run-context/AbstractRunContextManager.js +215 -0
- package/lib/instrumentation/run-context/AsyncHooksRunContextManager.js +106 -0
- package/lib/instrumentation/run-context/AsyncLocalStorageRunContextManager.js +73 -0
- package/lib/instrumentation/run-context/BasicRunContextManager.js +82 -0
- package/lib/instrumentation/run-context/RunContext.js +151 -0
- package/lib/instrumentation/run-context/index.js +23 -0
- package/lib/instrumentation/shimmer.js +123 -0
- package/lib/instrumentation/span-compression.js +239 -0
- package/lib/instrumentation/span.js +621 -0
- package/lib/instrumentation/template-shared.js +43 -0
- package/lib/instrumentation/timer.js +84 -0
- package/lib/instrumentation/transaction.js +571 -0
- package/lib/lambda.js +992 -0
- package/lib/load-source-map.js +100 -0
- package/lib/logging.js +212 -0
- package/lib/metrics/index.js +92 -0
- package/lib/metrics/platforms/generic/index.js +40 -0
- package/lib/metrics/platforms/generic/process-cpu.js +22 -0
- package/lib/metrics/platforms/generic/process-top.js +157 -0
- package/lib/metrics/platforms/generic/stats.js +34 -0
- package/lib/metrics/platforms/generic/system-cpu.js +51 -0
- package/lib/metrics/platforms/linux/index.js +19 -0
- package/lib/metrics/platforms/linux/stats.js +213 -0
- package/lib/metrics/queue.js +90 -0
- package/lib/metrics/registry.js +52 -0
- package/lib/metrics/reporter.js +119 -0
- package/lib/metrics/runtime.js +77 -0
- package/lib/middleware/connect.js +16 -0
- package/lib/opentelemetry-bridge/OTelBridgeNonRecordingSpan.js +150 -0
- package/lib/opentelemetry-bridge/OTelBridgeRunContext.js +124 -0
- package/lib/opentelemetry-bridge/OTelContextManager.js +82 -0
- package/lib/opentelemetry-bridge/OTelSpan.js +344 -0
- package/lib/opentelemetry-bridge/OTelTracer.js +201 -0
- package/lib/opentelemetry-bridge/OTelTracerProvider.js +25 -0
- package/lib/opentelemetry-bridge/README.md +244 -0
- package/lib/opentelemetry-bridge/index.js +15 -0
- package/lib/opentelemetry-bridge/oblog.js +23 -0
- package/lib/opentelemetry-bridge/opentelemetry-core-mini/README.md +3 -0
- package/lib/opentelemetry-bridge/opentelemetry-core-mini/internal/validators.js +52 -0
- package/lib/opentelemetry-bridge/opentelemetry-core-mini/trace/TraceState.js +109 -0
- package/lib/opentelemetry-bridge/otelutils.js +99 -0
- package/lib/opentelemetry-bridge/setup.js +76 -0
- package/lib/opentelemetry-metrics/ElasticApmMetricExporter.js +285 -0
- package/lib/opentelemetry-metrics/index.js +50 -0
- package/lib/parsers.js +225 -0
- package/lib/propwrap.js +147 -0
- package/lib/stacktraces.js +537 -0
- package/lib/symbols.js +15 -0
- package/lib/tracecontext/index.js +118 -0
- package/lib/tracecontext/traceparent.js +185 -0
- package/lib/tracecontext/tracestate.js +388 -0
- package/lib/wildcard-matcher.js +52 -0
- package/loader.mjs +7 -0
- package/package.json +299 -0
- package/start.d.ts +8 -0
- package/start.js +29 -0
- package/types/aws-lambda.d.ts +98 -0
- package/types/connect.d.ts +23 -0
|
@@ -0,0 +1,1007 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and other contributors where applicable.
|
|
3
|
+
* Licensed under the BSD 2-Clause License; you may not use this file except in
|
|
4
|
+
* compliance with the BSD 2-Clause License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const { URL } = require('url');
|
|
13
|
+
|
|
14
|
+
const AGENT_VERSION = require('../../package.json').version;
|
|
15
|
+
const { REDACTED } = require('../constants');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {Object} OptionDefinition
|
|
19
|
+
* @property {string} name the name of the configuration option
|
|
20
|
+
* @property {keyof TypeNormalizers} configType the type of the configuration option
|
|
21
|
+
* @property {any} defaultValue the default value of the property or undefined
|
|
22
|
+
* @property {any} [environmentValue] defined if value is provided via environment var
|
|
23
|
+
* @property {any} [startValue] defined if value is provided via `Agent.start()` API
|
|
24
|
+
* @property {any} [fileValue] defined if value is provided via config file
|
|
25
|
+
* @property {'environment' | 'start' | 'file'} [source] defined value comes from any source keeping its priorities (env, star, file, default)
|
|
26
|
+
* @property {string} [envVar] the name of the environment varaiable associated with the option
|
|
27
|
+
* @property {string} [envDeprecatedVar] the name of the deprecated environment varaiable associated with the option
|
|
28
|
+
* @property {string} [centralConfigName] name of option in central configuration
|
|
29
|
+
* @property {string} [crossAgentName] name of the same option in other agents
|
|
30
|
+
* @property {(v: any) => any} [redactFn] if passed the value will be redacted with it on serialization (preamble...)
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// TODO: options with `crossAgentName` property
|
|
34
|
+
// check for more cross agent config option names in
|
|
35
|
+
// https://docs.google.com/spreadsheets/d/1JJjZotapacA3FkHc2sv_0wiChILi3uKnkwLTjtBmxwU/edit#gid=0
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @type Array<OptionDefinition>
|
|
39
|
+
*/
|
|
40
|
+
const CONFIG_SCHEMA = [
|
|
41
|
+
{
|
|
42
|
+
name: 'abortedErrorThreshold',
|
|
43
|
+
configType: 'durationSeconds',
|
|
44
|
+
defaultValue: '25s',
|
|
45
|
+
envVar: 'ELASTIC_APM_ABORTED_ERROR_THRESHOLD',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'active',
|
|
49
|
+
configType: 'boolean',
|
|
50
|
+
defaultValue: true,
|
|
51
|
+
envVar: 'ELASTIC_APM_ACTIVE',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'addPatch',
|
|
55
|
+
configType: 'stringKeyValuePairs',
|
|
56
|
+
defaultValue: undefined,
|
|
57
|
+
envVar: 'ELASTIC_APM_ADD_PATCH',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'apiRequestSize',
|
|
61
|
+
configType: 'byte',
|
|
62
|
+
defaultValue: '768kb',
|
|
63
|
+
envVar: 'ELASTIC_APM_API_REQUEST_SIZE',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'apiRequestTime',
|
|
67
|
+
configType: 'durationSeconds',
|
|
68
|
+
defaultValue: '10s',
|
|
69
|
+
envVar: 'ELASTIC_APM_API_REQUEST_TIME',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'breakdownMetrics',
|
|
73
|
+
configType: 'boolean',
|
|
74
|
+
defaultValue: true,
|
|
75
|
+
envVar: 'ELASTIC_APM_BREAKDOWN_METRICS',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'captureBody',
|
|
79
|
+
configType: 'select(off,all,errors,transactions)',
|
|
80
|
+
defaultValue: 'off',
|
|
81
|
+
envVar: 'ELASTIC_APM_CAPTURE_BODY',
|
|
82
|
+
centralConfigName: 'capture_body',
|
|
83
|
+
crossAgentName: 'capture_body',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'captureErrorLogStackTraces',
|
|
87
|
+
configType: 'select(messages,always)',
|
|
88
|
+
defaultValue: 'messages',
|
|
89
|
+
envVar: 'ELASTIC_APM_CAPTURE_ERROR_LOG_STACK_TRACES',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'captureExceptions',
|
|
93
|
+
configType: 'boolean',
|
|
94
|
+
defaultValue: true,
|
|
95
|
+
envVar: 'ELASTIC_APM_CAPTURE_EXCEPTIONS',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'captureHeaders',
|
|
99
|
+
configType: 'boolean',
|
|
100
|
+
defaultValue: true,
|
|
101
|
+
envVar: 'ELASTIC_APM_CAPTURE_HEADERS',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'centralConfig',
|
|
105
|
+
configType: 'boolean',
|
|
106
|
+
defaultValue: true,
|
|
107
|
+
envVar: 'ELASTIC_APM_CENTRAL_CONFIG',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'cloudProvider',
|
|
111
|
+
configType: 'select(auto,gcp,azure,aws,none)',
|
|
112
|
+
defaultValue: 'auto',
|
|
113
|
+
envVar: 'ELASTIC_APM_CLOUD_PROVIDER',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'containerId',
|
|
117
|
+
configType: 'string',
|
|
118
|
+
defaultValue: undefined,
|
|
119
|
+
envVar: 'ELASTIC_APM_CONTAINER_ID',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: 'contextPropagationOnly',
|
|
123
|
+
configType: 'boolean',
|
|
124
|
+
defaultValue: false,
|
|
125
|
+
envVar: 'ELASTIC_APM_CONTEXT_PROPAGATION_ONLY',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: 'customMetricsHistogramBoundaries',
|
|
129
|
+
configType: 'sortedNumberArray',
|
|
130
|
+
// Exponential powers-of-2 bucket boundaries, rounded to 6 significant figures.
|
|
131
|
+
// 2**N for N in [-8, -7.5, -7, ..., 16, 16.5, 17]
|
|
132
|
+
// https://github.com/elastic/apm/blob/main/specs/agents/metrics-otel.md#histogram-aggregation
|
|
133
|
+
defaultValue: [
|
|
134
|
+
0.00390625, 0.00552427, 0.0078125, 0.0110485, 0.015625, 0.0220971,
|
|
135
|
+
0.03125, 0.0441942, 0.0625, 0.0883883, 0.125, 0.176777, 0.25, 0.353553,
|
|
136
|
+
0.5, 0.707107, 1, 1.41421, 2, 2.82843, 4, 5.65685, 8, 11.3137, 16,
|
|
137
|
+
22.6274, 32, 45.2548, 64, 90.5097, 128, 181.019, 256, 362.039, 512,
|
|
138
|
+
724.077, 1024, 1448.15, 2048, 2896.31, 4096, 5792.62, 8192, 11585.2,
|
|
139
|
+
16384, 23170.5, 32768, 46341, 65536, 92681.9, 131072,
|
|
140
|
+
],
|
|
141
|
+
envVar: 'ELASTIC_APM_CUSTOM_METRICS_HISTOGRAM_BOUNDARIES',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: 'disableInstrumentations',
|
|
145
|
+
configType: 'stringArray',
|
|
146
|
+
defaultValue: [],
|
|
147
|
+
envVar: 'ELASTIC_APM_DISABLE_INSTRUMENTATIONS',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: 'disableMetrics',
|
|
151
|
+
configType: 'stringArray',
|
|
152
|
+
defaultValue: [],
|
|
153
|
+
envVar: 'ELASTIC_APM_DISABLE_METRICS',
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'disableMetricsRegExp',
|
|
157
|
+
configType: 'wildcardArray',
|
|
158
|
+
defaultValue: [],
|
|
159
|
+
deps: ['disableMetrics'],
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'disableSend',
|
|
163
|
+
configType: 'boolean',
|
|
164
|
+
defaultValue: false,
|
|
165
|
+
envVar: 'ELASTIC_APM_DISABLE_SEND',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'elasticsearchCaptureBodyUrls',
|
|
169
|
+
configType: 'stringArray',
|
|
170
|
+
defaultValue: [
|
|
171
|
+
'*/_search',
|
|
172
|
+
'*/_search/template',
|
|
173
|
+
'*/_msearch',
|
|
174
|
+
'*/_msearch/template',
|
|
175
|
+
'*/_async_search',
|
|
176
|
+
'*/_count',
|
|
177
|
+
'*/_sql',
|
|
178
|
+
'*/_eql/search',
|
|
179
|
+
],
|
|
180
|
+
envVar: 'ELASTIC_APM_ELASTICSEARCH_CAPTURE_BODY_URLS',
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'elasticsearchCaptureBodyUrlsRegExp',
|
|
184
|
+
configType: 'wildcardArray',
|
|
185
|
+
defaultValue: [],
|
|
186
|
+
deps: ['elasticsearchCaptureBodyUrls'],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'environment',
|
|
190
|
+
configType: 'string',
|
|
191
|
+
defaultValue: process.env.NODE_ENV || 'development',
|
|
192
|
+
envVar: 'ELASTIC_APM_ENVIRONMENT',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'errorOnAbortedRequests',
|
|
196
|
+
configType: 'boolean',
|
|
197
|
+
defaultValue: false,
|
|
198
|
+
envVar: 'ELASTIC_APM_ERROR_ON_ABORTED_REQUESTS',
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: 'exitSpanMinDuration',
|
|
202
|
+
configType: 'durationMilliseconds',
|
|
203
|
+
defaultValue: '0ms',
|
|
204
|
+
envVar: 'ELASTIC_APM_EXIT_SPAN_MIN_DURATION',
|
|
205
|
+
centralConfigName: 'exit_span_min_duration',
|
|
206
|
+
crossAgentName: 'exit_span_min_duration',
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: 'globalLabels',
|
|
210
|
+
configType: 'stringKeyValuePairs',
|
|
211
|
+
defaultValue: undefined,
|
|
212
|
+
envVar: 'ELASTIC_APM_GLOBAL_LABELS',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: 'ignoreMessageQueues',
|
|
216
|
+
configType: 'stringArray',
|
|
217
|
+
defaultValue: [],
|
|
218
|
+
envVar: 'ELASTIC_APM_IGNORE_MESSAGE_QUEUES',
|
|
219
|
+
centralConfigName: 'ignore_message_queues',
|
|
220
|
+
crossAgentName: 'ignore_message_queues',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: 'ignoreMessageQueuesRegExp',
|
|
224
|
+
configType: 'wildcardArray',
|
|
225
|
+
defaultValue: [],
|
|
226
|
+
deps: ['ignoreMessageQueues'],
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: 'instrument',
|
|
230
|
+
configType: 'boolean',
|
|
231
|
+
defaultValue: true,
|
|
232
|
+
envVar: 'ELASTIC_APM_INSTRUMENT',
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: 'instrumentIncomingHTTPRequests',
|
|
236
|
+
configType: 'boolean',
|
|
237
|
+
defaultValue: true,
|
|
238
|
+
envVar: 'ELASTIC_APM_INSTRUMENT_INCOMING_HTTP_REQUESTS',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'kubernetesNamespace',
|
|
242
|
+
configType: 'string',
|
|
243
|
+
defaultValue: undefined,
|
|
244
|
+
envVar: 'KUBERNETES_NAMESPACE',
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: 'kubernetesNodeName',
|
|
248
|
+
configType: 'string',
|
|
249
|
+
defaultValue: undefined,
|
|
250
|
+
envVar: 'KUBERNETES_NODE_NAME',
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: 'kubernetesPodName',
|
|
254
|
+
configType: 'string',
|
|
255
|
+
defaultValue: undefined,
|
|
256
|
+
envVar: 'KUBERNETES_POD_NAME',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: 'kubernetesPodUID',
|
|
260
|
+
configType: 'string',
|
|
261
|
+
defaultValue: undefined,
|
|
262
|
+
envVar: 'KUBERNETES_POD_UID',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: 'logLevel',
|
|
266
|
+
configType: 'select(debug,info,warning,error,critical,off,trace)',
|
|
267
|
+
defaultValue: 'info',
|
|
268
|
+
envVar: 'ELASTIC_APM_LOG_LEVEL',
|
|
269
|
+
centralConfigName: 'log_level',
|
|
270
|
+
crossAgentName: 'log_level',
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: 'longFieldMaxLength',
|
|
274
|
+
configType: 'number',
|
|
275
|
+
defaultValue: 10000,
|
|
276
|
+
envVar: 'ELASTIC_APM_LONG_FIELD_MAX_LENGTH',
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: 'maxQueueSize',
|
|
280
|
+
configType: 'number',
|
|
281
|
+
// Rough equivalent of the Java Agent's max_queue_size:
|
|
282
|
+
// https://www.elastic.co/guide/en/apm/agent/java/current/config-reporter.html#config-max-queue-size
|
|
283
|
+
defaultValue: 1024,
|
|
284
|
+
envVar: 'ELASTIC_APM_MAX_QUEUE_SIZE',
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: 'metricsInterval',
|
|
288
|
+
configType: 'durationSeconds',
|
|
289
|
+
defaultValue: '30s',
|
|
290
|
+
envVar: 'ELASTIC_APM_METRICS_INTERVAL',
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: 'metricsLimit',
|
|
294
|
+
configType: 'number',
|
|
295
|
+
defaultValue: 1000,
|
|
296
|
+
envVar: 'ELASTIC_APM_METRICS_LIMIT',
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
name: 'opentelemetryBridgeEnabled',
|
|
300
|
+
configType: 'boolean',
|
|
301
|
+
defaultValue: false,
|
|
302
|
+
envVar: 'ELASTIC_APM_OPENTELEMETRY_BRIDGE_ENABLED',
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: 'sanitizeFieldNames',
|
|
306
|
+
configType: 'stringArray',
|
|
307
|
+
// These patterns are specified in the shared APM specs:
|
|
308
|
+
// https://github.com/elastic/apm/blob/main/specs/agents/sanitization.md
|
|
309
|
+
defaultValue: [
|
|
310
|
+
'password',
|
|
311
|
+
'passwd',
|
|
312
|
+
'pwd',
|
|
313
|
+
'secret',
|
|
314
|
+
'*key',
|
|
315
|
+
'*token*',
|
|
316
|
+
'*session*',
|
|
317
|
+
'*credit*',
|
|
318
|
+
'*card*',
|
|
319
|
+
'*auth*',
|
|
320
|
+
'set-cookie',
|
|
321
|
+
'*principal*',
|
|
322
|
+
// These are default patterns only in the Node.js APM agent, historically
|
|
323
|
+
// from when the "is-secret" dependency was used.
|
|
324
|
+
'pw',
|
|
325
|
+
'pass',
|
|
326
|
+
'connect.sid',
|
|
327
|
+
// Additional ones added to the Node.js APM agent.
|
|
328
|
+
'cookie', // The "Cookie" HTTP request header is often sensitive.
|
|
329
|
+
],
|
|
330
|
+
envVar: 'ELASTIC_APM_SANITIZE_FIELD_NAMES',
|
|
331
|
+
centralConfigName: 'sanitize_field_names',
|
|
332
|
+
crossAgentName: 'sanitize_field_names',
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
name: 'sanitizeFieldNamesRegExp',
|
|
336
|
+
configType: 'wildcardArray',
|
|
337
|
+
defaultValue: [],
|
|
338
|
+
deps: ['sanitizeFieldNames'],
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: 'serviceNodeName',
|
|
342
|
+
configType: 'string',
|
|
343
|
+
defaultValue: undefined,
|
|
344
|
+
envVar: 'ELASTIC_APM_SERVICE_NODE_NAME',
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: 'serverTimeout',
|
|
348
|
+
configType: 'durationSeconds',
|
|
349
|
+
defaultValue: '30s',
|
|
350
|
+
envVar: 'ELASTIC_APM_SERVER_TIMEOUT',
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: 'serverUrl',
|
|
354
|
+
configType: 'url',
|
|
355
|
+
defaultValue: 'http://127.0.0.1:8200',
|
|
356
|
+
envVar: 'ELASTIC_APM_SERVER_URL',
|
|
357
|
+
crossAgentName: 'server_url',
|
|
358
|
+
redactFn: sanitizeUrl,
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
name: 'sourceLinesErrorAppFrames',
|
|
362
|
+
configType: 'number',
|
|
363
|
+
defaultValue: 5,
|
|
364
|
+
envVar: 'ELASTIC_APM_SOURCE_LINES_ERROR_APP_FRAMES',
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
name: 'sourceLinesErrorLibraryFrames',
|
|
368
|
+
configType: 'number',
|
|
369
|
+
defaultValue: 5,
|
|
370
|
+
envVar: 'ELASTIC_APM_SOURCE_LINES_ERROR_LIBRARY_FRAMES',
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: 'sourceLinesSpanAppFrames',
|
|
374
|
+
configType: 'number',
|
|
375
|
+
defaultValue: 0,
|
|
376
|
+
envVar: 'ELASTIC_APM_SOURCE_LINES_SPAN_APP_FRAMES',
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
name: 'sourceLinesSpanLibraryFrames',
|
|
380
|
+
configType: 'number',
|
|
381
|
+
defaultValue: 0,
|
|
382
|
+
envVar: 'ELASTIC_APM_SOURCE_LINES_SPAN_LIBRARY_FRAMES',
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
name: 'spanCompressionEnabled',
|
|
386
|
+
configType: 'boolean',
|
|
387
|
+
defaultValue: true,
|
|
388
|
+
envVar: 'ELASTIC_APM_SPAN_COMPRESSION_ENABLED',
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
name: 'spanCompressionExactMatchMaxDuration',
|
|
392
|
+
configType: 'durationCompression',
|
|
393
|
+
defaultValue: '50ms',
|
|
394
|
+
envVar: 'ELASTIC_APM_SPAN_COMPRESSION_EXACT_MATCH_MAX_DURATION',
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: 'spanCompressionSameKindMaxDuration',
|
|
398
|
+
configType: 'durationCompression',
|
|
399
|
+
defaultValue: '0ms',
|
|
400
|
+
envVar: 'ELASTIC_APM_SPAN_COMPRESSION_SAME_KIND_MAX_DURATION',
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
name: 'stackTraceLimit',
|
|
404
|
+
configType: 'number',
|
|
405
|
+
defaultValue: 50,
|
|
406
|
+
envVar: 'ELASTIC_APM_STACK_TRACE_LIMIT',
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
name: 'traceContinuationStrategy',
|
|
410
|
+
configType: 'select(continue,restart,external)',
|
|
411
|
+
defaultValue: 'continue',
|
|
412
|
+
envVar: 'ELASTIC_APM_TRACE_CONTINUATION_STRATEGY',
|
|
413
|
+
centralConfigName: 'trace_continuation_strategy',
|
|
414
|
+
crossAgentName: 'trace_continuation_strategy',
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
name: 'transactionIgnoreUrls',
|
|
418
|
+
configType: 'stringArray',
|
|
419
|
+
defaultValue: [],
|
|
420
|
+
envVar: 'ELASTIC_APM_TRANSACTION_IGNORE_URLS',
|
|
421
|
+
centralConfigName: 'transaction_ignore_urls',
|
|
422
|
+
crossAgentName: 'transaction_ignore_urls',
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
name: 'transactionIgnoreUrlRegExp',
|
|
426
|
+
configType: 'wildcardArray',
|
|
427
|
+
defaultValue: [],
|
|
428
|
+
deps: ['transactionIgnoreUrls'],
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
name: 'transactionMaxSpans',
|
|
432
|
+
configType: 'numberInfinity',
|
|
433
|
+
defaultValue: 500,
|
|
434
|
+
envVar: 'ELASTIC_APM_TRANSACTION_MAX_SPANS',
|
|
435
|
+
centralConfigName: 'transaction_max_spans',
|
|
436
|
+
crossAgentName: 'transaction_max_spans',
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
name: 'transactionSampleRate',
|
|
440
|
+
configType: 'sampleRate',
|
|
441
|
+
defaultValue: 1,
|
|
442
|
+
envVar: 'ELASTIC_APM_TRANSACTION_SAMPLE_RATE',
|
|
443
|
+
centralConfigName: 'transaction_sample_rate',
|
|
444
|
+
crossAgentName: 'transaction_sample_rate',
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: 'useElasticTraceparentHeader',
|
|
448
|
+
configType: 'boolean',
|
|
449
|
+
defaultValue: false,
|
|
450
|
+
envVar: 'ELASTIC_APM_USE_ELASTIC_TRACEPARENT_HEADER',
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
name: 'usePathAsTransactionName',
|
|
454
|
+
configType: 'boolean',
|
|
455
|
+
defaultValue: false,
|
|
456
|
+
envVar: 'ELASTIC_APM_USE_PATH_AS_TRANSACTION_NAME',
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
name: 'verifyServerCert',
|
|
460
|
+
configType: 'boolean',
|
|
461
|
+
defaultValue: true,
|
|
462
|
+
envVar: 'ELASTIC_APM_VERIFY_SERVER_CERT',
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
name: 'errorMessageMaxLength',
|
|
466
|
+
configType: 'byte',
|
|
467
|
+
defaultValue: undefined,
|
|
468
|
+
envVar: 'ELASTIC_APM_ERROR_MESSAGE_MAX_LENGTH',
|
|
469
|
+
deprecated: 'Deprecated in: v3.21.0, use longFieldMaxLength',
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
name: 'spanStackTraceMinDuration',
|
|
473
|
+
configType: 'durationMillisecondsNegative',
|
|
474
|
+
// 'spanStackTraceMinDuration' is explicitly *not* defined in DEFAULTS
|
|
475
|
+
// because normalizeSpanStackTraceMinDuration() needs to know if a value
|
|
476
|
+
// was provided by the user.
|
|
477
|
+
defaultValue: undefined,
|
|
478
|
+
envVar: 'ELASTIC_APM_SPAN_STACK_TRACE_MIN_DURATION',
|
|
479
|
+
centralConfigName: 'span_stack_trace_min_duration',
|
|
480
|
+
crossAgentName: 'span_stack_trace_min_duration',
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
name: 'apiKey',
|
|
484
|
+
configType: 'string',
|
|
485
|
+
defaultValue: undefined,
|
|
486
|
+
envVar: 'ELASTIC_APM_API_KEY',
|
|
487
|
+
crossAgentName: 'api_key',
|
|
488
|
+
redactFn: () => REDACTED,
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
name: 'captureSpanStackTraces',
|
|
492
|
+
configType: 'boolean',
|
|
493
|
+
defaultValue: undefined,
|
|
494
|
+
envVar: 'ELASTIC_APM_CAPTURE_SPAN_STACK_TRACES',
|
|
495
|
+
deprecated: 'Deprecated in: v3.30.0, use spanStackTraceMinDuration',
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
name: 'contextManager',
|
|
499
|
+
configType: 'select(asynclocalstorage,asynchooks)',
|
|
500
|
+
// 'contextManager' is explicitly *not* defined in DEFAULTS because
|
|
501
|
+
// normalizeContextManager() needs to know if a value was provided by the
|
|
502
|
+
// user.
|
|
503
|
+
defaultValue: undefined,
|
|
504
|
+
envVar: 'ELASTIC_APM_CONTEXT_MANAGER',
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
name: 'frameworkName',
|
|
508
|
+
configType: 'string',
|
|
509
|
+
defaultValue: undefined,
|
|
510
|
+
envVar: 'ELASTIC_APM_FRAMEWORK_NAME',
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: 'frameworkVersion',
|
|
514
|
+
configType: 'string',
|
|
515
|
+
defaultValue: undefined,
|
|
516
|
+
envVar: 'ELASTIC_APM_FRAMEWORK_VERSION',
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
name: 'hostname',
|
|
520
|
+
configType: 'string',
|
|
521
|
+
defaultValue: undefined,
|
|
522
|
+
envVar: 'ELASTIC_APM_HOSTNAME',
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: 'payloadLogFile',
|
|
526
|
+
configType: 'string',
|
|
527
|
+
defaultValue: undefined,
|
|
528
|
+
envVar: 'ELASTIC_APM_PAYLOAD_LOG_FILE',
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
name: 'serverCaCertFile',
|
|
532
|
+
configType: 'string',
|
|
533
|
+
defaultValue: undefined,
|
|
534
|
+
envVar: 'ELASTIC_APM_SERVER_CA_CERT_FILE',
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
name: 'secretToken',
|
|
538
|
+
configType: 'string',
|
|
539
|
+
defaultValue: undefined,
|
|
540
|
+
envVar: 'ELASTIC_APM_SECRET_TOKEN',
|
|
541
|
+
crossAgentName: 'secret_token',
|
|
542
|
+
redactFn: () => REDACTED,
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
name: 'serviceName',
|
|
546
|
+
configType: 'string',
|
|
547
|
+
defaultValue: undefined,
|
|
548
|
+
envVar: 'ELASTIC_APM_SERVICE_NAME',
|
|
549
|
+
crossAgentName: 'service_name',
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
name: 'serviceVersion',
|
|
553
|
+
configType: 'string',
|
|
554
|
+
defaultValue: undefined,
|
|
555
|
+
envVar: 'ELASTIC_APM_SERVICE_VERSION',
|
|
556
|
+
crossAgentName: 'service_version',
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
name: 'spanFramesMinDuration',
|
|
560
|
+
configType: 'durationSecondsNegative',
|
|
561
|
+
defaultValue: undefined,
|
|
562
|
+
envVar: 'ELASTIC_APM_SPAN_FRAMES_MIN_DURATION',
|
|
563
|
+
deprecated: 'Deprecated in: v3.30.0, use spanStackTraceMinDuration',
|
|
564
|
+
},
|
|
565
|
+
{ name: 'ignoreUrls', configType: 'stringArray', defaultValue: undefined },
|
|
566
|
+
{
|
|
567
|
+
name: 'ignoreUrlRegExp',
|
|
568
|
+
configType: 'wildcardArray',
|
|
569
|
+
defaultValue: [],
|
|
570
|
+
deps: ['ignoreUrls'],
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
name: 'ignoreUrlStr',
|
|
574
|
+
configType: 'wildcardArray',
|
|
575
|
+
defaultValue: [],
|
|
576
|
+
deps: ['ignoreUrls'],
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
name: 'ignoreUserAgents',
|
|
580
|
+
configType: 'stringArray',
|
|
581
|
+
defaultValue: undefined,
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
name: 'ignoreUserAgentRegExp',
|
|
585
|
+
configType: 'wildcardArray',
|
|
586
|
+
defaultValue: [],
|
|
587
|
+
deps: ['ignoreUserAgents'],
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
name: 'ignoreUserAgentStr',
|
|
591
|
+
configType: 'wildcardArray',
|
|
592
|
+
defaultValue: [],
|
|
593
|
+
deps: ['ignoreUserAgents'],
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
name: 'apmClientHeaders',
|
|
597
|
+
configType: 'stringKeyValuePairs',
|
|
598
|
+
defaultValue: undefined,
|
|
599
|
+
envVar: 'ELASTIC_APM_APM_CLIENT_HEADERS',
|
|
600
|
+
},
|
|
601
|
+
// Special options that
|
|
602
|
+
// - may afect the whole config
|
|
603
|
+
// - change the behavior of thelogger
|
|
604
|
+
// - are for testing or internal use
|
|
605
|
+
{
|
|
606
|
+
name: 'configFile',
|
|
607
|
+
configType: 'string',
|
|
608
|
+
defaultValue: 'elastic-apm-node.js',
|
|
609
|
+
envVar: 'ELASTIC_APM_CONFIG_FILE',
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
name: 'logger',
|
|
613
|
+
configType: 'logger',
|
|
614
|
+
defaultValue: undefined,
|
|
615
|
+
envVar: 'ELASTIC_APM_LOGGER',
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
name: 'transport',
|
|
619
|
+
configType: 'function',
|
|
620
|
+
defaultValue: undefined,
|
|
621
|
+
internal: true,
|
|
622
|
+
},
|
|
623
|
+
];
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Retuns an object with th default values for all config options
|
|
627
|
+
* @returns {Record<string,any>}
|
|
628
|
+
*/
|
|
629
|
+
function getDefaultOptions() {
|
|
630
|
+
return CONFIG_SCHEMA.reduce((acc, def) => {
|
|
631
|
+
if (typeof def.defaultValue !== 'undefined') {
|
|
632
|
+
acc[def.name] = def.defaultValue;
|
|
633
|
+
}
|
|
634
|
+
return acc;
|
|
635
|
+
}, {});
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Retuns an object with the values of config options defined set
|
|
640
|
+
* in the environment
|
|
641
|
+
* @returns {Record<string,any>}
|
|
642
|
+
*/
|
|
643
|
+
function getEnvironmentOptions() {
|
|
644
|
+
return CONFIG_SCHEMA.reduce((acc, def) => {
|
|
645
|
+
if ('environmentValue' in def) {
|
|
646
|
+
acc[def.name] = def.environmentValue;
|
|
647
|
+
}
|
|
648
|
+
return acc;
|
|
649
|
+
}, {});
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Retuns an object with the values of config options defined set
|
|
654
|
+
* in the environment
|
|
655
|
+
* @returns {Record<string,any>}
|
|
656
|
+
*/
|
|
657
|
+
function getFileOptions() {
|
|
658
|
+
return CONFIG_SCHEMA.reduce((acc, def) => {
|
|
659
|
+
if ('fileValue' in def) {
|
|
660
|
+
acc[def.name] = def.fileValue;
|
|
661
|
+
}
|
|
662
|
+
return acc;
|
|
663
|
+
}, {});
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Support function to read environment after the module is loaded. This is needed to
|
|
668
|
+
* perform some tests that modify `process.env`
|
|
669
|
+
* - ./test/config.tes.js
|
|
670
|
+
* - ./test/logging-preamble.test.js
|
|
671
|
+
*
|
|
672
|
+
* TODO: remove this function when test are refactored using the good `runTestFixture` method
|
|
673
|
+
*/
|
|
674
|
+
function readEnvOptions() {
|
|
675
|
+
CONFIG_SCHEMA.forEach((def) => {
|
|
676
|
+
if (def.envVar && process.env[def.envVar]) {
|
|
677
|
+
def.environmentValue = process.env[def.envVar];
|
|
678
|
+
def.source = 'environment';
|
|
679
|
+
} else if (def.envVar) {
|
|
680
|
+
// TODO: this is necessary since config.test.js sets different vars during tests
|
|
681
|
+
delete def.environmentValue;
|
|
682
|
+
delete def.source;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Tries to load a configuration file for the given path or from the ENV vars, if both undefined
|
|
689
|
+
* it uses the default config filename `elastic-apm-node.js`. If the config file is not present or
|
|
690
|
+
* there is something wrong in the file it will return no options
|
|
691
|
+
* @param {string} [confPath] the path to the file
|
|
692
|
+
* @returns {Record<string,any> | null}
|
|
693
|
+
*/
|
|
694
|
+
function readFileOptions(confPath) {
|
|
695
|
+
const configFileDef = CONFIG_SCHEMA.find((def) => def.name === 'configFile');
|
|
696
|
+
const defaultValue = configFileDef.defaultValue;
|
|
697
|
+
const envValue = process.env[configFileDef.envVar];
|
|
698
|
+
const filePath = path.resolve(confPath || envValue || defaultValue);
|
|
699
|
+
|
|
700
|
+
if (fs.existsSync(filePath)) {
|
|
701
|
+
try {
|
|
702
|
+
return require(filePath);
|
|
703
|
+
} catch (err) {
|
|
704
|
+
console.error(
|
|
705
|
+
"Elastic APM initialization error: Can't read config file %s",
|
|
706
|
+
filePath,
|
|
707
|
+
);
|
|
708
|
+
console.error(err.stack);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
return null;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Sets into the schema the value given at agent start
|
|
717
|
+
*
|
|
718
|
+
* @param {Record<string,any>} options
|
|
719
|
+
*/
|
|
720
|
+
function setStartOptions(options) {
|
|
721
|
+
if (!options) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
const fileOpts = options.configFile && readFileOptions(options.configFile);
|
|
726
|
+
|
|
727
|
+
CONFIG_SCHEMA.forEach((def) => {
|
|
728
|
+
const source = def.source || 'default';
|
|
729
|
+
|
|
730
|
+
if (def.name in options) {
|
|
731
|
+
def.startValue = options[def.name];
|
|
732
|
+
if (source !== 'environment') {
|
|
733
|
+
def.source = 'start';
|
|
734
|
+
}
|
|
735
|
+
} else if (fileOpts && def.name in fileOpts) {
|
|
736
|
+
// console.log('setting from file', def.name, fileOpts[def.name], source);
|
|
737
|
+
def.fileValue = fileOpts[def.name];
|
|
738
|
+
if (source === 'default') {
|
|
739
|
+
def.source = 'file';
|
|
740
|
+
}
|
|
741
|
+
console.log(def);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Collects information about the agent, environment and configuration options that are
|
|
748
|
+
* sets from a source (env vars, start options or config file). For each config option it
|
|
749
|
+
* collects
|
|
750
|
+
* - source: where te value came from (environment, start, file)
|
|
751
|
+
* - sourceValue: the raw value provided im the source
|
|
752
|
+
* - normalizedValue: the value normalized by the configuration which is used in the agent
|
|
753
|
+
* - file: if source === 'file' this proprty is defined with the path of the config file
|
|
754
|
+
*
|
|
755
|
+
* @param {Object} config The configuration object with normalized options
|
|
756
|
+
* @returns {Object} Object with agent, environment, and configuration data.
|
|
757
|
+
*/
|
|
758
|
+
function getPreambleData(config) {
|
|
759
|
+
const configFileDef = CONFIG_SCHEMA.find((def) => def.name === 'configFile');
|
|
760
|
+
const configFilePath = path.resolve(
|
|
761
|
+
configFileDef.environmentValue ||
|
|
762
|
+
configFileDef.startValue ||
|
|
763
|
+
configFileDef.defaultValue,
|
|
764
|
+
);
|
|
765
|
+
|
|
766
|
+
const result = {
|
|
767
|
+
agentVersion: AGENT_VERSION,
|
|
768
|
+
env: {
|
|
769
|
+
pid: process.pid,
|
|
770
|
+
proctitle: process.title,
|
|
771
|
+
// For darwin: https://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history
|
|
772
|
+
os: `${os.platform()} ${os.release()}`,
|
|
773
|
+
arch: os.arch(),
|
|
774
|
+
host: os.hostname(),
|
|
775
|
+
timezone: getTimezoneUtc(),
|
|
776
|
+
runtime: `Node.js ${process.version}`,
|
|
777
|
+
},
|
|
778
|
+
config: {},
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
const excludedKeys = new Set(['logger', 'transport']);
|
|
782
|
+
const mandatoryKeys = new Set([
|
|
783
|
+
'serviceName',
|
|
784
|
+
'serviceVersion',
|
|
785
|
+
'serverUrl',
|
|
786
|
+
'logLevel',
|
|
787
|
+
]);
|
|
788
|
+
|
|
789
|
+
CONFIG_SCHEMA.forEach((def) => {
|
|
790
|
+
if (
|
|
791
|
+
excludedKeys.has(def.name) ||
|
|
792
|
+
(!def.source && !mandatoryKeys.has(def.name))
|
|
793
|
+
) {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const details = {
|
|
798
|
+
source: def.source || 'default',
|
|
799
|
+
value: config[def.name],
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
const sourceVal = def[`${details.source}Value`];
|
|
803
|
+
|
|
804
|
+
if (def.crossAgentName) {
|
|
805
|
+
details.commonName = def.crossAgentName;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
if (def.source === 'file') {
|
|
809
|
+
details.file = configFilePath;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if (typeof def.redactFn === 'function') {
|
|
813
|
+
details.value = def.redactFn(details.value);
|
|
814
|
+
} else if (sourceVal !== details.value) {
|
|
815
|
+
details.sourceValue = sourceVal;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
result.config[def.name] = details;
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
return result;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Returns the current Timezone in UTC notation fomat
|
|
826
|
+
*
|
|
827
|
+
* @returns {String} ex. UTC-0600
|
|
828
|
+
*/
|
|
829
|
+
function getTimezoneUtc() {
|
|
830
|
+
const offsetHours = -(new Date().getTimezoneOffset() / 60);
|
|
831
|
+
const offsetSign = offsetHours >= 0 ? '+' : '-';
|
|
832
|
+
const offsetPad = Math.abs(offsetHours) < 10 ? '0' : '';
|
|
833
|
+
return `UTC${offsetSign}${offsetPad}${Math.abs(offsetHours * 100)}`;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Takes an URL string and redacts user & password info if present in the basic
|
|
838
|
+
* auth part
|
|
839
|
+
*
|
|
840
|
+
* @param {String} urlStr The URL to strip sensitive info
|
|
841
|
+
* @returns {String || null} url with basic auth REDACTED
|
|
842
|
+
*/
|
|
843
|
+
function sanitizeUrl(urlStr) {
|
|
844
|
+
if (!urlStr) {
|
|
845
|
+
return '';
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
const url = new URL(urlStr);
|
|
849
|
+
if (url.username) {
|
|
850
|
+
url.username = REDACTED;
|
|
851
|
+
}
|
|
852
|
+
if (url.password) {
|
|
853
|
+
url.password = REDACTED;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
return decodeURIComponent(url.href);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// Fail fast if CONFIG_SCHEMA has issues
|
|
860
|
+
// - duplicated options
|
|
861
|
+
// - dependencies not defined or defined after the dependant option
|
|
862
|
+
// - type with no normalizer
|
|
863
|
+
const depSet = new Set();
|
|
864
|
+
const fileOpts = readFileOptions();
|
|
865
|
+
|
|
866
|
+
CONFIG_SCHEMA.forEach((def) => {
|
|
867
|
+
if (depSet.has(def.name)) {
|
|
868
|
+
throw Error(`config option ${def.name} duplicated.`);
|
|
869
|
+
}
|
|
870
|
+
if (def.deps && def.deps.some((d) => !depSet.has(d))) {
|
|
871
|
+
throw Error(
|
|
872
|
+
`config option ${def.name} dependencies (${def.deps}) need to be defined before.`,
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
depSet.add(def.name);
|
|
876
|
+
|
|
877
|
+
// Initalize values comming from environment and config file
|
|
878
|
+
if (def.envVar && process.env[def.envVar]) {
|
|
879
|
+
def.environmentValue = process.env[def.envVar];
|
|
880
|
+
def.source = 'environment';
|
|
881
|
+
} else if (fileOpts && typeof fileOpts[def.name] !== 'undefined') {
|
|
882
|
+
def.fileValue = fileOpts[def.name];
|
|
883
|
+
def.source = 'file';
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
// TODO: these constants below to be removed in the future (normalization)
|
|
888
|
+
function getConfigName(def) {
|
|
889
|
+
return def.name;
|
|
890
|
+
}
|
|
891
|
+
function optsOfTypes(types) {
|
|
892
|
+
if (!Array.isArray(types)) {
|
|
893
|
+
types = [types];
|
|
894
|
+
}
|
|
895
|
+
return CONFIG_SCHEMA.filter((def) => types.indexOf(def.configType) !== -1);
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
const BOOL_OPTS = optsOfTypes('boolean').map(getConfigName);
|
|
899
|
+
const NUM_OPTS = optsOfTypes(['number', 'numberInfinity']).map(getConfigName);
|
|
900
|
+
const BYTES_OPTS = optsOfTypes('byte').map(getConfigName);
|
|
901
|
+
const URL_OPTS = optsOfTypes('url').map(getConfigName);
|
|
902
|
+
const ARRAY_OPTS = optsOfTypes('stringArray').map(getConfigName);
|
|
903
|
+
const KEY_VALUE_OPTS = optsOfTypes('stringKeyValuePairs').map(getConfigName);
|
|
904
|
+
const MINUS_ONE_EQUAL_INFINITY = optsOfTypes(['numberInfinity']).map(
|
|
905
|
+
getConfigName,
|
|
906
|
+
);
|
|
907
|
+
|
|
908
|
+
const CENTRAL_CONFIG_OPTS = CONFIG_SCHEMA.filter(
|
|
909
|
+
(def) => def.centralConfigName,
|
|
910
|
+
).reduce((acc, def) => {
|
|
911
|
+
acc[def.centralConfigName] = def.name;
|
|
912
|
+
return acc;
|
|
913
|
+
}, {});
|
|
914
|
+
|
|
915
|
+
const DURATION_OPTS = [
|
|
916
|
+
{
|
|
917
|
+
name: 'abortedErrorThreshold',
|
|
918
|
+
defaultUnit: 's',
|
|
919
|
+
allowedUnits: ['ms', 's', 'm'],
|
|
920
|
+
allowNegative: false,
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
name: 'apiRequestTime',
|
|
924
|
+
defaultUnit: 's',
|
|
925
|
+
allowedUnits: ['ms', 's', 'm'],
|
|
926
|
+
allowNegative: false,
|
|
927
|
+
},
|
|
928
|
+
{
|
|
929
|
+
name: 'exitSpanMinDuration',
|
|
930
|
+
defaultUnit: 'ms',
|
|
931
|
+
allowedUnits: ['us', 'ms', 's', 'm'],
|
|
932
|
+
allowNegative: false,
|
|
933
|
+
},
|
|
934
|
+
{
|
|
935
|
+
name: 'metricsInterval',
|
|
936
|
+
defaultUnit: 's',
|
|
937
|
+
allowedUnits: ['ms', 's', 'm'],
|
|
938
|
+
allowNegative: false,
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
name: 'serverTimeout',
|
|
942
|
+
defaultUnit: 's',
|
|
943
|
+
allowedUnits: ['ms', 's', 'm'],
|
|
944
|
+
allowNegative: false,
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
name: 'spanCompressionExactMatchMaxDuration',
|
|
948
|
+
defaultUnit: 'ms',
|
|
949
|
+
allowedUnits: ['ms', 's', 'm'],
|
|
950
|
+
allowNegative: false,
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
name: 'spanCompressionSameKindMaxDuration',
|
|
954
|
+
defaultUnit: 'ms',
|
|
955
|
+
allowedUnits: ['ms', 's', 'm'],
|
|
956
|
+
allowNegative: false,
|
|
957
|
+
},
|
|
958
|
+
{
|
|
959
|
+
// Deprecated: use `spanStackTraceMinDuration`.
|
|
960
|
+
name: 'spanFramesMinDuration',
|
|
961
|
+
defaultUnit: 's',
|
|
962
|
+
allowedUnits: ['ms', 's', 'm'],
|
|
963
|
+
allowNegative: true,
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
name: 'spanStackTraceMinDuration',
|
|
967
|
+
defaultUnit: 'ms',
|
|
968
|
+
allowedUnits: ['ms', 's', 'm'],
|
|
969
|
+
allowNegative: true,
|
|
970
|
+
},
|
|
971
|
+
];
|
|
972
|
+
const CROSS_AGENT_CONFIG_VAR_NAME = CONFIG_SCHEMA.filter(
|
|
973
|
+
(def) => def.crossAgentName,
|
|
974
|
+
).reduce((acc, def) => {
|
|
975
|
+
acc[def.name] = def.crossAgentName;
|
|
976
|
+
return acc;
|
|
977
|
+
}, {});
|
|
978
|
+
|
|
979
|
+
const ENV_TABLE = CONFIG_SCHEMA.filter((def) => def.envVar).reduce(
|
|
980
|
+
(acc, def) => {
|
|
981
|
+
acc[def.name] = def.envVar;
|
|
982
|
+
return acc;
|
|
983
|
+
},
|
|
984
|
+
{},
|
|
985
|
+
);
|
|
986
|
+
|
|
987
|
+
// Exports
|
|
988
|
+
module.exports = {
|
|
989
|
+
BOOL_OPTS,
|
|
990
|
+
NUM_OPTS,
|
|
991
|
+
DURATION_OPTS,
|
|
992
|
+
BYTES_OPTS,
|
|
993
|
+
MINUS_ONE_EQUAL_INFINITY,
|
|
994
|
+
ARRAY_OPTS,
|
|
995
|
+
KEY_VALUE_OPTS,
|
|
996
|
+
URL_OPTS,
|
|
997
|
+
CROSS_AGENT_CONFIG_VAR_NAME,
|
|
998
|
+
CENTRAL_CONFIG_OPTS,
|
|
999
|
+
ENV_TABLE,
|
|
1000
|
+
CONFIG_SCHEMA,
|
|
1001
|
+
getDefaultOptions,
|
|
1002
|
+
getEnvironmentOptions,
|
|
1003
|
+
getFileOptions,
|
|
1004
|
+
setStartOptions,
|
|
1005
|
+
getPreambleData,
|
|
1006
|
+
readEnvOptions,
|
|
1007
|
+
};
|