@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.
Files changed (154) hide show
  1. package/LICENSE +26 -0
  2. package/NOTICE.md +442 -0
  3. package/README.md +48 -0
  4. package/changes.json +78 -0
  5. package/index.d.ts +398 -0
  6. package/index.js +11 -0
  7. package/lib/InflightEventSet.js +53 -0
  8. package/lib/activation-method.js +119 -0
  9. package/lib/agent.js +941 -0
  10. package/lib/apm-client/apm-client.js +313 -0
  11. package/lib/apm-client/http-apm-client/CHANGELOG.md +271 -0
  12. package/lib/apm-client/http-apm-client/README.md +485 -0
  13. package/lib/apm-client/http-apm-client/central-config.js +41 -0
  14. package/lib/apm-client/http-apm-client/container-info.js +111 -0
  15. package/lib/apm-client/http-apm-client/detect-hostname.js +96 -0
  16. package/lib/apm-client/http-apm-client/index.js +1975 -0
  17. package/lib/apm-client/http-apm-client/logging.js +31 -0
  18. package/lib/apm-client/http-apm-client/ndjson.js +20 -0
  19. package/lib/apm-client/http-apm-client/truncate.js +434 -0
  20. package/lib/apm-client/noop-apm-client.js +73 -0
  21. package/lib/async-hooks-polyfill.js +58 -0
  22. package/lib/cloud-metadata/aws.js +175 -0
  23. package/lib/cloud-metadata/azure.js +123 -0
  24. package/lib/cloud-metadata/callback-coordination.js +159 -0
  25. package/lib/cloud-metadata/gcp.js +133 -0
  26. package/lib/cloud-metadata/index.js +175 -0
  27. package/lib/config/config.js +458 -0
  28. package/lib/config/normalizers.js +701 -0
  29. package/lib/config/schema.js +1007 -0
  30. package/lib/constants.js +35 -0
  31. package/lib/errors.js +303 -0
  32. package/lib/filters/sanitize-field-names.js +69 -0
  33. package/lib/http-request.js +249 -0
  34. package/lib/instrumentation/azure-functions.js +519 -0
  35. package/lib/instrumentation/context.js +56 -0
  36. package/lib/instrumentation/dropped-spans-stats.js +112 -0
  37. package/lib/instrumentation/elasticsearch-shared.js +63 -0
  38. package/lib/instrumentation/express-utils.js +91 -0
  39. package/lib/instrumentation/generic-span.js +322 -0
  40. package/lib/instrumentation/http-shared.js +424 -0
  41. package/lib/instrumentation/ids.js +39 -0
  42. package/lib/instrumentation/index.js +1127 -0
  43. package/lib/instrumentation/modules/@apollo/server.js +30 -0
  44. package/lib/instrumentation/modules/@aws-sdk/client-dynamodb.js +143 -0
  45. package/lib/instrumentation/modules/@aws-sdk/client-s3.js +230 -0
  46. package/lib/instrumentation/modules/@aws-sdk/client-sns.js +197 -0
  47. package/lib/instrumentation/modules/@aws-sdk/client-sqs.js +336 -0
  48. package/lib/instrumentation/modules/@elastic/elasticsearch.js +343 -0
  49. package/lib/instrumentation/modules/@hapi/hapi.js +221 -0
  50. package/lib/instrumentation/modules/@opentelemetry/api.js +86 -0
  51. package/lib/instrumentation/modules/@opentelemetry/sdk-metrics.js +79 -0
  52. package/lib/instrumentation/modules/@redis/client/dist/lib/client/commands-queue.js +178 -0
  53. package/lib/instrumentation/modules/@redis/client/dist/lib/client/index.js +49 -0
  54. package/lib/instrumentation/modules/@smithy/smithy-client.js +198 -0
  55. package/lib/instrumentation/modules/_lambda-handler.js +40 -0
  56. package/lib/instrumentation/modules/apollo-server-core.js +49 -0
  57. package/lib/instrumentation/modules/aws-sdk/dynamodb.js +155 -0
  58. package/lib/instrumentation/modules/aws-sdk/s3.js +184 -0
  59. package/lib/instrumentation/modules/aws-sdk/sns.js +232 -0
  60. package/lib/instrumentation/modules/aws-sdk/sqs.js +361 -0
  61. package/lib/instrumentation/modules/aws-sdk.js +76 -0
  62. package/lib/instrumentation/modules/bluebird.js +93 -0
  63. package/lib/instrumentation/modules/cassandra-driver.js +280 -0
  64. package/lib/instrumentation/modules/elasticsearch.js +191 -0
  65. package/lib/instrumentation/modules/express-graphql.js +66 -0
  66. package/lib/instrumentation/modules/express-queue.js +28 -0
  67. package/lib/instrumentation/modules/express.js +162 -0
  68. package/lib/instrumentation/modules/fastify.js +172 -0
  69. package/lib/instrumentation/modules/finalhandler.js +41 -0
  70. package/lib/instrumentation/modules/generic-pool.js +85 -0
  71. package/lib/instrumentation/modules/graphql.js +256 -0
  72. package/lib/instrumentation/modules/handlebars.js +22 -0
  73. package/lib/instrumentation/modules/http.js +112 -0
  74. package/lib/instrumentation/modules/http2.js +320 -0
  75. package/lib/instrumentation/modules/https.js +68 -0
  76. package/lib/instrumentation/modules/ioredis.js +94 -0
  77. package/lib/instrumentation/modules/jade.js +18 -0
  78. package/lib/instrumentation/modules/kafkajs.js +476 -0
  79. package/lib/instrumentation/modules/knex.js +91 -0
  80. package/lib/instrumentation/modules/koa-router.js +74 -0
  81. package/lib/instrumentation/modules/koa.js +15 -0
  82. package/lib/instrumentation/modules/memcached.js +99 -0
  83. package/lib/instrumentation/modules/mimic-response.js +45 -0
  84. package/lib/instrumentation/modules/mongodb/lib/cmap/connection_pool.js +40 -0
  85. package/lib/instrumentation/modules/mongodb-core.js +206 -0
  86. package/lib/instrumentation/modules/mongodb.js +259 -0
  87. package/lib/instrumentation/modules/mysql.js +200 -0
  88. package/lib/instrumentation/modules/mysql2.js +140 -0
  89. package/lib/instrumentation/modules/pg.js +148 -0
  90. package/lib/instrumentation/modules/pug.js +18 -0
  91. package/lib/instrumentation/modules/redis.js +176 -0
  92. package/lib/instrumentation/modules/restify.js +52 -0
  93. package/lib/instrumentation/modules/tedious.js +159 -0
  94. package/lib/instrumentation/modules/undici.js +270 -0
  95. package/lib/instrumentation/modules/ws.js +59 -0
  96. package/lib/instrumentation/noop-transaction.js +81 -0
  97. package/lib/instrumentation/run-context/AbstractRunContextManager.js +215 -0
  98. package/lib/instrumentation/run-context/AsyncHooksRunContextManager.js +106 -0
  99. package/lib/instrumentation/run-context/AsyncLocalStorageRunContextManager.js +73 -0
  100. package/lib/instrumentation/run-context/BasicRunContextManager.js +82 -0
  101. package/lib/instrumentation/run-context/RunContext.js +151 -0
  102. package/lib/instrumentation/run-context/index.js +23 -0
  103. package/lib/instrumentation/shimmer.js +123 -0
  104. package/lib/instrumentation/span-compression.js +239 -0
  105. package/lib/instrumentation/span.js +621 -0
  106. package/lib/instrumentation/template-shared.js +43 -0
  107. package/lib/instrumentation/timer.js +84 -0
  108. package/lib/instrumentation/transaction.js +571 -0
  109. package/lib/lambda.js +992 -0
  110. package/lib/load-source-map.js +100 -0
  111. package/lib/logging.js +212 -0
  112. package/lib/metrics/index.js +92 -0
  113. package/lib/metrics/platforms/generic/index.js +40 -0
  114. package/lib/metrics/platforms/generic/process-cpu.js +22 -0
  115. package/lib/metrics/platforms/generic/process-top.js +157 -0
  116. package/lib/metrics/platforms/generic/stats.js +34 -0
  117. package/lib/metrics/platforms/generic/system-cpu.js +51 -0
  118. package/lib/metrics/platforms/linux/index.js +19 -0
  119. package/lib/metrics/platforms/linux/stats.js +213 -0
  120. package/lib/metrics/queue.js +90 -0
  121. package/lib/metrics/registry.js +52 -0
  122. package/lib/metrics/reporter.js +119 -0
  123. package/lib/metrics/runtime.js +77 -0
  124. package/lib/middleware/connect.js +16 -0
  125. package/lib/opentelemetry-bridge/OTelBridgeNonRecordingSpan.js +150 -0
  126. package/lib/opentelemetry-bridge/OTelBridgeRunContext.js +124 -0
  127. package/lib/opentelemetry-bridge/OTelContextManager.js +82 -0
  128. package/lib/opentelemetry-bridge/OTelSpan.js +344 -0
  129. package/lib/opentelemetry-bridge/OTelTracer.js +201 -0
  130. package/lib/opentelemetry-bridge/OTelTracerProvider.js +25 -0
  131. package/lib/opentelemetry-bridge/README.md +244 -0
  132. package/lib/opentelemetry-bridge/index.js +15 -0
  133. package/lib/opentelemetry-bridge/oblog.js +23 -0
  134. package/lib/opentelemetry-bridge/opentelemetry-core-mini/README.md +3 -0
  135. package/lib/opentelemetry-bridge/opentelemetry-core-mini/internal/validators.js +52 -0
  136. package/lib/opentelemetry-bridge/opentelemetry-core-mini/trace/TraceState.js +109 -0
  137. package/lib/opentelemetry-bridge/otelutils.js +99 -0
  138. package/lib/opentelemetry-bridge/setup.js +76 -0
  139. package/lib/opentelemetry-metrics/ElasticApmMetricExporter.js +285 -0
  140. package/lib/opentelemetry-metrics/index.js +50 -0
  141. package/lib/parsers.js +225 -0
  142. package/lib/propwrap.js +147 -0
  143. package/lib/stacktraces.js +537 -0
  144. package/lib/symbols.js +15 -0
  145. package/lib/tracecontext/index.js +118 -0
  146. package/lib/tracecontext/traceparent.js +185 -0
  147. package/lib/tracecontext/tracestate.js +388 -0
  148. package/lib/wildcard-matcher.js +52 -0
  149. package/loader.mjs +7 -0
  150. package/package.json +299 -0
  151. package/start.d.ts +8 -0
  152. package/start.js +29 -0
  153. package/types/aws-lambda.d.ts +98 -0
  154. package/types/connect.d.ts +23 -0
