@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,313 @@
|
|
|
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 version = require('../../package').version;
|
|
11
|
+
const { INTAKE_STRING_MAX_SIZE } = require('../constants');
|
|
12
|
+
const { CENTRAL_CONFIG_OPTS } = require('../config/schema');
|
|
13
|
+
const { normalize } = require('../config/config');
|
|
14
|
+
const { CloudMetadata } = require('../cloud-metadata');
|
|
15
|
+
const { isLambdaExecutionEnvironment } = require('../lambda');
|
|
16
|
+
const logging = require('../logging');
|
|
17
|
+
|
|
18
|
+
const { HttpApmClient } = require('./http-apm-client');
|
|
19
|
+
const { NoopApmClient } = require('./noop-apm-client');
|
|
20
|
+
const {
|
|
21
|
+
isAzureFunctionsEnvironment,
|
|
22
|
+
getAzureFunctionsExtraMetadata,
|
|
23
|
+
} = require('../instrumentation/azure-functions');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns an APM client suited for the configuration provided
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} config The agent's configuration
|
|
29
|
+
* @param {Object} agent The agents instance
|
|
30
|
+
*/
|
|
31
|
+
function createApmClient(config, agent) {
|
|
32
|
+
if (config.disableSend || config.contextPropagationOnly) {
|
|
33
|
+
return new NoopApmClient();
|
|
34
|
+
} else if (typeof config.transport === 'function') {
|
|
35
|
+
return config.transport(config, agent);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const client = new HttpApmClient(getHttpClientConfig(config, agent));
|
|
39
|
+
|
|
40
|
+
client.on('config', (remoteConf) => {
|
|
41
|
+
agent.logger.debug({ remoteConf }, 'central config received');
|
|
42
|
+
try {
|
|
43
|
+
const conf = {};
|
|
44
|
+
const unknown = [];
|
|
45
|
+
|
|
46
|
+
for (const [key, value] of Object.entries(remoteConf)) {
|
|
47
|
+
const newKey = CENTRAL_CONFIG_OPTS[key];
|
|
48
|
+
if (newKey) {
|
|
49
|
+
conf[newKey] = value;
|
|
50
|
+
} else {
|
|
51
|
+
unknown.push(key);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (unknown.length > 0) {
|
|
55
|
+
agent.logger.warn(
|
|
56
|
+
`Central config warning: unsupported config names: ${unknown.join(
|
|
57
|
+
', ',
|
|
58
|
+
)}`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (Object.keys(conf).length > 0) {
|
|
63
|
+
normalize(conf, agent.logger);
|
|
64
|
+
for (const [key, value] of Object.entries(conf)) {
|
|
65
|
+
const oldValue = agent._conf[key];
|
|
66
|
+
agent._conf[key] = value;
|
|
67
|
+
if (
|
|
68
|
+
key === 'logLevel' &&
|
|
69
|
+
value !== oldValue &&
|
|
70
|
+
!logging.isLoggerCustom(agent.logger)
|
|
71
|
+
) {
|
|
72
|
+
logging.setLogLevel(agent.logger, value);
|
|
73
|
+
// Hackily also set the HttpApmClient._log level.
|
|
74
|
+
logging.setLogLevel(client._log, value);
|
|
75
|
+
agent.logger.info(
|
|
76
|
+
`Central config success: updated logger with new logLevel: ${value}`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
agent.logger.info(`Central config success: updated ${key}: ${value}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
agent.logger.error(
|
|
84
|
+
{ remoteConf, err },
|
|
85
|
+
'Central config error: exception while applying changes',
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
client.on('error', (err) => {
|
|
91
|
+
agent.logger.error('APM Server transport error: %s', err.stack);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
client.on('request-error', (err) => {
|
|
95
|
+
const haveAccepted = Number.isFinite(err.accepted);
|
|
96
|
+
const haveErrors = Array.isArray(err.errors);
|
|
97
|
+
let msg;
|
|
98
|
+
|
|
99
|
+
if (err.code === 404) {
|
|
100
|
+
msg =
|
|
101
|
+
'APM Server responded with "404 Not Found". ' +
|
|
102
|
+
"This might be because you're running an incompatible version of the APM Server. " +
|
|
103
|
+
'This agent only supports APM Server v6.5 and above. ' +
|
|
104
|
+
"If you're using an older version of the APM Server, " +
|
|
105
|
+
'please downgrade this agent to version 1.x or upgrade the APM Server';
|
|
106
|
+
} else if (err.code) {
|
|
107
|
+
msg = `APM Server transport error (${err.code}): ${err.message}`;
|
|
108
|
+
} else {
|
|
109
|
+
msg = `APM Server transport error: ${err.message}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (haveAccepted || haveErrors) {
|
|
113
|
+
if (haveAccepted)
|
|
114
|
+
msg += `\nAPM Server accepted ${err.accepted} events in the last request`;
|
|
115
|
+
if (haveErrors) {
|
|
116
|
+
for (const error of err.errors) {
|
|
117
|
+
msg += `\nError: ${error.message}`;
|
|
118
|
+
if (error.document) msg += `\n Document: ${error.document}`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} else if (err.response) {
|
|
122
|
+
msg += `\n${err.response}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
agent.logger.error(msg);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return client;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Returns a HTTP client configuration based on agent configuration options
|
|
133
|
+
*
|
|
134
|
+
* @param {Object} conf The agent configuration object
|
|
135
|
+
* @param {Object} agent
|
|
136
|
+
* @returns {Object}
|
|
137
|
+
*/
|
|
138
|
+
function getHttpClientConfig(conf, agent) {
|
|
139
|
+
let clientLogger = null;
|
|
140
|
+
if (!logging.isLoggerCustom(agent.logger)) {
|
|
141
|
+
// https://www.elastic.co/guide/en/ecs/current/ecs-event.html#field-event-module
|
|
142
|
+
clientLogger = agent.logger.child({ 'event.module': 'apmclient' });
|
|
143
|
+
}
|
|
144
|
+
const isLambda = isLambdaExecutionEnvironment();
|
|
145
|
+
|
|
146
|
+
const clientConfig = {
|
|
147
|
+
agentName: 'nodejs',
|
|
148
|
+
agentVersion: version,
|
|
149
|
+
agentActivationMethod: agent._agentActivationMethod,
|
|
150
|
+
serviceName: conf.serviceName,
|
|
151
|
+
serviceVersion: conf.serviceVersion,
|
|
152
|
+
frameworkName: conf.frameworkName,
|
|
153
|
+
frameworkVersion: conf.frameworkVersion,
|
|
154
|
+
globalLabels: maybePairsToObject(conf.globalLabels),
|
|
155
|
+
configuredHostname: conf.hostname,
|
|
156
|
+
environment: conf.environment,
|
|
157
|
+
|
|
158
|
+
// Sanitize conf
|
|
159
|
+
truncateKeywordsAt: INTAKE_STRING_MAX_SIZE,
|
|
160
|
+
truncateLongFieldsAt: conf.longFieldMaxLength,
|
|
161
|
+
// truncateErrorMessagesAt: see below
|
|
162
|
+
|
|
163
|
+
// HTTP conf
|
|
164
|
+
secretToken: conf.secretToken,
|
|
165
|
+
apiKey: conf.apiKey,
|
|
166
|
+
userAgent: userAgentFromConf(conf),
|
|
167
|
+
serverUrl: conf.serverUrl,
|
|
168
|
+
serverCaCert: loadServerCaCertFile(conf.serverCaCertFile),
|
|
169
|
+
rejectUnauthorized: conf.verifyServerCert,
|
|
170
|
+
serverTimeout: conf.serverTimeout * 1000,
|
|
171
|
+
headers: maybePairsToObject(conf.apmClientHeaders),
|
|
172
|
+
|
|
173
|
+
// APM Agent Configuration via Kibana:
|
|
174
|
+
centralConfig: conf.centralConfig,
|
|
175
|
+
|
|
176
|
+
// Streaming conf
|
|
177
|
+
size: conf.apiRequestSize,
|
|
178
|
+
time: conf.apiRequestTime * 1000,
|
|
179
|
+
maxQueueSize: conf.maxQueueSize,
|
|
180
|
+
|
|
181
|
+
// Debugging/testing options
|
|
182
|
+
logger: clientLogger,
|
|
183
|
+
payloadLogFile: conf.payloadLogFile,
|
|
184
|
+
apmServerVersion: conf.apmServerVersion,
|
|
185
|
+
|
|
186
|
+
// Container conf
|
|
187
|
+
containerId: conf.containerId,
|
|
188
|
+
kubernetesNodeName: conf.kubernetesNodeName,
|
|
189
|
+
kubernetesNamespace: conf.kubernetesNamespace,
|
|
190
|
+
kubernetesPodName: conf.kubernetesPodName,
|
|
191
|
+
kubernetesPodUID: conf.kubernetesPodUID,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// `service_node_name` is ignored in Lambda and Azure Functions envs.
|
|
195
|
+
if (conf.serviceNodeName) {
|
|
196
|
+
if (isLambda) {
|
|
197
|
+
agent.logger.warn(
|
|
198
|
+
{ serviceNodeName: conf.serviceNodeName },
|
|
199
|
+
'ignoring "serviceNodeName" config setting in Lambda environment',
|
|
200
|
+
);
|
|
201
|
+
} else if (isAzureFunctionsEnvironment) {
|
|
202
|
+
agent.logger.warn(
|
|
203
|
+
{ serviceNodeName: conf.serviceNodeName },
|
|
204
|
+
'ignoring "serviceNodeName" config setting in Azure Functions environment',
|
|
205
|
+
);
|
|
206
|
+
} else {
|
|
207
|
+
clientConfig.serviceNodeName = conf.serviceNodeName;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Extra metadata handling.
|
|
212
|
+
if (isLambda) {
|
|
213
|
+
// Tell the Client to wait for a subsequent `.setExtraMetadata()` call
|
|
214
|
+
// before allowing intake requests. This will be called by `apm.lambda()`
|
|
215
|
+
// on first Lambda function invocation.
|
|
216
|
+
clientConfig.expectExtraMetadata = true;
|
|
217
|
+
} else if (isAzureFunctionsEnvironment) {
|
|
218
|
+
clientConfig.extraMetadata = getAzureFunctionsExtraMetadata();
|
|
219
|
+
} else if (conf.cloudProvider !== 'none') {
|
|
220
|
+
clientConfig.cloudMetadataFetcher = new CloudMetadata(
|
|
221
|
+
conf.cloudProvider,
|
|
222
|
+
conf.logger,
|
|
223
|
+
conf.serviceName,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (conf.errorMessageMaxLength !== undefined) {
|
|
228
|
+
// As of v10 of the http client, truncation of error messages will default
|
|
229
|
+
// to `truncateLongFieldsAt` if `truncateErrorMessagesAt` is not specified.
|
|
230
|
+
clientConfig.truncateErrorMessagesAt = conf.errorMessageMaxLength;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return clientConfig;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Return the User-Agent string the agent will use for its comms to APM Server.
|
|
237
|
+
//
|
|
238
|
+
// Per https://github.com/elastic/apm/blob/main/specs/agents/transport.md#user-agent
|
|
239
|
+
// the pattern is roughly this:
|
|
240
|
+
// $repoName/$version ($serviceName $serviceVersion)
|
|
241
|
+
//
|
|
242
|
+
// The format of User-Agent is governed by https://datatracker.ietf.org/doc/html/rfc7231.
|
|
243
|
+
// User-Agent = product *( RWS ( product / comment ) )
|
|
244
|
+
// We do not expect `$repoName` and `$version` to have surprise/invalid values.
|
|
245
|
+
// From `validateServiceName` above, we know that `$serviceName` is null or a
|
|
246
|
+
// string limited to `/^[a-zA-Z0-9 _-]+$/`. However, `$serviceVersion` is
|
|
247
|
+
// provided by the user and could have invalid characters.
|
|
248
|
+
//
|
|
249
|
+
// `comment` is defined by
|
|
250
|
+
// https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6 as:
|
|
251
|
+
// comment = "(" *( ctext / quoted-pair / comment ) ")"
|
|
252
|
+
// obs-text = %x80-FF
|
|
253
|
+
// ctext = HTAB / SP / %x21-27 / %x2A-5B / %x5D-7E / obs-text
|
|
254
|
+
// quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
|
|
255
|
+
//
|
|
256
|
+
// `commentBadChar` below *approximates* these rules, and is used to replace
|
|
257
|
+
// invalid characters with '_' in the generated User-Agent string. This
|
|
258
|
+
// replacement isn't part of the APM spec.
|
|
259
|
+
function userAgentFromConf(conf) {
|
|
260
|
+
let userAgent = `apm-agent-nodejs/${version}`;
|
|
261
|
+
|
|
262
|
+
// This regex *approximately* matches the allowed syntax for a "comment".
|
|
263
|
+
// It does not handle "quoted-pair" or a "comment" in a comment.
|
|
264
|
+
const commentBadChar = /[^\t \x21-\x27\x2a-\x5b\x5d-\x7e\x80-\xff]/g;
|
|
265
|
+
const commentParts = [];
|
|
266
|
+
if (conf.serviceName) {
|
|
267
|
+
commentParts.push(conf.serviceName);
|
|
268
|
+
}
|
|
269
|
+
if (conf.serviceVersion) {
|
|
270
|
+
commentParts.push(conf.serviceVersion.replace(commentBadChar, '_'));
|
|
271
|
+
}
|
|
272
|
+
if (commentParts.length > 0) {
|
|
273
|
+
userAgent += ` (${commentParts.join(' ')})`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return userAgent;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Reads te server CA cert file and returns a buffer with its contents
|
|
281
|
+
* @param {string | undefined} serverCaCertFile
|
|
282
|
+
* @param {any} logger
|
|
283
|
+
* @returns {Buffer}
|
|
284
|
+
*/
|
|
285
|
+
function loadServerCaCertFile(serverCaCertFile, logger) {
|
|
286
|
+
if (serverCaCertFile) {
|
|
287
|
+
try {
|
|
288
|
+
return fs.readFileSync(serverCaCertFile);
|
|
289
|
+
} catch (err) {
|
|
290
|
+
logger.error(
|
|
291
|
+
"Elastic APM initialization error: Can't read server CA cert file %s (%s)",
|
|
292
|
+
serverCaCertFile,
|
|
293
|
+
err.message,
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function maybePairsToObject(pairs) {
|
|
300
|
+
return pairs ? pairsToObject(pairs) : undefined;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function pairsToObject(pairs) {
|
|
304
|
+
return pairs.reduce((object, [key, value]) => {
|
|
305
|
+
object[key] = value;
|
|
306
|
+
return object;
|
|
307
|
+
}, {});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
module.exports = {
|
|
311
|
+
createApmClient,
|
|
312
|
+
userAgentFromConf,
|
|
313
|
+
};
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# elastic-apm-http-client changelog
|
|
2
|
+
|
|
3
|
+
Note: After v12.0.0 the `elastic-apm-http-client` package code was included
|
|
4
|
+
in this repo. This repo was the only intended user of the http-client package.
|
|
5
|
+
|
|
6
|
+
## v12.0.0
|
|
7
|
+
|
|
8
|
+
- **Breaking change.** The `hostname` configuration option has been renamed to
|
|
9
|
+
`configuredHostname`. As well, the hostname detection has changed to prefer
|
|
10
|
+
using a FQDN, if available. See [the spec](https://github.com/elastic/apm/blob/main/specs/agents/metadata.md#hostname).
|
|
11
|
+
(https://github.com/elastic/apm-agent-nodejs/issues/3310)
|
|
12
|
+
|
|
13
|
+
- The APM client will send `metadata.system.detected_hostname` and
|
|
14
|
+
`metadata.system.configured_hostname` as appropriate for APM server versions
|
|
15
|
+
>=7.4, rather than the now deprecated `metadata.system.hostname`.
|
|
16
|
+
See [the spec](https://github.com/elastic/apm/blob/main/specs/agents/metadata.md#hostname).
|
|
17
|
+
|
|
18
|
+
## v11.4.0
|
|
19
|
+
|
|
20
|
+
- Add support for pre-registering of partial transactions for AWS Lambda.
|
|
21
|
+
This adds `client.lambdaShouldRegisterTransactions()` and
|
|
22
|
+
`client.lambdaRegisterTransaction(transaction, awsRequestId)` so the
|
|
23
|
+
APM agent can register a partial transaction with the Elastic Lambda
|
|
24
|
+
extension before executing the user's handler. In some error cases
|
|
25
|
+
(`uncaughtException`, `unhandledRejection`, Lambda timeout), the extension
|
|
26
|
+
can report that transaction when the APM agent is unable.
|
|
27
|
+
(https://github.com/elastic/apm-agent-nodejs/issues/3136)
|
|
28
|
+
|
|
29
|
+
## v11.3.1
|
|
30
|
+
|
|
31
|
+
- Tweak logic to only exclude `metadata.service.agent.activation_method` when
|
|
32
|
+
the APM server version is known to be 8.7.0 -- i.e. optimistically assume
|
|
33
|
+
it is a version that is fine. The APM server 8.7.0 issue isn't so severe that
|
|
34
|
+
we want a fast first serverless function invocation to not send the field.
|
|
35
|
+
(https://github.com/elastic/apm/pull/783)
|
|
36
|
+
|
|
37
|
+
## v11.3.0
|
|
38
|
+
|
|
39
|
+
- Ensure `metadata.service.agent.activation_method` is only sent for APM
|
|
40
|
+
server version 8.7.1 or later. APM server 8.7.0 included a bug where
|
|
41
|
+
receiving `activation_method` is harmful.
|
|
42
|
+
(https://github.com/elastic/apm-agent-nodejs/issues/3230)
|
|
43
|
+
|
|
44
|
+
This change adds the `client.supportsActivationMethodField()` method.
|
|
45
|
+
|
|
46
|
+
## v11.2.0
|
|
47
|
+
|
|
48
|
+
- Support a new `agentActivationMethod` string config var that is added to
|
|
49
|
+
`metadata.service.agent.activation_method`. Spec:
|
|
50
|
+
https://github.com/elastic/apm/blob/main/specs/agents/metadata.md#activation-method
|
|
51
|
+
|
|
52
|
+
## v11.1.0
|
|
53
|
+
|
|
54
|
+
- Add an `extraMetadata` config option, which is an object to merge into the
|
|
55
|
+
built metadata object. This is an alternative to the existing
|
|
56
|
+
`cloudMetadataFetcher` and `expectExtraMetadata` options which provide ways
|
|
57
|
+
to asynchronously provide metadata. Only one (or zero) of these three options
|
|
58
|
+
may be used.
|
|
59
|
+
|
|
60
|
+
## v11.0.4
|
|
61
|
+
|
|
62
|
+
- Update the default `serverUrl` to "http://127.0.0.1:8200". We no longer use
|
|
63
|
+
"localhost" to avoid ambiguity if localhost resolves to multiple addresses
|
|
64
|
+
(e.g. IPv4 and IPv6). APM server only listens on IPv4 by default.
|
|
65
|
+
(https://github.com/elastic/apm-agent-nodejs/pull/3049)
|
|
66
|
+
|
|
67
|
+
## v11.0.3
|
|
68
|
+
|
|
69
|
+
- Prevent a possible tight loop in central config fetching.
|
|
70
|
+
(https://github.com/elastic/apm-agent-nodejs/issues/3029)
|
|
71
|
+
|
|
72
|
+
## v11.0.2
|
|
73
|
+
|
|
74
|
+
**Bad release. Upgrade to 11.0.3.**
|
|
75
|
+
|
|
76
|
+
- Add guards to ensure that a crazy `Cache-Control: max-age=...` response
|
|
77
|
+
header cannot accidentally result in inappropriate intervals for fetching
|
|
78
|
+
central config. The re-fetch delay is clamped to `[5 seconds, 1 day]`.
|
|
79
|
+
(https://github.com/elastic/apm-agent-nodejs/issues/2941)
|
|
80
|
+
|
|
81
|
+
- Improve container-info gathering to support AWS ECS/Fargate environments.
|
|
82
|
+
(https://github.com/elastic/apm-agent-nodejs/issues/2914)
|
|
83
|
+
|
|
84
|
+
## v11.0.1
|
|
85
|
+
|
|
86
|
+
- Fix an issue when running in a Lambda function, where a missing or erroring
|
|
87
|
+
APM Lambda extension could result in apmclient back-off such that (a) the
|
|
88
|
+
end-of-lambda-invocation signaling (`?flushed=true`) would not happen and
|
|
89
|
+
(b) premature "beforeExit" event could result in the Lambda Runtime
|
|
90
|
+
responding `null` before the Lambda function could respond
|
|
91
|
+
(https://github.com/elastic/apm-agent-nodejs/issues/1831).
|
|
92
|
+
|
|
93
|
+
## v11.0.0
|
|
94
|
+
|
|
95
|
+
- Add support for coordinating data flushing in an AWS Lambda environment. The
|
|
96
|
+
following two API additions are used to ensure that (a) the Elastic Lambda
|
|
97
|
+
extension is signaled at invocation end [per spec](https://github.com/elastic/apm/blob/main/specs/agents/tracing-instrumentation-aws-lambda.md#data-flushing)
|
|
98
|
+
and (b) a new intake request is not started when a Lambda function invocation
|
|
99
|
+
is not active.
|
|
100
|
+
|
|
101
|
+
- `Client#lambdaStart()` should be used to indicate when a Lambda function
|
|
102
|
+
invocation begins.
|
|
103
|
+
- `Client#flush([opts,] cb)` now supports an optional `opts.lambdaEnd`
|
|
104
|
+
boolean. Set it to true to indicate this is a flush at the end of a Lambda
|
|
105
|
+
function invocation.
|
|
106
|
+
|
|
107
|
+
This is a **BREAKING CHANGE**, because current versions of elastic-apm-node
|
|
108
|
+
depend on `^10.4.0`. If this were released as another 10.x, then usage of
|
|
109
|
+
current elastic-apm-node with this version of the client would break
|
|
110
|
+
behavior in a Lambda environment.
|
|
111
|
+
|
|
112
|
+
- Add the `freeSocketTimeout` option, with a default of 4000 (ms), and switch
|
|
113
|
+
from Node.js's core `http.Agent` to the [agentkeepalive package](https://github.com/node-modules/agentkeepalive)
|
|
114
|
+
to fix ECONNRESET issues with HTTP Keep-Alive usage talking to APM Server
|
|
115
|
+
(https://github.com/elastic/apm-agent-nodejs/issues/2594).
|
|
116
|
+
|
|
117
|
+
## v10.4.0
|
|
118
|
+
|
|
119
|
+
- Add APM Server version checking to the client. On creation the client will
|
|
120
|
+
call the [APM Server Information API](https://www.elastic.co/guide/en/apm/server/current/server-info.html)
|
|
121
|
+
to get the server version and save that.
|
|
122
|
+
|
|
123
|
+
The new `Client#supportsKeepingUnsampledTransaction()` boolean method returns
|
|
124
|
+
`true` if APM Server is a version that requires unsampled transactions to
|
|
125
|
+
be sent. This will be used by the APM Agent to [drop unsampled transactions
|
|
126
|
+
for newer APM Servers](https://github.com/elastic/apm-agent-nodejs/issues/2455).
|
|
127
|
+
|
|
128
|
+
There is a new `apmServerVersion: <string>` config option to tell the Client
|
|
129
|
+
to skip fetching the APM Server version and use the given value. This config
|
|
130
|
+
option is intended mainly for internal test suite usage.
|
|
131
|
+
|
|
132
|
+
## v10.3.0
|
|
133
|
+
|
|
134
|
+
- Add the `expectExtraMetadata: true` configuration option and
|
|
135
|
+
`Client#setExtraMetadata(metadata)` method to provide a mechanism for the
|
|
136
|
+
Node.js APM Agent to pass in metadata asynchronously and be sure that the
|
|
137
|
+
client will not begin an intake request until that metadata is provided.
|
|
138
|
+
This is to support passing in [AWS Lambda metadata that cannot be gathered
|
|
139
|
+
until the first Lambda function
|
|
140
|
+
invocation](https://github.com/elastic/apm-agent-nodejs/issues/2404).
|
|
141
|
+
(Note: The `expectExtraMetadata` option cannot be used in combination with
|
|
142
|
+
`cloudMetadataFetcher`.)
|
|
143
|
+
|
|
144
|
+
- Use `Z_BEST_SPEED` for gzip compression per
|
|
145
|
+
https://github.com/elastic/apm/blob/main/specs/agents/transport.md#compression
|
|
146
|
+
|
|
147
|
+
## v10.2.0
|
|
148
|
+
|
|
149
|
+
- The client will no longer append data to the configured `userAgent` string.
|
|
150
|
+
Before this it would append " elastic-apm-http-client/$ver node/$ver". This
|
|
151
|
+
is to support [the APM agents spec for
|
|
152
|
+
User-Agent](https://github.com/elastic/apm/blob/main/specs/agents/transport.md#user-agent).
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
## v10.1.0
|
|
156
|
+
|
|
157
|
+
- Fix client handling of an AWS Lambda environment:
|
|
158
|
+
1. `client.flush()` will initiate a quicker completion of the current intake
|
|
159
|
+
request.
|
|
160
|
+
2. The process 'beforeExit' event is *not* used to start a graceful shutdown
|
|
161
|
+
of the client, because the Lambda Runtime sometimes uses 'beforeExit' to
|
|
162
|
+
handle *freezing* of the Lambda VM instance. That VM instance is typically
|
|
163
|
+
unfrozen and used again, for which this Client is still needed.
|
|
164
|
+
|
|
165
|
+
## v10.0.0
|
|
166
|
+
|
|
167
|
+
- All truncation of string fields (per `truncate*At` config options) have
|
|
168
|
+
changed from truncating at a number of unicode chars, rather than a number
|
|
169
|
+
of bytes. This is both faster and matches [the json-schema spec](https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.3.1)
|
|
170
|
+
for [apm-server intake fields](https://www.elastic.co/guide/en/apm/server/current/events-api.html#events-api-schema-definition)
|
|
171
|
+
that specify `maxLength`.
|
|
172
|
+
- BREAKING CHANGE: The `truncateQueriesAt` config option has been removed.
|
|
173
|
+
- In its place the `truncateLongFieldsAt` config option has been added to cover
|
|
174
|
+
`span.context.db.statement` and a number of other possibly-long fields (per
|
|
175
|
+
[spec](https://github.com/elastic/apm/blob/main/specs/agents/field-limits.md#long_field_max_length-configuration)).
|
|
176
|
+
This *does* mean that in rare cases of long field values longer than the
|
|
177
|
+
default 10000 chars, this change will result in those values being truncated.
|
|
178
|
+
- The `truncateErrorMessagesAt` config option has been deprecated, in favor
|
|
179
|
+
of `truncateLongFieldsAt`. Note, however, that `truncateLongFieldsAt` does
|
|
180
|
+
*not* support the special case `-1` value to disable truncation. If
|
|
181
|
+
`truncateErrorMessagesAt` is not specified, the value for
|
|
182
|
+
`truncateLongFieldsAt` is used. This means the effective default is now 10000,
|
|
183
|
+
no longer 2048.
|
|
184
|
+
|
|
185
|
+
## v9.9.0
|
|
186
|
+
|
|
187
|
+
- feat: Use uninstrumented HTTP(S) client request functions to avoid tracing
|
|
188
|
+
requests made by the APM agent itself.
|
|
189
|
+
([#161](https://github.com/elastic/apm-nodejs-http-client/pull/161))
|
|
190
|
+
|
|
191
|
+
## v9.8.1
|
|
192
|
+
|
|
193
|
+
- perf: eliminate encodeObject stack and faster loop in `_writeBatch`
|
|
194
|
+
([#159](https://github.com/elastic/apm-nodejs-http-client/pull/159))
|
|
195
|
+
- test: start testing with node 16
|
|
196
|
+
([#157](https://github.com/elastic/apm-nodejs-http-client/pull/157))
|
|
197
|
+
|
|
198
|
+
## v9.8.0
|
|
199
|
+
|
|
200
|
+
- Add `client.addMetadataFilter(fn)`. See the
|
|
201
|
+
[APM agent issue](https://github.com/elastic/apm-agent-nodejs/issues/1916).
|
|
202
|
+
|
|
203
|
+
## v9.7.1
|
|
204
|
+
|
|
205
|
+
- Fix to ensure the `client.flush(cb)` callback is called in the (expected to
|
|
206
|
+
be rare) case where there are no active handles -- i.e., the process is
|
|
207
|
+
exiting.
|
|
208
|
+
([#150](https://github.com/elastic/apm-nodejs-http-client/issues/150))
|
|
209
|
+
|
|
210
|
+
## v9.7.0
|
|
211
|
+
|
|
212
|
+
- A number of changes were made to fix issues with the APM agent under heavy
|
|
213
|
+
load and with a slow or non-responsive APM server.
|
|
214
|
+
([#144](https://github.com/elastic/apm-nodejs-http-client/pull/144))
|
|
215
|
+
|
|
216
|
+
1. A new `maxQueueSize` config option is added (default 1024 for now) to
|
|
217
|
+
control how many events (transactions, spans, errors, metricsets)
|
|
218
|
+
will be queued before being dropped if events are incoming faster
|
|
219
|
+
than can be sent to APM server. This ensures the APM agent memory usage
|
|
220
|
+
does not grow unbounded.
|
|
221
|
+
|
|
222
|
+
2. JSON encoding of events (when uncorking) is done in limited size
|
|
223
|
+
batches to control the amount of single chunk CPU eventloop blocking
|
|
224
|
+
time. (See MAX_WRITE_BATCH_SIZE in Client._writev.) Internal stats
|
|
225
|
+
are collected to watch for long(est) batch processing times.
|
|
226
|
+
|
|
227
|
+
3. The handling of individual requests to the APM Server intake API has
|
|
228
|
+
be rewritten to handle some error cases -- especially from a
|
|
229
|
+
non-responsive APM server -- and to ensure that only one intake
|
|
230
|
+
request is being performed at a time. Two new config options --
|
|
231
|
+
`intakeResTimeout` and `intakeResTimeoutOnEnd` -- have been added to
|
|
232
|
+
allow fine control over some parts of this handling. See the comment on
|
|
233
|
+
`makeIntakeRequest` for the best overview.
|
|
234
|
+
|
|
235
|
+
4. Support for backoff on intake API requests has been implemented per
|
|
236
|
+
https://github.com/elastic/apm/blob/main/specs/agents/transport.md#transport-errors
|
|
237
|
+
|
|
238
|
+
- Started testing against node v15 in preparation for supporting the coming
|
|
239
|
+
node v16.
|
|
240
|
+
|
|
241
|
+
## v9.6.0
|
|
242
|
+
|
|
243
|
+
- Fix config initialization such that the keep-alive agent is used all the
|
|
244
|
+
time, as intended. Before this change the keep-alive HTTP(S) agent would only
|
|
245
|
+
be used if a second call to `client.config(...)` was made. For the [Elastic
|
|
246
|
+
APM Agent](https://github.com/elastic/apm-agent-nodejs)'s usage of this
|
|
247
|
+
module, that was when any of the express, fastify, restify, hapi, or koa
|
|
248
|
+
modules was instrumented. ([#139](https://github.com/elastic/apm-nodejs-http-client/pull/139))
|
|
249
|
+
|
|
250
|
+
A compatibility note for direct users of this APM http-client:
|
|
251
|
+
Options passed to the
|
|
252
|
+
[`Writable`](https://nodejs.org/api/stream.html#stream_new_stream_writable_options)
|
|
253
|
+
and [`http[s].Agent`](https://nodejs.org/api/http.html#http_new_agent_options)
|
|
254
|
+
constructors no longer include the full options object passed to the
|
|
255
|
+
[Client constructor](https://github.com/elastic/apm-nodejs-http-client/blob/main/README.md#new-clientoptions).
|
|
256
|
+
Therefore usage of *undocumented* options can no longer be used.
|
|
257
|
+
|
|
258
|
+
## v9.5.1
|
|
259
|
+
|
|
260
|
+
- Fix possible crash when polling apm-server for config. Specifically it
|
|
261
|
+
could happen with the Elastic Node.js APM agent when:
|
|
262
|
+
|
|
263
|
+
1. using node.js v12;
|
|
264
|
+
2. instrumenting one of hapi, restify, koa, express, or fastify; and
|
|
265
|
+
3. on a *second* request to APM server *that fails* (non-200 response).
|
|
266
|
+
|
|
267
|
+
https://github.com/elastic/apm-agent-nodejs/issues/1749
|
|
268
|
+
|
|
269
|
+
## v9.5.0
|
|
270
|
+
|
|
271
|
+
(This changelog was started after the 9.5.0 release.)
|