dd-trace 3.3.1 → 3.12.1

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 (198) hide show
  1. package/LICENSE-3rdparty.csv +8 -0
  2. package/README.md +108 -43
  3. package/ci/init.js +6 -1
  4. package/ext/exporters.d.ts +2 -1
  5. package/ext/exporters.js +2 -1
  6. package/index.d.ts +129 -36
  7. package/package.json +18 -9
  8. package/packages/datadog-instrumentations/src/body-parser.js +26 -0
  9. package/packages/datadog-instrumentations/src/cassandra-driver.js +7 -7
  10. package/packages/datadog-instrumentations/src/child-process.js +30 -0
  11. package/packages/datadog-instrumentations/src/connect.js +15 -15
  12. package/packages/datadog-instrumentations/src/cucumber.js +1 -3
  13. package/packages/datadog-instrumentations/src/elasticsearch.js +51 -47
  14. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +1 -1
  15. package/packages/datadog-instrumentations/src/helpers/hooks.js +9 -0
  16. package/packages/datadog-instrumentations/src/helpers/register.js +5 -0
  17. package/packages/datadog-instrumentations/src/http/server.js +20 -12
  18. package/packages/datadog-instrumentations/src/http2/server.js +67 -1
  19. package/packages/datadog-instrumentations/src/jest.js +182 -25
  20. package/packages/datadog-instrumentations/src/koa.js +32 -32
  21. package/packages/datadog-instrumentations/src/ldapjs.js +91 -0
  22. package/packages/datadog-instrumentations/src/mariadb.js +63 -0
  23. package/packages/datadog-instrumentations/src/memcached.js +1 -4
  24. package/packages/datadog-instrumentations/src/mocha.js +135 -24
  25. package/packages/datadog-instrumentations/src/next.js +10 -2
  26. package/packages/datadog-instrumentations/src/opensearch.js +10 -0
  27. package/packages/datadog-instrumentations/src/oracledb.js +8 -8
  28. package/packages/datadog-instrumentations/src/pg.js +7 -3
  29. package/packages/datadog-instrumentations/src/qs.js +24 -0
  30. package/packages/datadog-instrumentations/src/redis.js +12 -3
  31. package/packages/datadog-instrumentations/src/restify.js +5 -1
  32. package/packages/datadog-instrumentations/src/rhea.js +29 -15
  33. package/packages/datadog-instrumentations/src/router.js +23 -23
  34. package/packages/datadog-plugin-amqp10/src/consumer.js +32 -0
  35. package/packages/datadog-plugin-amqp10/src/index.js +11 -101
  36. package/packages/datadog-plugin-amqp10/src/producer.js +34 -0
  37. package/packages/datadog-plugin-amqp10/src/util.js +15 -0
  38. package/packages/datadog-plugin-amqplib/src/client.js +38 -0
  39. package/packages/datadog-plugin-amqplib/src/consumer.js +40 -0
  40. package/packages/datadog-plugin-amqplib/src/index.js +14 -102
  41. package/packages/datadog-plugin-amqplib/src/producer.js +37 -0
  42. package/packages/datadog-plugin-amqplib/src/util.js +14 -0
  43. package/packages/datadog-plugin-cassandra-driver/src/index.js +22 -60
  44. package/packages/datadog-plugin-cucumber/src/index.js +14 -33
  45. package/packages/datadog-plugin-cypress/src/plugin.js +2 -1
  46. package/packages/datadog-plugin-dns/src/index.js +16 -91
  47. package/packages/datadog-plugin-dns/src/lookup.js +40 -0
  48. package/packages/datadog-plugin-dns/src/lookup_service.js +24 -0
  49. package/packages/datadog-plugin-dns/src/resolve.js +24 -0
  50. package/packages/datadog-plugin-dns/src/reverse.js +21 -0
  51. package/packages/datadog-plugin-elasticsearch/src/index.js +24 -60
  52. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +24 -0
  53. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +41 -0
  54. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +14 -99
  55. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +33 -0
  56. package/packages/datadog-plugin-graphql/src/execute.js +73 -0
  57. package/packages/datadog-plugin-graphql/src/index.js +14 -176
  58. package/packages/datadog-plugin-graphql/src/parse.js +32 -0
  59. package/packages/datadog-plugin-graphql/src/resolve.js +70 -76
  60. package/packages/datadog-plugin-graphql/src/validate.js +28 -0
  61. package/packages/datadog-plugin-grpc/src/client.js +46 -55
  62. package/packages/datadog-plugin-grpc/src/index.js +7 -24
  63. package/packages/datadog-plugin-grpc/src/server.js +50 -52
  64. package/packages/datadog-plugin-grpc/src/util.js +15 -14
  65. package/packages/datadog-plugin-http/src/client.js +15 -5
  66. package/packages/datadog-plugin-http/src/index.js +7 -22
  67. package/packages/datadog-plugin-http/src/server.js +19 -3
  68. package/packages/datadog-plugin-http2/src/client.js +20 -1
  69. package/packages/datadog-plugin-http2/src/index.js +8 -26
  70. package/packages/datadog-plugin-http2/src/server.js +44 -0
  71. package/packages/datadog-plugin-jest/src/index.js +41 -65
  72. package/packages/datadog-plugin-kafkajs/src/consumer.js +42 -0
  73. package/packages/datadog-plugin-kafkajs/src/index.js +11 -87
  74. package/packages/datadog-plugin-kafkajs/src/producer.js +31 -0
  75. package/packages/datadog-plugin-mariadb/src/index.js +10 -0
  76. package/packages/datadog-plugin-memcached/src/index.js +17 -52
  77. package/packages/datadog-plugin-mocha/src/index.js +40 -60
  78. package/packages/datadog-plugin-moleculer/src/client.js +22 -36
  79. package/packages/datadog-plugin-moleculer/src/index.js +8 -26
  80. package/packages/datadog-plugin-moleculer/src/server.js +18 -30
  81. package/packages/datadog-plugin-mongodb-core/src/index.js +23 -51
  82. package/packages/datadog-plugin-mysql/src/index.js +23 -52
  83. package/packages/datadog-plugin-mysql2/src/index.js +1 -3
  84. package/packages/datadog-plugin-net/src/index.js +4 -0
  85. package/packages/datadog-plugin-net/src/ipc.js +21 -0
  86. package/packages/datadog-plugin-net/src/tcp.js +46 -0
  87. package/packages/datadog-plugin-next/src/index.js +3 -0
  88. package/packages/datadog-plugin-opensearch/src/index.js +11 -0
  89. package/packages/datadog-plugin-oracledb/src/index.js +29 -55
  90. package/packages/datadog-plugin-pg/src/index.js +27 -51
  91. package/packages/datadog-plugin-redis/src/index.js +29 -60
  92. package/packages/datadog-plugin-rhea/src/consumer.js +55 -0
  93. package/packages/datadog-plugin-rhea/src/index.js +11 -96
  94. package/packages/datadog-plugin-rhea/src/producer.js +45 -0
  95. package/packages/datadog-plugin-router/src/index.js +13 -2
  96. package/packages/datadog-plugin-sharedb/src/index.js +22 -39
  97. package/packages/datadog-plugin-tedious/src/index.js +20 -41
  98. package/packages/dd-trace/src/appsec/addresses.js +3 -1
  99. package/packages/dd-trace/src/appsec/blocking.js +44 -0
  100. package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +8 -6
  101. package/packages/dd-trace/src/appsec/gateway/engine/engine.js +1 -1
  102. package/packages/dd-trace/src/appsec/gateway/engine/index.js +7 -2
  103. package/packages/dd-trace/src/appsec/gateway/engine/runner.js +0 -1
  104. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +4 -1
  105. package/packages/dd-trace/src/appsec/iast/analyzers/command-injection-analyzer.js +11 -0
  106. package/packages/dd-trace/src/appsec/iast/analyzers/injection-analyzer.js +19 -0
  107. package/packages/dd-trace/src/appsec/iast/analyzers/ldap-injection-analyzer.js +11 -0
  108. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +13 -0
  109. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +43 -5
  110. package/packages/dd-trace/src/appsec/iast/iast-context.js +3 -1
  111. package/packages/dd-trace/src/appsec/iast/index.js +24 -8
  112. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +20 -1
  113. package/packages/dd-trace/src/appsec/iast/path-line.js +17 -6
  114. package/packages/dd-trace/src/appsec/iast/taint-tracking/csi-methods.js +17 -0
  115. package/packages/dd-trace/src/appsec/iast/taint-tracking/filter.js +16 -0
  116. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +18 -0
  117. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +98 -0
  118. package/packages/dd-trace/src/appsec/iast/taint-tracking/origin-types.js +4 -0
  119. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +38 -0
  120. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +67 -0
  121. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +103 -0
  122. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +98 -30
  123. package/packages/dd-trace/src/appsec/index.js +79 -25
  124. package/packages/dd-trace/src/{plugins/util → appsec}/ip_blocklist.js +0 -0
  125. package/packages/dd-trace/src/appsec/ip_extractor.js +98 -0
  126. package/packages/dd-trace/src/appsec/recommended.json +134 -53
  127. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +7 -0
  128. package/packages/dd-trace/src/appsec/remote_config/index.js +56 -0
  129. package/packages/dd-trace/src/appsec/remote_config/manager.js +264 -0
  130. package/packages/dd-trace/src/{exporters → appsec/remote_config}/scheduler.js +9 -9
  131. package/packages/dd-trace/src/appsec/rule_manager.js +61 -1
  132. package/packages/dd-trace/src/appsec/templates/blocked.html +99 -0
  133. package/packages/dd-trace/src/appsec/templates/blocked.json +8 -0
  134. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +66 -0
  135. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +9 -5
  136. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +19 -51
  137. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +10 -5
  138. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +202 -0
  139. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +51 -62
  140. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +89 -0
  141. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +82 -0
  142. package/packages/dd-trace/src/config.js +119 -35
  143. package/packages/dd-trace/src/constants.js +9 -1
  144. package/packages/dd-trace/src/dogstatsd.js +42 -10
  145. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +10 -2
  146. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +0 -1
  147. package/packages/dd-trace/src/exporter.js +3 -0
  148. package/packages/dd-trace/src/exporters/agent/index.js +10 -2
  149. package/packages/dd-trace/src/exporters/agent/writer.js +2 -9
  150. package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +82 -0
  151. package/packages/dd-trace/src/exporters/common/request.js +51 -1
  152. package/packages/dd-trace/src/exporters/span-stats/index.js +6 -2
  153. package/packages/dd-trace/src/format.js +29 -10
  154. package/packages/dd-trace/src/lambda/handler.js +72 -0
  155. package/packages/dd-trace/src/lambda/index.js +5 -0
  156. package/packages/dd-trace/src/lambda/runtime/errors.js +20 -0
  157. package/packages/dd-trace/src/lambda/runtime/patch.js +74 -0
  158. package/packages/dd-trace/src/lambda/runtime/ritm.js +138 -0
  159. package/packages/dd-trace/src/metrics.js +15 -2
  160. package/packages/dd-trace/src/opentracing/propagation/text_map.js +1 -5
  161. package/packages/dd-trace/src/opentracing/span.js +2 -1
  162. package/packages/dd-trace/src/opentracing/span_context.js +9 -0
  163. package/packages/dd-trace/src/plugin_manager.js +11 -17
  164. package/packages/dd-trace/src/plugins/cache.js +9 -0
  165. package/packages/dd-trace/src/plugins/ci_plugin.js +97 -0
  166. package/packages/dd-trace/src/plugins/client.js +9 -0
  167. package/packages/dd-trace/src/plugins/composite.js +26 -0
  168. package/packages/dd-trace/src/plugins/consumer.js +9 -0
  169. package/packages/dd-trace/src/plugins/database.js +55 -0
  170. package/packages/dd-trace/src/plugins/incoming.js +7 -0
  171. package/packages/dd-trace/src/plugins/index.js +3 -0
  172. package/packages/dd-trace/src/plugins/log_plugin.js +2 -2
  173. package/packages/dd-trace/src/plugins/outgoing.js +31 -0
  174. package/packages/dd-trace/src/plugins/plugin.js +3 -0
  175. package/packages/dd-trace/src/plugins/producer.js +9 -0
  176. package/packages/dd-trace/src/plugins/server.js +9 -0
  177. package/packages/dd-trace/src/plugins/storage.js +21 -0
  178. package/packages/dd-trace/src/plugins/tracing.js +94 -0
  179. package/packages/dd-trace/src/plugins/util/ci.js +40 -4
  180. package/packages/dd-trace/src/plugins/util/git.js +58 -18
  181. package/packages/dd-trace/src/plugins/util/test.js +71 -8
  182. package/packages/dd-trace/src/plugins/util/user-provided-git.js +14 -1
  183. package/packages/dd-trace/src/plugins/util/web.js +11 -114
  184. package/packages/dd-trace/src/priority_sampler.js +6 -2
  185. package/packages/dd-trace/src/profiling/config.js +11 -6
  186. package/packages/dd-trace/src/profiling/exporters/agent.js +4 -0
  187. package/packages/dd-trace/src/profiling/index.js +2 -2
  188. package/packages/dd-trace/src/profiling/profiler.js +43 -7
  189. package/packages/dd-trace/src/proxy.js +8 -16
  190. package/packages/dd-trace/src/ritm.js +25 -14
  191. package/packages/dd-trace/src/span_processor.js +17 -0
  192. package/packages/dd-trace/src/span_sampler.js +77 -0
  193. package/packages/dd-trace/src/span_stats.js +2 -2
  194. package/packages/dd-trace/src/telemetry/dependencies.js +21 -7
  195. package/packages/dd-trace/src/telemetry/index.js +7 -1
  196. package/packages/dd-trace/src/telemetry/send-data.js +3 -1
  197. package/packages/dd-trace/src/tracer.js +10 -5
  198. package/packages/dd-trace/src/util.js +43 -1