@@ -0,0 +1,31 @@
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
+ // Logging utilities for the APM http client.
10
+
11
+ // A logger that does nothing and supports enough of the pino API
12
+ // (https://getpino.io/#/docs/api?id=logger) for use as a fallback in
13
+ // this package.
14
+ class NoopLogger {
15
+ trace() {}
16
+ debug() {}
17
+ info() {}
18
+ warn() {}
19
+ error() {}
20
+ fatal() {}
21
+ child() {
22
+ return this;
23
+ }
24
+ isLevelEnabled(_level) {
25
+ return false;
26
+ }
27
+ }
28
+
29
+ module.exports = {
30
+ NoopLogger,
31
+ };
@@ -0,0 +1,20 @@
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 stringify = require('fast-safe-stringify');
10
+
11
+ exports.serialize = function serialize(obj) {
12
+ const str = tryJSONStringify(obj) || stringify(obj);
13
+ return str + '\n';
14
+ };
15
+
16
+ function tryJSONStringify(obj) {
17
+ try {
18
+ return JSON.stringify(obj);
19
+ } catch (e) {}
20
+ }
@@ -0,0 +1,434 @@
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
+ var breadthFilter = require('breadth-filter');
10
+
11
+ exports.metadata = truncMetadata;
12
+ exports.transaction = truncTransaction;
13
+ exports.span = truncSpan;
14
+ exports.error = truncError;
15
+ exports.metricset = truncMetricSet;
16
+
17
+ // Truncate the string `s` to a `max` maximum number of JavaScript characters.
18
+ //
19
+ // Note that JavaScript uses UCS-2 internally, so characters outside of the
20
+ // BMP are represented as surrogate pairs. These count as *two* characters.
21
+ // The result is that a string with surrogate pairs will appear to be truncated
22
+ // shorter than expected:
23
+ // unitrunc('aaaa', 4) // => 'aaaa'
24
+ // unitrunc('😂😂😂😂', 4) // => '😂😂'
25
+ //
26
+ // This will avoid truncating in the middle of a surrogate pair by truncating
27
+ // one character earlier. For example:
28
+ // unitrunc('foo😂bar', 4) // => 'foo'
29
+ function unitrunc(s, max) {
30
+ if (s.length > max) {
31
+ if (max <= 0) {
32
+ return '';
33
+ }
34
+ // If the last character is a "high" surrogate (D800–DBFF) per
35
+ // https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates
36
+ // then we would truncate in the middle of a surrogate pair. Move back one
37
+ // char to have a clean(er) truncation.
38
+ const endChar = s.charCodeAt(max - 1);
39
+ if (endChar >= 0xd800 && endChar <= 0xdbff) {
40
+ return s.slice(0, max - 1);
41
+ } else {
42
+ return s.slice(0, max);
43
+ }
44
+ }
45
+ return s;
46
+ }
47
+
48
+ function truncMetadata(metadata, opts) {
49
+ return breadthFilter(metadata, {
50
+ onArray,
51
+ onObject,
52
+ onValue(value, key, path) {
53
+ if (typeof value !== 'string') {
54
+ return value;
55
+ }
56
+
57
+ let max = opts.truncateStringsAt;
58
+ switch (path[0]) {
59
+ case 'service':
60
+ switch (path[1]) {
61
+ case 'name':
62
+ case 'version':
63
+ case 'environment':
64
+ max = opts.truncateKeywordsAt;
65
+ break;
66
+
67
+ case 'agent':
68
+ case 'framework':
69
+ case 'language':
70
+ case 'runtime':
71
+ switch (path[2]) {
72
+ case 'name':
73
+ case 'version':
74
+ max = opts.truncateKeywordsAt;
75
+ break;
76
+ }
77
+ break;
78
+ }
79
+ break;
80
+
81
+ case 'process':
82
+ if (path[1] === 'title') {
83
+ max = opts.truncateKeywordsAt;
84
+ }
85
+ break;
86
+
87
+ case 'system':
88
+ switch (path[1]) {
89
+ case 'architecture':
90
+ case 'hostname':
91
+ case 'platform':
92
+ max = opts.truncateKeywordsAt;
93
+ break;
94
+ }
95
+ break;
96
+ case 'cloud':
97
+ switch (path[1]) {
98
+ case 'availability_zone':
99
+ case 'provider':
100
+ case 'region':
101
+ max = opts.truncateKeywordsAt;
102
+ break;
103
+ case 'account':
104
+ switch (path[2]) {
105
+ case 'id':
106
+ case 'name':
107
+ max = opts.truncateKeywordsAt;
108
+ break;
109
+ }
110
+ break;
111
+ case 'instance':
112
+ switch (path[2]) {
113
+ case 'id':
114
+ case 'name':
115
+ max = opts.truncateKeywordsAt;
116
+ break;
117
+ }
118
+ break;
119
+ case 'machine':
120
+ switch (path[2]) {
121
+ case 'type':
122
+ max = opts.truncateKeywordsAt;
123
+ break;
124
+ }
125
+ break;
126
+ case 'project':
127
+ switch (path[2]) {
128
+ case 'id':
129
+ case 'name':
130
+ max = opts.truncateKeywordsAt;
131
+ break;
132
+ }
133
+ }
134
+ break;
135
+ }
136
+
137
+ return unitrunc(value, max);
138
+ },
139
+ });
140
+ }
141
+
142
+ function truncTransaction(trans, opts) {
143
+ const result = breadthFilter(trans, {
144
+ onArray,
145
+ onObject: onObjectWithHeaders,
146
+ onValue(value, key, path) {
147
+ if (typeof value !== 'string') {
148
+ if (isHeader(path)) return String(value);
149
+
150
+ return value;
151
+ }
152
+
153
+ let max = opts.truncateStringsAt;
154
+ switch (path[0]) {
155
+ case 'name':
156
+ case 'type':
157
+ case 'result':
158
+ case 'id':
159
+ case 'trace_id':
160
+ case 'parent_id':
161
+ max = opts.truncateKeywordsAt;
162
+ break;
163
+
164
+ case 'context':
165
+ max = contextLength(path, opts);
166
+ break;
167
+ }
168
+
169
+ return unitrunc(value, max);
170
+ },
171
+ });
172
+
173
+ return Object.assign(
174
+ {
175
+ name: 'undefined',
176
+ type: 'undefined',
177
+ result: 'undefined',
178
+ },
179
+ result,
180
+ );
181
+ }
182
+
183
+ function truncSpan(span, opts) {
184
+ let result = breadthFilter(span, {
185
+ onArray,
186
+ onObject,
187
+ onValue(value, key, path) {
188
+ if (typeof value !== 'string') {
189
+ return value;
190
+ }
191
+
192
+ let max = opts.truncateStringsAt;
193
+ switch (path[0]) {
194
+ case 'name':
195
+ case 'type':
196
+ case 'id':
197
+ case 'trace_id':
198
+ case 'parent_id':
199
+ case 'transaction_id':
200
+ case 'subtype':
201
+ case 'action':
202
+ max = opts.truncateKeywordsAt;
203
+ break;
204
+
205
+ case 'context':
206
+ max = contextLength(path, opts);
207
+ break;
208
+ }
209
+
210
+ return unitrunc(value, max);
211
+ },
212
+ });
213
+
214
+ result = truncateCustomKeys(result, opts.truncateCustomKeysAt, [
215
+ 'name',
216
+ 'type',
217
+ 'id',
218
+ 'trace_id',
219
+ 'parent_id',
220
+ 'transaction_id',
221
+ 'subtype',
222
+ 'action',
223
+ 'context',
224
+ ]);
225
+
226
+ return Object.assign(
227
+ {
228
+ name: 'undefined',
229
+ type: 'undefined',
230
+ },
231
+ result,
232
+ );
233
+ }
234
+
235
+ function truncError(error, opts) {
236
+ return breadthFilter(error, {
237
+ onArray,
238
+ onObject: onObjectWithHeaders,
239
+ onValue(value, key, path) {
240
+ if (typeof value !== 'string') {
241
+ if (isHeader(path)) return String(value);
242
+
243
+ return value;
244
+ }
245
+
246
+ let max = opts.truncateStringsAt;
247
+ switch (path[0]) {
248
+ case 'id':
249
+ case 'trace_id':
250
+ case 'parent_id':
251
+ case 'transaction_id':
252
+ max = opts.truncateKeywordsAt;
253
+ break;
254
+
255
+ case 'context':
256
+ max = contextLength(path, opts);
257
+ break;
258
+
259
+ case 'log':
260
+ switch (path[1]) {
261
+ case 'level':
262
+ case 'logger_name':
263
+ case 'param_message':
264
+ max = opts.truncateKeywordsAt;
265
+ break;
266
+
267
+ case 'message':
268
+ if (opts.truncateErrorMessagesAt === undefined) {
269
+ max = opts.truncateLongFieldsAt;
270
+ } else if (opts.truncateErrorMessagesAt < 0) {
271
+ return value; // skip truncation
272
+ } else {
273
+ max = opts.truncateErrorMessagesAt;
274
+ }
275
+ break;
276
+ }
277
+ break;
278
+
279
+ case 'exception':
280
+ switch (path[1]) {
281
+ case 'type':
282
+ case 'code':
283
+ case 'module':
284
+ max = opts.truncateKeywordsAt;
285
+ break;
286
+ case 'message':
287
+ if (opts.truncateErrorMessagesAt === undefined) {
288
+ max = opts.truncateLongFieldsAt;
289
+ } else if (opts.truncateErrorMessagesAt < 0) {
290
+ return value; // skip truncation
291
+ } else {
292
+ max = opts.truncateErrorMessagesAt;
293
+ }
294
+ break;
295
+ }
296
+ break;
297
+ }
298
+
299
+ return unitrunc(value, max);
300
+ },
301
+ });
302
+ }
303
+
304
+ function truncMetricSet(metricset, opts) {
305
+ return breadthFilter(metricset, {
306
+ onArray,
307
+ onObject,
308
+ onValue(value, key, path) {
309
+ if (typeof value !== 'string') {
310
+ return value;
311
+ }
312
+
313
+ const max =
314
+ path[0] === 'tags' ? opts.truncateKeywordsAt : opts.truncateStringsAt;
315
+
316
+ return unitrunc(value, max);
317
+ },
318
+ });
319
+ }
320
+
321
+ function contextLength(path, opts) {
322
+ switch (path[1]) {
323
+ case 'db':
324
+ if (path[2] === 'statement') {
325
+ return opts.truncateLongFieldsAt;
326
+ }
327
+ break;
328
+
329
+ case 'message':
330
+ if (path[2] === 'body') {
331
+ return opts.truncateLongFieldsAt;
332
+ }
333
+ break;
334
+
335
+ case 'request':
336
+ switch (path[2]) {
337
+ case 'method':
338
+ case 'http_version':
339
+ return opts.truncateKeywordsAt;
340
+
341
+ case 'body':
342
+ return opts.truncateLongFieldsAt;
343
+
344
+ case 'url':
345
+ switch (path[3]) {
346
+ case 'protocol':
347
+ case 'hostname':
348
+ case 'port':
349
+ case 'pathname':
350
+ case 'search':
351
+ case 'hash':
352
+ case 'raw':
353
+ case 'full':
354
+ return opts.truncateKeywordsAt;
355
+ }
356
+ break;
357
+ }
358
+ break;
359
+
360
+ case 'user':
361
+ switch (path[2]) {
362
+ case 'id':
363
+ case 'email':
364
+ case 'username':
365
+ return opts.truncateKeywordsAt;
366
+ }
367
+ break;
368
+
369
+ case 'tags':
370
+ return opts.truncateKeywordsAt;
371
+
372
+ case 'destination':
373
+ switch (path[2]) {
374
+ case 'address':
375
+ return opts.truncateKeywordsAt;
376
+
377
+ case 'service':
378
+ switch (path[3]) {
379
+ case 'name':
380
+ case 'resource':
381
+ case 'type':
382
+ return opts.truncateKeywordsAt;
383
+ }
384
+ break;
385
+ }
386
+ break;
387
+ }
388
+
389
+ return opts.truncateStringsAt;
390
+ }
391
+
392
+ function isHeader(path) {
393
+ return (
394
+ path[0] === 'context' &&
395
+ (path[1] === 'request' || path[1] === 'response') &&
396
+ path[2] === 'headers' &&
397
+ path[3]
398
+ );
399
+ }
400
+
401
+ function onObjectWithHeaders(value, key, path, isNew) {
402
+ if (isHeader(path)) return String(value);
403
+ return onObject(value, key, path, isNew);
404
+ }
405
+
406
+ function onObject(value, key, path, isNew) {
407
+ return isNew ? {} : '[Circular]';
408
+ }
409
+
410
+ function onArray(value, key, path, isNew) {
411
+ return isNew ? [] : '[Circular]';
412
+ }
413
+
414
+ function truncateCustomKeys(value, max, keywords) {
415
+ if (typeof value !== 'object' || value === null) {
416
+ return value;
417
+ }
418
+ const result = value;
419
+ const keys = Object.keys(result);
420
+ const truncatedKeys = keys.map((k) => {
421
+ if (keywords.includes(k)) {
422
+ return k;
423
+ }
424
+ return unitrunc(k, max);
425
+ });
426
+
427
+ for (const [index, k] of keys.entries()) {
428
+ const value = result[k];
429
+ delete result[k];
430
+ const newKey = truncatedKeys[index];
431
+ result[newKey] = truncateCustomKeys(value, max, keywords);
432
+ }
433
+ return result;
434
+ }
@@ -0,0 +1,73 @@
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
+ // A no-op (does nothing) APM Client -- i.e. the APM server client API
10
+ // provided by elastic-apm-http-client.
11
+ //
12
+ // This is used for some configurations (when `disableSend=true` or when
13
+ // `contextPropagationOnly=true`) and in some tests.
14
+
15
+ class NoopApmClient {
16
+ config(opts) {}
17
+
18
+ addMetadataFilter(fn) {}
19
+ setExtraMetadata(metadata) {}
20
+
21
+ lambdaStart() {}
22
+ lambdaShouldRegisterTransactions() {
23
+ return true;
24
+ }
25
+ lambdaRegisterTransaction(trans, awsRequestId) {}
26
+
27
+ sendSpan(span, cb) {
28
+ if (cb) {
29
+ process.nextTick(cb);
30
+ }
31
+ }
32
+
33
+ sendTransaction(transaction, cb) {
34
+ if (cb) {
35
+ process.nextTick(cb);
36
+ }
37
+ }
38
+
39
+ sendError(_error, cb) {
40
+ if (cb) {
41
+ process.nextTick(cb);
42
+ }
43
+ }
44
+
45
+ sendMetricSet(metricset, cb) {
46
+ if (cb) {
47
+ process.nextTick(cb);
48
+ }
49
+ }
50
+
51
+ flush(opts, cb) {
52
+ if (typeof opts === 'function') {
53
+ cb = opts;
54
+ opts = {};
55
+ } else if (!opts) {
56
+ opts = {};
57
+ }
58
+ if (cb) {
59
+ process.nextTick(cb);
60
+ }
61
+ }
62
+
63
+ supportsKeepingUnsampledTransaction() {
64
+ return true;
65
+ }
66
+
67
+ // Inherited from Writable, called in agent.js.
68
+ destroy() {}
69
+ }
70
+
71
+ module.exports = {
72
+ NoopApmClient,
73
+ };
@@ -0,0 +1,58 @@
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 async_hooks = require('async_hooks');
10
+ const semver = require('semver');
11
+
12
+ // A polyfilled `AsyncResource.bind` that behaves like Node.js v17.8.0.
13
+ // https://nodejs.org/api/async_context.html#asyncresourcebindfn-thisarg
14
+ // Adapted from dd-trace and
15
+ // https://github.com/nodejs/node/blob/v17.8.0/lib/async_hooks.js#L227-L260
16
+ let AsyncResource;
17
+ if (semver.satisfies(process.versions.node, '>=17.8.0')) {
18
+ AsyncResource = async_hooks.AsyncResource;
19
+ } else {
20
+ AsyncResource = class extends async_hooks.AsyncResource {
21
+ static bind(fn, type, thisArg) {
22
+ type = type || fn.name;
23
+ return new AsyncResource(type || 'bound-anonymous-fn').bind(fn, thisArg);
24
+ }
25
+
26
+ bind(fn, thisArg) {
27
+ let bound;
28
+ if (thisArg === undefined) {
29
+ const resource = this;
30
+ bound = function (...args) {
31
+ args.unshift(fn, this);
32
+ return Reflect.apply(resource.runInAsyncScope, resource, args);
33
+ };
34
+ } else {
35
+ bound = this.runInAsyncScope.bind(this, fn, thisArg);
36
+ }
37
+ Object.defineProperties(bound, {
38
+ length: {
39
+ configurable: true,
40
+ enumerable: false,
41
+ value: fn.length,
42
+ writable: false,
43
+ },
44
+ asyncResource: {
45
+ configurable: true,
46
+ enumerable: true,
47
+ value: this,
48
+ writable: true,
49
+ },
50
+ });
51
+ return bound;
52
+ }
53
+ };
54
+ }
55
+
56
+ module.exports = {
57
+ AsyncResource,
58
+ };