@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,239 @@
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
+ const STRATEGY_EXACT_MATCH = 'exact_match';
9
+ const STRATEGY_SAME_KIND = 'same_kind';
10
+
11
+ class SpanCompression {
12
+ constructor(agent) {
13
+ this._bufferedSpan = null;
14
+ this._agent = agent;
15
+ this.timestamp = null;
16
+ this.duration = 0;
17
+ this.composite = {
18
+ count: 0,
19
+ sum: 0,
20
+ compression_strategy: null,
21
+ };
22
+ }
23
+
24
+ setBufferedSpan(span) {
25
+ this._bufferedSpan = span;
26
+ }
27
+
28
+ getBufferedSpan() {
29
+ return this._bufferedSpan;
30
+ }
31
+
32
+ // Compares two spans and returns which compression strategy to use
33
+ // or returns false if the second span can't be compressed into the
34
+ // first.
35
+ //
36
+ // @param Span compositeSpan
37
+ // @param Span toCompressSpan
38
+ // @returns boolean|String
39
+ _getCompressionStrategy(compositeSpan, toCompressSpan) {
40
+ if (
41
+ !this._isEnabled() ||
42
+ !compositeSpan._serviceTarget ||
43
+ !toCompressSpan._serviceTarget
44
+ ) {
45
+ return false;
46
+ }
47
+
48
+ const isSameKind = this.isSameKind(compositeSpan, toCompressSpan);
49
+
50
+ if (!isSameKind) {
51
+ return false;
52
+ }
53
+
54
+ let strategy = STRATEGY_SAME_KIND;
55
+ if (compositeSpan.name === toCompressSpan.name) {
56
+ strategy = STRATEGY_EXACT_MATCH;
57
+ }
58
+
59
+ return strategy;
60
+ }
61
+
62
+ isSameKind(compositeSpan, toCompressSpan) {
63
+ return (
64
+ compositeSpan.type === toCompressSpan.type &&
65
+ compositeSpan.subtype === toCompressSpan.subtype &&
66
+ compositeSpan._serviceTarget.type ===
67
+ toCompressSpan._serviceTarget.type &&
68
+ compositeSpan._serviceTarget.name === toCompressSpan._serviceTarget.name
69
+ );
70
+ }
71
+
72
+ // Sets initial composite values or confirms strategy matches
73
+ //
74
+ // Returns true if spanToCompress can be compressed into compositeSpan,
75
+ // returns false otherwise.
76
+ //
77
+ // @param Span compositeSpan
78
+ // @param Span spanToCompress
79
+ // @returns boolean
80
+ _initCompressionStrategy(compositeSpan, spanToCompress) {
81
+ if (!this.composite.compression_strategy) {
82
+ // If no strategy is set, check if strategizable or not. If so,
83
+ // set initial values. If not, bail.
84
+ this.composite.compression_strategy = this._getCompressionStrategy(
85
+ compositeSpan,
86
+ spanToCompress,
87
+ );
88
+ if (!this.composite.compression_strategy) {
89
+ return false;
90
+ }
91
+
92
+ // set initial composite context values
93
+ this.timestamp = compositeSpan.timestamp;
94
+ this.composite.count = 1;
95
+ this.composite.sum = compositeSpan._duration;
96
+ } else {
97
+ // if so, compare with the compression strat and bail if mismatch
98
+ const strat = this._getCompressionStrategy(compositeSpan, spanToCompress);
99
+ if (strat !== this.composite.compression_strategy) {
100
+ return false;
101
+ }
102
+ }
103
+
104
+ return true;
105
+ }
106
+
107
+ // Attempts to compression the second span into the first
108
+ //
109
+ // @param Span compositeSpan
110
+ // @param Span spanToCompress
111
+ // @return boolean
112
+ tryToCompress(compositeSpan, spanToCompress) {
113
+ if (!this._isEnabled()) {
114
+ return false;
115
+ }
116
+
117
+ // sets initial compression strategy value. returns
118
+ // false if not compression eligable
119
+ if (!this._initCompressionStrategy(compositeSpan, spanToCompress)) {
120
+ return false;
121
+ }
122
+
123
+ const isAlreadyComposite = this.isComposite();
124
+ const canBeCompressed = isAlreadyComposite
125
+ ? this.tryToCompressComposite(compositeSpan, spanToCompress)
126
+ : this.tryToCompressRegular(compositeSpan, spanToCompress);
127
+
128
+ if (!canBeCompressed) {
129
+ return false;
130
+ }
131
+
132
+ if (!isAlreadyComposite) {
133
+ this.composite.count = 1;
134
+ this.composite.sum = compositeSpan._duration;
135
+ }
136
+
137
+ this.composite.count++;
138
+ this.composite.sum += spanToCompress._duration;
139
+ this.duration =
140
+ (spanToCompress._endTimestamp - compositeSpan.timestamp) / 1000;
141
+ return true;
142
+ }
143
+
144
+ tryToCompressRegular(compositeSpan, spanToCompress) {
145
+ if (!this.isSameKind(compositeSpan, spanToCompress)) {
146
+ return false;
147
+ }
148
+
149
+ if (compositeSpan.name === spanToCompress.name) {
150
+ if (
151
+ this.duration <=
152
+ this._agent._conf.spanCompressionExactMatchMaxDuration * 1000 &&
153
+ spanToCompress._duration <=
154
+ this._agent._conf.spanCompressionExactMatchMaxDuration * 1000
155
+ ) {
156
+ this.composite.compression_strategy = STRATEGY_EXACT_MATCH;
157
+ return true;
158
+ }
159
+ return false;
160
+ }
161
+
162
+ if (
163
+ this.duration <=
164
+ this._agent._conf.spanCompressionSameKindMaxDuration * 1000 &&
165
+ spanToCompress._duration <=
166
+ this._agent._conf.spanCompressionSameKindMaxDuration * 1000
167
+ ) {
168
+ this.composite.compression_strategy = STRATEGY_SAME_KIND;
169
+ compositeSpan.name = this._spanNameFromCompositeSpan(compositeSpan);
170
+ return true;
171
+ }
172
+
173
+ return false;
174
+ }
175
+
176
+ tryToCompressComposite(compositeSpan, spanToCompress) {
177
+ switch (this.composite.compression_strategy) {
178
+ case STRATEGY_EXACT_MATCH:
179
+ return (
180
+ this.isSameKind(compositeSpan, spanToCompress) &&
181
+ compositeSpan.name === spanToCompress.name &&
182
+ spanToCompress._duration <=
183
+ this._agent._conf.spanCompressionExactMatchMaxDuration * 1000
184
+ );
185
+ case STRATEGY_SAME_KIND:
186
+ return (
187
+ this.isSameKind(compositeSpan, spanToCompress) &&
188
+ spanToCompress._duration <=
189
+ this._agent._conf.spanCompressionSameKindMaxDuration * 1000
190
+ );
191
+ }
192
+ }
193
+
194
+ _spanNameFromCompositeSpan(compositeSpan) {
195
+ const prefix = 'Calls to ';
196
+ const serviceTarget = compositeSpan._serviceTarget;
197
+ if (!serviceTarget.type) {
198
+ if (!serviceTarget.name) {
199
+ return prefix + 'unknown';
200
+ } else {
201
+ return prefix + serviceTarget.name;
202
+ }
203
+ } else if (!serviceTarget.name) {
204
+ return prefix + serviceTarget.type;
205
+ } else {
206
+ return prefix + serviceTarget.type + '/' + serviceTarget.name;
207
+ }
208
+ }
209
+
210
+ _isEnabled() {
211
+ return this._agent._conf.spanCompressionEnabled;
212
+ }
213
+
214
+ isCompositeSameKind() {
215
+ return this.composite.compression_strategy === STRATEGY_SAME_KIND;
216
+ }
217
+
218
+ isComposite() {
219
+ return this.composite.count > 1;
220
+ }
221
+
222
+ // Encodes/Serializes composite span properties
223
+ // @return Object
224
+ encode() {
225
+ return {
226
+ compression_strategy: this.composite.compression_strategy,
227
+ count: this.composite.count,
228
+ sum: this.composite.sum,
229
+ };
230
+ }
231
+ }
232
+
233
+ module.exports = {
234
+ SpanCompression,
235
+ constants: {
236
+ STRATEGY_EXACT_MATCH,
237
+ STRATEGY_SAME_KIND,
238
+ },
239
+ };