package/index.d.ts CHANGED
@@ -15,7 +15,7 @@ export declare interface Tracer extends opentracing.Tracer {
15
15
  * @param {SpanOptions} [options] Options for the newly created span.
16
16
  * @returns {Span} A new Span object.
17
17
  */
18
- startSpan(name: string, options?: SpanOptions): Span;
18
+ startSpan (name: string, options?: SpanOptions): Span;
19
19
 
20
20
  /**
21
21
  * Injects the given SpanContext instance for cross-process propagation
@@ -27,7 +27,7 @@ export declare interface Tracer extends opentracing.Tracer {
27
27
  * @param {string} format The format of the carrier.
28
28
  * @param {any} carrier The carrier object.
29
29
  */
30
- inject(spanContext: SpanContext | Span, format: string, carrier: any): void;
30
+ inject (spanContext: SpanContext | Span, format: string, carrier: any): void;
31
31
 
32
32
  /**
33
33
  * Returns a SpanContext instance extracted from `carrier` in the given
@@ -38,31 +38,31 @@ export declare interface Tracer extends opentracing.Tracer {
38
38
  * The extracted SpanContext, or null if no such SpanContext could
39
39
  * be found in `carrier`
40
40
  */
41
- extract(format: string, carrier: any): SpanContext | null;
41
+ extract (format: string, carrier: any): SpanContext | null;
42
42
 
43
43
  /**
44
44
  * Initializes the tracer. This should be called before importing other libraries.
45
45
  */
46
- init(options?: TracerOptions): this;
46
+ init (options?: TracerOptions): this;
47
47
 
48
48
  /**
49
49
  * Sets the URL for the trace agent. This should only be called _after_
50
50
  * init() is called, only in cases where the URL needs to be set after
51
51
  * initialization.
52
52
  */
53
- setUrl(url: string): this;
53
+ setUrl (url: string): this;
54
54
 
55
55
  /**
56
56
  * Enable and optionally configure a plugin.
57
57
  * @param plugin The name of a built-in plugin.
58
58
  * @param config Configuration options. Can also be `false` to disable the plugin.
59
59
  */
60
- use<P extends keyof Plugins>(plugin: P, config?: Plugins[P] | boolean): this;
60
+ use<P extends keyof Plugins> (plugin: P, config?: Plugins[P] | boolean): this;
61
61
 
62
62
  /**
63
63
  * Returns a reference to the current scope.
64
64
  */
65
- scope(): Scope;
65
+ scope (): Scope;
66
66
 
67
67
  /**
68
68
  * Instruments a function by automatically creating a span activated on its
@@ -81,8 +81,8 @@ export declare interface Tracer extends opentracing.Tracer {
81
81
  * If the `orphanable` option is set to false, the function will not be traced
82
82
  * unless there is already an active span or `childOf` option.
83
83
  */
84
- trace<T>(name: string, fn: (span?: Span, fn?: (error?: Error) => any) => T): T;
85
- trace<T>(name: string, options: TraceOptions & SpanOptions, fn: (span?: Span, done?: (error?: Error) => string) => T): T;
84
+ trace<T> (name: string, fn: (span?: Span, fn?: (error?: Error) => any) => T): T;
85
+ trace<T> (name: string, options: TraceOptions & SpanOptions, fn: (span?: Span, done?: (error?: Error) => string) => T): T;
86
86
 
87
87
  /**
88
88
  * Wrap a function to automatically create a span activated on its
@@ -98,23 +98,23 @@ export declare interface Tracer extends opentracing.Tracer {
98
98
  * * The function doesn't accept a callback and doesn't return a promise, in
99
99
  * which case the span will finish at the end of the function execution.
100
100
  */
101
- wrap<T = (...args: any[]) => any>(name: string, fn: T, requiresParent?: boolean): T;
102
- wrap<T = (...args: any[]) => any>(name: string, options: TraceOptions & SpanOptions, fn: T): T;
103
- wrap<T = (...args: any[]) => any>(name: string, options: (...args: any[]) => TraceOptions & SpanOptions, fn: T): T;
101
+ wrap<T = (...args: any[]) => any> (name: string, fn: T, requiresParent?: boolean): T;
102
+ wrap<T = (...args: any[]) => any> (name: string, options: TraceOptions & SpanOptions, fn: T): T;
103
+ wrap<T = (...args: any[]) => any> (name: string, options: (...args: any[]) => TraceOptions & SpanOptions, fn: T): T;
104
104
 
105
105
  /**
106
106
  * Create and return a string that can be included in the <head> of a
107
107
  * document to enable RUM tracing to include it. The resulting string
108
108
  * should not be cached.
109
109
  */
110
- getRumData(): string;
110
+ getRumData (): string;
111
111
 
112
112
  /**
113
113
  * Links an authenticated user to the current trace.
114
114
  * @param {User} user Properties of the authenticated user. Accepts custom fields.
115
115
  * @returns {Tracer} The Tracer instance for chaining.
116
116
  */
117
- setUser(user: User): Tracer;
117
+ setUser (user: User): Tracer;
118
118
  }
119
119
 
120
120
  export declare interface TraceOptions extends Analyzable {
@@ -144,7 +144,7 @@ export declare interface TraceOptions extends Analyzable {
144
144
  * have children.
145
145
  */
146
146
  export declare interface Span extends opentracing.Span {
147
- context(): SpanContext;
147
+ context (): SpanContext;
148
148
  }
149
149
 
150
150
  /**
@@ -161,12 +161,17 @@ export declare interface SpanContext extends opentracing.SpanContext {
161
161
  /**
162
162
  * Returns the string representation of the internal trace ID.
163
163
  */
164
- toTraceId(): string;
164
+ toTraceId (): string;
165
165
 
166
166
  /**
167
167
  * Returns the string representation of the internal span ID.
168
168
  */
169
- toSpanId(): string;
169
+ toSpanId (): string;
170
+
171
+ /**
172
+ * Returns the string representation used for DBM integration.
173
+ */
174
+ toTraceparent (): string;
170
175
  }
171
176
 
172
177
  /**
@@ -176,7 +181,7 @@ export declare interface SamplingRule {
176
181
  /**
177
182
  * Sampling rate for this rule.
178
183
  */
179
- sampleRate: Number
184
+ sampleRate: number
180
185
 
181
186
  /**
182
187
  * Service on which to apply this rule. The rule will apply to all services if not provided.
@@ -189,6 +194,31 @@ export declare interface SamplingRule {
189
194
  name?: string | RegExp
190
195
  }
191
196
 
197
+ /**
198
+ * Span sampling rules to ingest single spans where the enclosing trace is dropped
199
+ */
200
+ export declare interface SpanSamplingRule {
201
+ /**
202
+ * Sampling rate for this rule. Will default to 1.0 (always) if not provided.
203
+ */
204
+ sampleRate?: number
205
+
206
+ /**
207
+ * Maximum number of spans matching a span sampling rule to be allowed per second.
208
+ */
209
+ maxPerSecond?: number
210
+
211
+ /**
212
+ * Service name or pattern on which to apply this rule. The rule will apply to all services if not provided.
213
+ */
214
+ service?: string
215
+
216
+ /**
217
+ * Operation name or pattern on which to apply this rule. The rule will apply to all operation names if not provided.
218
+ */
219
+ name?: string
220
+ }
221
+
192
222
  /**
193
223
  * List of options available to the tracer.
194
224
  */
@@ -212,6 +242,11 @@ export declare interface TracerOptions {
212
242
  */
213
243
  service?: string;
214
244
 
245
+ /**
246
+ * Provide service name mappings for each plugin.
247
+ */
248
+ serviceMapping?: { [key: string]: string };
249
+
215
250
  /**
216
251
  * The url of the trace agent that the tracer will submit to.
217
252
  * Takes priority over hostname and port, if set.
@@ -272,7 +307,7 @@ export declare interface TracerOptions {
272
307
  * and controls the ingestion rate limit between the agent and the backend.
273
308
  * Defaults to deferring the decision to the agent.
274
309
  */
275
- rateLimit?: Number,
310
+ rateLimit?: number,
276
311
 
277
312
  /**
278
313
  * Sampling rules to apply to priority samplin. Each rule is a JSON,
@@ -283,6 +318,12 @@ export declare interface TracerOptions {
283
318
  */
284
319
  samplingRules?: SamplingRule[]
285
320
 
321
+ /**
322
+ * Span sampling rules that take effect when the enclosing trace is dropped, to ingest single spans
323
+ * @default []
324
+ */
325
+ spanSamplingRules?: SpanSamplingRule[]
326
+
286
327
  /**
287
328
  * Interval in milliseconds at which the tracer will submit traces to the agent.
288
329
  * @default 2000
@@ -293,7 +334,7 @@ export declare interface TracerOptions {
293
334
  * Number of spans before partially exporting a trace. This prevents keeping all the spans in memory for very large traces.
294
335
  * @default 1000
295
336
  */
296
- flushMinSpans?: number;
337
+ flushMinSpans?: number;
297
338
 
298
339
  /**
299
340
  * Whether to enable runtime metrics.
@@ -346,10 +387,10 @@ export declare interface TracerOptions {
346
387
  runtimeId?: boolean
347
388
 
348
389
  /**
349
- * Whether to write traces to log output, rather than send to an agent
390
+ * Whether to write traces to log output or agentless, rather than send to an agent
350
391
  * @default false
351
392
  */
352
- exporter?: 'log' | 'agent'
393
+ exporter?: 'log' | 'agent' | 'datadog'
353
394
 
354
395
  /**
355
396
  * Whether to enable the experimental `getRumData` method.
@@ -360,7 +401,7 @@ export declare interface TracerOptions {
360
401
  /**
361
402
  * Configuration of the IAST. Can be a boolean as an alias to `iast.enabled`.
362
403
  */
363
- iast?: boolean | {
404
+ iast?: boolean | {
364
405
  /**
365
406
  * Whether to enable IAST.
366
407
  * @default false
@@ -432,6 +473,12 @@ export declare interface TracerOptions {
432
473
  */
433
474
  orphanable?: boolean
434
475
 
476
+ /**
477
+ * Enables DBM to APM link using tag injection.
478
+ * @default 'disabled'
479
+ */
480
+ dbmPropagationMode?: 'disabled' | 'service' | 'full'
481
+
435
482
  /**
436
483
  * Configuration of the AppSec protection. Can be a boolean as an alias to `appsec.enabled`.
437
484
  */
@@ -467,14 +514,35 @@ export declare interface TracerOptions {
467
514
  /**
468
515
  * Specifies a regex that will redact sensitive data by its value in attack reports.
469
516
  */
470
- obfuscatorValueRegex?: string
517
+ obfuscatorValueRegex?: string,
518
+
519
+ /**
520
+ * Specifies a path to a custom blocking template html file.
521
+ */
522
+ blockedTemplateHtml?: string,
523
+
524
+ /**
525
+ * Specifies a path to a custom blocking template json file.
526
+ */
527
+ blockedTemplateJson?: string,
471
528
  };
529
+
530
+ /**
531
+ * Configuration of ASM Remote Configuration
532
+ */
533
+ remoteConfig?: {
534
+ /**
535
+ * Specifies the remote configuration polling interval in seconds
536
+ * @default 5
537
+ */
538
+ pollInterval?: number,
539
+ }
472
540
  }
473
541
 
474
542
  /**
475
543
  * User object that can be passed to `tracer.setUser()`.
476
544
  */
477
- export declare interface User {
545
+ export declare interface User {
478
546
  /**
479
547
  * Unique identifier of the user.
480
548
  * Mandatory.
@@ -537,7 +605,7 @@ export declare interface Scope {
537
605
  *
538
606
  * @returns {Span} The active span.
539
607
  */
540
- active(): Span | null;
608
+ active (): Span | null;
541
609
 
542
610
  /**
543
611
  * Activate a span in the scope of a function.
@@ -546,7 +614,7 @@ export declare interface Scope {
546
614
  * @param {Function} fn Function that will have the span activated on its scope.
547
615
  * @returns The return value of the provided function.
548
616
  */
549
- activate<T>(span: Span, fn: ((...args: any[]) => T)): T;
617
+ activate<T> (span: Span, fn: ((...args: any[]) => T)): T;
550
618
 
551
619
  /**
552
620
  * Binds a target to the provided span, or the active span if omitted.
@@ -555,9 +623,9 @@ export declare interface Scope {
555
623
  * @param {Span} [span=scope.active()] The span to activate.
556
624
  * @returns The bound target.
557
625
  */
558
- bind<T extends (...args: any[]) => void>(fn: T, span?: Span | null): T;
559
- bind<V, T extends (...args: any[]) => V>(fn: T, span?: Span | null): T;
560
- bind<T>(fn: Promise<T>, span?: Span | null): Promise<T>;
626
+ bind<T extends (...args: any[]) => void> (fn: T, span?: Span | null): T;
627
+ bind<V, T extends (...args: any[]) => V> (fn: T, span?: Span | null): T;
628
+ bind<T> (fn: Promise<T>, span?: Span | null): Promise<T>;
561
629
  }
562
630
 
563
631
  /** @hidden */
@@ -587,6 +655,7 @@ interface Plugins {
587
655
  "kafkajs": plugins.kafkajs
588
656
  "knex": plugins.knex;
589
657
  "koa": plugins.koa;
658
+ "mariadb": plugins.mariadb;
590
659
  "memcached": plugins.memcached;
591
660
  "microgateway-core": plugins.microgateway_core;
592
661
  "mocha": plugins.mocha;
@@ -597,6 +666,7 @@ interface Plugins {
597
666
  "mysql2": plugins.mysql2;
598
667
  "net": plugins.net;
599
668
  "next": plugins.next;
669
+ "opensearch": plugins.opensearch;
600
670
  "oracledb": plugins.oracledb;
601
671
  "paperplane": plugins.paperplane;
602
672
  "pg": plugins.pg;
@@ -729,7 +799,7 @@ declare namespace plugins {
729
799
  * status code as its only parameter and return `true` for success or `false`
730
800
  * for errors.
731
801
  *
732
- * @default code => code < 400
802
+ * @default code => code < 400 || code >= 500
733
803
  */
734
804
  validateStatus?: (code: number) => boolean;
735
805
 
@@ -763,7 +833,7 @@ declare namespace plugins {
763
833
  * status code as its only parameter and return `true` for success or `false`
764
834
  * for errors.
765
835
  *
766
- * @default code => code < 400
836
+ * @default code => code < 400 || code >= 500
767
837
  */
768
838
  validateStatus?: (code: number) => boolean;
769
839
  }
@@ -1164,6 +1234,18 @@ declare namespace plugins {
1164
1234
  */
1165
1235
  interface kafkajs extends Instrumentation {}
1166
1236
 
1237
+ /**
1238
+ * This plugin automatically instruments the
1239
+ * [ldapjs](https://github.com/ldapjs/node-ldapjs/) module.
1240
+ */
1241
+ interface ldapjs extends Instrumentation {}
1242
+
1243
+ /**
1244
+ * This plugin automatically instruments the
1245
+ * [mariadb](https://github.com/mariadb-corporation/mariadb-connector-nodejs) module.
1246
+ */
1247
+ interface mariadb extends mysql {}
1248
+
1167
1249
  /**
1168
1250
  * This plugin automatically instruments the
1169
1251
  * [memcached](https://github.com/3rd-Eden/memcached) module.
@@ -1186,7 +1268,7 @@ declare namespace plugins {
1186
1268
  * This plugin automatically instruments the
1187
1269
  * [moleculer](https://moleculer.services/) module.
1188
1270
  */
1189
- interface moleculer extends Moleculer {
1271
+ interface moleculer extends Moleculer {
1190
1272
  /**
1191
1273
  * Configuration for Moleculer clients. Set to false to disable client
1192
1274
  * instrumentation.
@@ -1204,7 +1286,12 @@ declare namespace plugins {
1204
1286
  * This plugin automatically instruments the
1205
1287
  * [mongodb-core](https://github.com/mongodb-js/mongodb-core) module.
1206
1288
  */
1207
- interface mongodb_core extends Instrumentation {}
1289
+ interface mongodb_core extends Instrumentation {
1290
+ /**
1291
+ * Whether to include the query contents in the resource name.
1292
+ */
1293
+ queryInResourceName?: boolean;
1294
+ }
1208
1295
 
1209
1296
  /**
1210
1297
  * This plugin automatically instruments the
@@ -1240,7 +1327,7 @@ declare namespace plugins {
1240
1327
  /**
1241
1328
  * Hooks to run before spans are finished.
1242
1329
  */
1243
- hooks?: {
1330
+ hooks?: {
1244
1331
  /**
1245
1332
  * Hook to execute just before the request span finishes.
1246
1333
  */
@@ -1248,6 +1335,12 @@ declare namespace plugins {
1248
1335
  };
1249
1336
  }
1250
1337
 
1338
+ /**
1339
+ * This plugin automatically instruments the
1340
+ * [opensearch](https://github.com/opensearch-project/opensearch-js) module.
1341
+ */
1342
+ interface opensearch extends elasticsearch {}
1343
+
1251
1344
  /**
1252
1345
  * This plugin automatically instruments the
1253
1346
  * [oracledb](https://github.com/oracle/node-oracledb) module.
@@ -1263,7 +1356,7 @@ declare namespace plugins {
1263
1356
  * This plugin automatically instruments the
1264
1357
  * [paperplane](https://github.com/articulate/paperplane) module.
1265
1358
  */
1266
- interface paperplane extends HttpServer {}
1359
+ interface paperplane extends HttpServer {}
1267
1360
 
1268
1361
  /**
1269
1362
  * This plugin automatically instruments the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "3.3.1",
3
+ "version": "3.12.1",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -16,14 +16,16 @@
16
16
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
17
17
  "tdd": "node scripts/tdd.js",
18
18
  "test": "SERVICES=* yarn services && mocha --colors --exit --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
19
- "test:trace:core": "mocha --colors --exit --expose-gc --file packages/dd-trace/test/setup/core.js --exclude \"packages/dd-trace/test/profiling/**/*.spec.js\" \"packages/dd-trace/test/**/*.spec.js\"",
20
- "test:trace:core:ci": "nyc --no-clean --include \"packages/dd-trace/src/**/*.js\" --exclude \"packages/dd-trace/src/profiling/**/*.js\" -- npm run test:trace:core",
19
+ "test:trace:core": "mocha --colors --exit --expose-gc --file packages/dd-trace/test/setup/core.js --exclude \"packages/dd-trace/test/lambda/**/*.spec.js\" --exclude \"packages/dd-trace/test/profiling/**/*.spec.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" \"packages/dd-trace/test/**/*.spec.js\"",
20
+ "test:trace:core:ci": "nyc --no-clean --include \"packages/dd-trace/src/**/*.js\" --exclude \"packages/dd-trace/src/lambda/**/*.spec.js\" --exclude \"packages/dd-trace/src/profiling/**/*.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" -- npm run test:trace:core -- --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter.json",
21
21
  "test:instrumentations": "mocha --colors --file 'packages/dd-trace/test/setup/core.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
22
22
  "test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
23
23
  "test:core": "mocha --colors --file packages/datadog-core/test/setup.js 'packages/datadog-core/test/**/*.spec.js'",
24
24
  "test:core:ci": "nyc --no-clean --include 'packages/datadog-core/src/**/*.js' -- npm run test:core",
25
- "test:plugins": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
26
- "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
25
+ "test:lambda": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
26
+ "test:lambda:ci": "nyc --no-clean --include \"packages/dd-trace/src/lambda/**/*.js\" -- npm run test:lambda",
27
+ "test:plugins": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\" \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
28
+ "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" --include \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\" -- npm run test:plugins",
27
29
  "test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
28
30
  "test:profiler": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/dd-trace/test/profiling/**/*.spec.js\"",
29
31
  "test:profiler:ci": "nyc --no-clean --include \"packages/dd-trace/src/profiling/**/*.js\" -- npm run test:profiler",
@@ -58,9 +60,11 @@
58
60
  "node": ">=14"
59
61
  },
60
62
  "dependencies": {
61
- "@datadog/native-appsec": "^1.2.1",
62
- "@datadog/native-metrics": "^1.4.3",
63
- "@datadog/pprof": "^1.0.2",
63
+ "@datadog/native-appsec": "2.0.0",
64
+ "@datadog/native-iast-rewriter": "1.1.2",
65
+ "@datadog/native-iast-taint-tracking": "1.1.0",
66
+ "@datadog/native-metrics": "^1.5.0",
67
+ "@datadog/pprof": "^1.1.1",
64
68
  "@datadog/sketches-js": "^2.1.0",
65
69
  "crypto-randomuuid": "^1.0.0",
66
70
  "diagnostics_channel": "^1.1.0",
@@ -77,8 +81,10 @@
77
81
  "lru-cache": "^7.14.0",
78
82
  "methods": "^1.1.2",
79
83
  "module-details-from-path": "^1.0.3",
84
+ "node-abort-controller": "^3.0.1",
80
85
  "opentracing": ">=0.12.1",
81
86
  "path-to-regexp": "^0.1.2",
87
+ "protobufjs": "^7.1.2",
82
88
  "retry": "^0.10.1",
83
89
  "semver": "^5.5.0"
84
90
  },
@@ -93,9 +99,10 @@
93
99
  "checksum": "^0.1.1",
94
100
  "cli-table3": "^0.5.1",
95
101
  "dotenv": "8.2.0",
96
- "eslint": "^7.32.0",
102
+ "eslint": "^8.23.0",
97
103
  "eslint-config-standard": "^11.0.0-beta.0",
98
104
  "eslint-plugin-import": "^2.8.0",
105
+ "eslint-plugin-mocha": "^10.1.0",
99
106
  "eslint-plugin-node": "^5.2.1",
100
107
  "eslint-plugin-promise": "^3.6.0",
101
108
  "eslint-plugin-standard": "^3.0.1",
@@ -107,6 +114,8 @@
107
114
  "jszip": "^3.5.0",
108
115
  "mkdirp": "^0.5.1",
109
116
  "mocha": "8",
117
+ "mocha-junit-reporter": "^2.1.0",
118
+ "mocha-multi-reporters": "^1.5.1",
110
119
  "msgpack-lite": "^0.1.26",
111
120
  "multer": "^1.4.5-lts.1",
112
121
  "nock": "^11.3.3",
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ const { channel, addHook, AsyncResource } = require('./helpers/instrument')
4
+
5
+ const bodyParserReadCh = channel('datadog:body-parser:read:finish')
6
+
7
+ function publishRequestBodyAndNext (request, next) {
8
+ return function () {
9
+ if (bodyParserReadCh.hasSubscribers && request) {
10
+ bodyParserReadCh.publish({ request })
11
+ }
12
+ next.apply(this, arguments)
13
+ }
14
+ }
15
+
16
+ addHook({
17
+ name: 'body-parser',
18
+ file: 'lib/read.js',
19
+ versions: ['>=1']
20
+ }, read => {
21
+ return function (req, res, next) {
22
+ const nextResource = new AsyncResource('bound-anonymous-fn')
23
+ arguments[2] = nextResource.bind(publishRequestBodyAndNext(req, next))
24
+ read.apply(this, arguments)
25
+ }
26
+ })
@@ -7,10 +7,10 @@ const {
7
7
  } = require('./helpers/instrument')
8
8
  const shimmer = require('../../datadog-shimmer')
9
9
 
10
- const startCh = channel('apm:cassandra:query:start')
11
- const finishCh = channel('apm:cassandra:query:finish')
12
- const errorCh = channel('apm:cassandra:query:error')
13
- const addConnectionCh = channel(`apm:cassandra:query:addConnection`)
10
+ const startCh = channel('apm:cassandra-driver:query:start')
11
+ const finishCh = channel('apm:cassandra-driver:query:finish')
12
+ const errorCh = channel('apm:cassandra-driver:query:error')
13
+ const connectCh = channel(`apm:cassandra-driver:query:connect`)
14
14
 
15
15
  addHook({ name: 'cassandra-driver', versions: ['>=3.0.0'] }, cassandra => {
16
16
  shimmer.wrap(cassandra.Client.prototype, 'batch', batch => function (queries, options, callback) {
@@ -115,7 +115,7 @@ addHook({ name: 'cassandra-driver', versions: ['>=3.3'], file: 'lib/request-exec
115
115
  if (!startCh.hasSubscribers) {
116
116
  return _sendOnConnection.apply(this, arguments)
117
117
  }
118
- addConnectionCh.publish({ address: this._connection.address, port: this._connection.port })
118
+ connectCh.publish({ hostname: this._connection.address, port: this._connection.port })
119
119
  return _sendOnConnection.apply(this, arguments)
120
120
  })
121
121
  return RequestExecution
@@ -136,7 +136,7 @@ addHook({ name: 'cassandra-driver', versions: ['3.3 - 4.3'], file: 'lib/request-
136
136
  getHostCallback = asyncResource.bind(getHostCallback)
137
137
 
138
138
  arguments[0] = AsyncResource.bind(function () {
139
- addConnectionCh.publish({ address: execution._connection.address, port: execution._connection.port })
139
+ connectCh.publish({ hostname: execution._connection.address, port: execution._connection.port })
140
140
  return getHostCallback.apply(this, arguments)
141
141
  })
142
142
 
@@ -160,7 +160,7 @@ addHook({ name: 'cassandra-driver', versions: ['3 - 3.2'], file: 'lib/request-ha
160
160
  callback = asyncResource.bind(callback)
161
161
 
162
162
  arguments[2] = AsyncResource.bind(function () {
163
- addConnectionCh.publish({ address: handler.connection.address, port: handler.connection.port })
163
+ connectCh.publish({ hostname: handler.connection.address, port: handler.connection.port })
164
164
  return callback.apply(this, arguments)
165
165
  })
166
166
 
@@ -0,0 +1,30 @@
1
+ 'use strict'
2
+
3
+ const {
4
+ channel,
5
+ addHook
6
+ } = require('./helpers/instrument')
7
+ const shimmer = require('../../datadog-shimmer')
8
+
9
+ const childProcessChannel = channel('datadog:child_process:execution:start')
10
+ const execMethods = ['exec', 'execFile', 'fork', 'spawn', 'execFileSync', 'execSync', 'spawnSync']
11
+ const names = ['child_process', 'node:child_process']
12
+ names.forEach(name => {
13
+ addHook({ name }, childProcess => {
14
+ shimmer.massWrap(childProcess, execMethods, wrapChildProcessMethod())
15
+ return childProcess
16
+ })
17
+ })
18
+
19
+ function wrapChildProcessMethod () {
20
+ function wrapMethod (childProcessMethod) {
21
+ return function () {
22
+ if (childProcessChannel.hasSubscribers && arguments.length > 0) {
23
+ const command = arguments[0]
24
+ childProcessChannel.publish({ command })
25
+ }
26
+ return childProcessMethod.apply(this, arguments)
27
+ }
28
+ }
29
+ return wrapMethod
30
+ }
@@ -1,12 +1,13 @@
1
1
  'use strict'
2
2
 
3
3
  const shimmer = require('../../datadog-shimmer')
4
- const { addHook, channel, AsyncResource } = require('./helpers/instrument')
4
+ const { addHook, channel } = require('./helpers/instrument')
5
5
 
6
6
  const enterChannel = channel('apm:connect:middleware:enter')
7
7
  const exitChannel = channel('apm:connect:middleware:exit')
8
8
  const errorChannel = channel('apm:connect:middleware:error')
9
9
  const nextChannel = channel('apm:connect:middleware:next')
10
+ const finishChannel = channel('apm:connect:middleware:finish')
10
11
  const handleChannel = channel('apm:connect:request:handle')
11
12
 
12
13
  function wrapConnect (connect) {
@@ -61,7 +62,6 @@ function wrapLayerHandle (layer) {
61
62
  return shimmer.wrap(original, function () {
62
63
  if (!enterChannel.hasSubscribers) return original.apply(this, arguments)
63
64
 
64
- const middlewareResource = new AsyncResource('bound-anonymous-fn')
65
65
  const lastIndex = arguments.length - 1
66
66
  const name = original._name || original.name
67
67
  const req = arguments[arguments.length > 3 ? 1 : 0]
@@ -71,21 +71,21 @@ function wrapLayerHandle (layer) {
71
71
  arguments[lastIndex] = wrapNext(req, next)
72
72
  }
73
73
 
74
- return middlewareResource.runInAsyncScope(() => {
75
- const route = layer.route
74
+ const route = layer.route
76
75
 
77
- enterChannel.publish({ name, req, route })
76
+ enterChannel.publish({ name, req, route })
78
77
 
79
- try {
80
- return original.apply(this, arguments)
81
- } catch (error) {
82
- errorChannel.publish({ req, error })
83
- nextChannel.publish({ req })
84
- exitChannel.publish({ req })
78
+ try {
79
+ return original.apply(this, arguments)
80
+ } catch (error) {
81
+ errorChannel.publish({ req, error })
82
+ nextChannel.publish({ req })
83
+ finishChannel.publish({ req })
85
84
 
86
- throw error
87
- }
88
- })
85
+ throw error
86
+ } finally {
87
+ exitChannel.publish({ req })
88
+ }
89
89
  })
90
90
  }
91
91
 
@@ -96,7 +96,7 @@ function wrapNext (req, next) {
96
96
  }
97
97
 
98
98
  nextChannel.publish({ req })
99
- exitChannel.publish({ req })
99
+ finishChannel.publish({ req })
100
100
 
101
101
  next.apply(this, arguments)
102
102
  }
@@ -50,7 +50,7 @@ function wrapRun (pl, isLatestVersion) {
50
50
 
51
51
  const asyncResource = new AsyncResource('bound-anonymous-fn')
52
52
  return asyncResource.runInAsyncScope(() => {
53
- runStartCh.publish({ pickleName: this.pickle.name, pickleUri: this.pickle.uri })
53
+ runStartCh.publish({ testName: this.pickle.name, fullTestSuite: this.pickle.uri })
54
54
  try {
55
55
  const promise = run.apply(this, arguments)
56
56
  promise.finally(() => {
@@ -142,5 +142,3 @@ addHook({
142
142
 
143
143
  return Runtime
144
144
  })
145
-
146
- module.exports = { pickleHook, testCaseHook }