dd-trace 2.35.1 → 2.37.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 (67) hide show
  1. package/LICENSE-3rdparty.csv +2 -0
  2. package/MIGRATING.md +158 -0
  3. package/README.md +18 -11
  4. package/index.d.ts +281 -0
  5. package/package.json +6 -4
  6. package/packages/datadog-instrumentations/src/cookie.js +21 -0
  7. package/packages/datadog-instrumentations/src/fetch.js +48 -0
  8. package/packages/datadog-instrumentations/src/grpc/server.js +1 -1
  9. package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -0
  10. package/packages/datadog-instrumentations/src/helpers/register.js +10 -0
  11. package/packages/datadog-instrumentations/src/jest.js +2 -3
  12. package/packages/datadog-instrumentations/src/next.js +2 -2
  13. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +18 -0
  14. package/packages/datadog-plugin-cypress/src/plugin.js +109 -47
  15. package/packages/datadog-plugin-cypress/src/support.js +3 -2
  16. package/packages/datadog-plugin-fetch/src/index.js +36 -0
  17. package/packages/datadog-plugin-http/src/client.js +24 -8
  18. package/packages/datadog-plugin-mysql/src/index.js +2 -11
  19. package/packages/datadog-plugin-tedious/src/index.js +2 -2
  20. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +3 -0
  21. package/packages/dd-trace/src/appsec/iast/analyzers/cookie-analyzer.js +52 -0
  22. package/packages/dd-trace/src/appsec/iast/analyzers/insecure-cookie-analyzer.js +3 -22
  23. package/packages/dd-trace/src/appsec/iast/analyzers/no-httponly-cookie-analyzer.js +12 -0
  24. package/packages/dd-trace/src/appsec/iast/analyzers/no-samesite-cookie-analyzer.js +12 -0
  25. package/packages/dd-trace/src/appsec/iast/analyzers/set-cookies-header-interceptor.js +7 -3
  26. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +3 -3
  27. package/packages/dd-trace/src/appsec/iast/analyzers/unvalidated-redirect-analyzer.js +48 -0
  28. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +3 -3
  29. package/packages/dd-trace/src/appsec/iast/analyzers/weak-hash-analyzer.js +24 -0
  30. package/packages/dd-trace/src/appsec/iast/index.js +9 -2
  31. package/packages/dd-trace/src/appsec/iast/path-line.js +13 -0
  32. package/packages/dd-trace/src/appsec/iast/tags.js +6 -0
  33. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +2 -1
  34. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +13 -4
  35. package/packages/dd-trace/src/appsec/iast/taint-tracking/origin-types.js +5 -1
  36. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +24 -4
  37. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +3 -1
  38. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +3 -0
  39. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +7 -1
  40. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -3
  41. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +5 -2
  42. package/packages/dd-trace/src/config.js +13 -0
  43. package/packages/dd-trace/src/external-logger/src/index.js +126 -0
  44. package/packages/dd-trace/src/external-logger/test/index.spec.js +147 -0
  45. package/packages/dd-trace/src/lambda/handler.js +3 -15
  46. package/packages/dd-trace/src/noop/proxy.js +4 -0
  47. package/packages/dd-trace/src/opentelemetry/context_manager.js +74 -0
  48. package/packages/dd-trace/src/opentelemetry/sampler.js +18 -0
  49. package/packages/dd-trace/src/opentelemetry/span.js +151 -0
  50. package/packages/dd-trace/src/opentelemetry/span_context.js +44 -0
  51. package/packages/dd-trace/src/opentelemetry/span_processor.js +50 -0
  52. package/packages/dd-trace/src/opentelemetry/tracer.js +124 -0
  53. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +72 -0
  54. package/packages/dd-trace/src/opentracing/span.js +14 -4
  55. package/packages/dd-trace/src/plugin_manager.js +10 -7
  56. package/packages/dd-trace/src/plugins/database.js +7 -3
  57. package/packages/dd-trace/src/plugins/plugin.js +3 -1
  58. package/packages/dd-trace/src/plugins/util/exec.js +2 -2
  59. package/packages/dd-trace/src/plugins/util/git.js +51 -24
  60. package/packages/dd-trace/src/profiling/config.js +2 -0
  61. package/packages/dd-trace/src/profiling/profiler.js +13 -4
  62. package/packages/dd-trace/src/proxy.js +4 -0
  63. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +24 -1
  64. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +18 -1
  65. package/packages/dd-trace/src/tracer.js +3 -3
  66. package/packages/dd-trace/src/util.js +1 -1
  67. package/version.js +8 -4
@@ -6,6 +6,8 @@ require,@datadog/native-iast-taint-tracking,Apache license 2.0,Copyright 2018 Da
6
6
  require,@datadog/pprof,Apache license 2.0,Copyright 2019 Google Inc.
7
7
  require,@datadog/sketches-js,Apache license 2.0,Copyright 2020 Datadog Inc.
8
8
  require,@types/node,MIT,Copyright Authors
9
+ require,@opentelemetry/api,Apache license 2.0,Copyright OpenTelemetry Authors
10
+ require,@opentelemetry/core,Apache license 2.0,Copyright OpenTelemetry Authors
9
11
  require,crypto-randomuuid,MIT,Copyright 2021 Node.js Foundation and contributors
10
12
  require,diagnostics_channel,MIT,Copyright 2021 Simon D.
11
13
  require,ignore,MIT,Copyright 2013 Kael Zhang and contributors
package/MIGRATING.md CHANGED
@@ -4,6 +4,164 @@ This guide describes the steps to upgrade dd-trace from a major version to the
4
4
  next. If you are having any issues related to migrating, please feel free to
5
5
  open an issue or contact our [support](https://www.datadoghq.com/support/) team.
6
6
 
7
+ ## 3.0 to 4.0
8
+
9
+ ### Node 14 is no longer supported
10
+
11
+ Node.js 14 has reached EOL in April 2023 and is no longer supported. Generally
12
+ speaking, we highly recommend always keeping Node.js up to date regardless of
13
+ our support policy.
14
+
15
+ ### The `orphanable` option was removed
16
+
17
+ This option was only useful internally for a single integration that has since
18
+ been removed. It was never useful for manual instrumentation since all that is
19
+ needed to orphan a span on creation is to use
20
+ `tracer.trace('web.request', { childOf: null })`.
21
+
22
+ ### Support for `jest-jasmine2` has been removed
23
+
24
+ The default test runner for Jest was changed to `jest-circus` around 2 years ago and
25
+ is no longer supported by our Jest integration for CI Visibility. We recommend
26
+ switching to `jest-circus` to anyone still using `jest-jasmine2`.
27
+
28
+ ### Support for older Next.js versions was removed
29
+
30
+ We now support only Next.js 10.2 and up.
31
+
32
+ ### W3C headers are now prioritized over Datadog headers
33
+
34
+ As we move towards open standards, we have decided to prioritize W3C Trace
35
+ Context headers over our own vendor-specific headers for context propagation
36
+ across services. For most applications this shouldn't change anything and
37
+ distributed tracing should continue to work seamlessly.
38
+
39
+ In some rare cases it's possible that some of the services involved in a trace
40
+ are not instrumented by Datadog at all which can cause spans within the trace to
41
+ become disconnected. While the data would still be available in the UI, the
42
+ relationship between spans would no longer be visible. This can be addressed by
43
+ restoring the previous behaviour using
44
+ `DD_TRACE_PROPAGATION_STYLE='datadog,tracecontext'`.
45
+
46
+ ## 2.0 to 3.0
47
+
48
+ ### Node 12 is no longer supported
49
+
50
+ Node.js 12 has been EOL since April 2022 and is no longer supported. Generally
51
+ speaking, we highly recommend always keeping Node.js up to date regardless of our
52
+ support policy.
53
+
54
+ ### HTTP query string reported by default
55
+
56
+ HTTP query strings are now reported by default as part of the `http.url` tag.
57
+ This change is considered breaking only because there might be sensitive data
58
+ in the query string. A default regular expression based obfuscator is provided
59
+ for common use cases like API keys, but if your use case is not covered, the
60
+ [DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP](https://datadoghq.dev/dd-trace-js/#tracer-settings)
61
+ environment variable can be used to control what is obfuscated, and a value of
62
+ `.*` would redact the query string entirely.
63
+
64
+ ### HTTP operation name change
65
+
66
+ The HTTP integration now uses `web.request` for incoming requests and continues
67
+ to use `http.request` for outgoing requests. When using a supported web
68
+ framework like Express, this change will have no effect because the root span
69
+ would already have an operation name override like `express.request`.
70
+ Any [monitor](https://docs.datadoghq.com/monitors/create/types/apm/?tab=apmmetrics)
71
+ on `http.request` for incoming requests should be updated to `web.request`.
72
+
73
+ With this change, both operation names also appear under the main service name
74
+ and are no longer split between the server service name and a separate client
75
+ service name suffixed with `-http-client`.
76
+
77
+ ### gRPC operation name change
78
+
79
+ The gRPC integration now uses `grpc.server` for incoming requests and
80
+ `grpc.client` for outgoing requests. Any
81
+ [monitor](https://docs.datadoghq.com/monitors/create/types/apm/?tab=apmmetrics)
82
+ on `grpc.request` should be updated to one of these.
83
+
84
+ With this change, both operation names also appear under the main service name
85
+ and are no longer split between the server service name and a separate client
86
+ service name suffixed with `-http-client`.
87
+
88
+ ### Removal of `fs` integration
89
+
90
+ The `fs` integration was removed as it was originally added without an actual
91
+ use case, and it's been problematic ever since. It's noisy, the output is
92
+ confusing when using streams, errors that are handled higher in the stack end up
93
+ being captured, etc.
94
+
95
+ If you had any use for file system instrumentation, please let us know so we can
96
+ provide an alternative.
97
+
98
+ ### Scope binding for promises and event emitters
99
+
100
+ It's no longer possible to bind promises using `tracer.scope().bind(promise)` or
101
+ event emitters using `tracer.scope().bind(emitter)`. These were historically
102
+ added mostly for internal use, and changes to context propagation over the years
103
+ made them unnecessary, both internally and externaly. If one of these is used
104
+ anywhere, the call will simply be ignored and no binding will occur.
105
+
106
+ To bind the `then` handler of a promise, bind the function directly directly:
107
+
108
+ ```js
109
+ promise.then(tracer.scope().bind(handler))
110
+ ```
111
+
112
+ To bind all listeners for an event, wrap the call to `emit` directly instead:
113
+
114
+ ```js
115
+ tracer.scope().activate(span, () => {
116
+ emitter.emit('event')
117
+ })
118
+ ```
119
+
120
+ To bind individual listeners, bind the listener function directly instead:
121
+
122
+ ```js
123
+ emitter.on('event', tracer.scope().bind(listener, span))
124
+ ```
125
+
126
+ ### Removed APIs
127
+
128
+ The following APIs have been deprecated for a long time and have now been
129
+ completely removed:
130
+
131
+ - `tracer.currentSpan()`
132
+ - `tracer.bindEmitter()`
133
+
134
+ Since these have not been recommended nor publicly documented for years at this
135
+ point, there should be no impact as no application is expected to be using them.
136
+
137
+ ### CI Visibility new entrypoints
138
+
139
+ #### Cypress
140
+
141
+ `dd-trace/cypress/plugin` and `dd-trace/cypress/support` are removed, so you won't
142
+ be able to use them for your `cypress` instrumentation. Use `dd-trace/ci/cypress/plugin`
143
+ and `dd-trace/ci/cypress/support` instead for your plugin and support configuration
144
+ respectively.
145
+
146
+ #### Jest
147
+
148
+ The use of `'dd-trace/ci/jest/env'` in [`testEnvironment`](https://jestjs.io/docs/configuration#testenvironment-string)
149
+ is no longer supported.
150
+ To instrument `jest` tests now, add `'-r dd-trace/ci/init'` to the `NODE_OPTIONS` environment
151
+ variable passed to the process running the tests, for example, `NODE_OPTIONS='-r dd-trace/ci/init' yarn test`.
152
+
153
+ #### Mocha
154
+
155
+ The use of `--require dd-trace/ci/init` as a `mocha` flag is no longer supported.
156
+ To instrument `mocha` tests now, add `'-r dd-trace/ci/init'` to the `NODE_OPTIONS` environment
157
+ variable passed to the process running the tests, for example, `NODE_OPTIONS='-r dd-trace/ci/init' yarn test`.
158
+
159
+ #### Cucumber
160
+
161
+ The use of `--require-module dd-trace/ci/init` as a `cucumber-js` flag is no longer supported.
162
+ To instrument `cucumber-js` tests now, add `'-r dd-trace/ci/init'` to the `NODE_OPTIONS` environment
163
+ variable passed to the process running the tests, for example, `NODE_OPTIONS='-r dd-trace/ci/init' yarn test`.
164
+
7
165
  ## 1.0 to 2.0
8
166
 
9
167
  ### Configuration
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # `dd-trace`: Node.js APM Tracer Library
2
2
 
3
- [![npm v3](https://img.shields.io/npm/v/dd-trace/latest?color=blue&label=dd-trace%40v3&logo=npm)](https://www.npmjs.com/package/dd-trace)
3
+ [![npm v4](https://img.shields.io/npm/v/dd-trace/latest?color=blue&label=dd-trace%40v4&logo=npm)](https://www.npmjs.com/package/dd-trace)
4
+ [![npm v3](https://img.shields.io/npm/v/dd-trace/latest-node14?color=blue&label=dd-trace%40v3&logo=npm)](https://www.npmjs.com/package/dd-trace/v/latest-node12)
4
5
  [![npm v2](https://img.shields.io/npm/v/dd-trace/latest-node12?color=blue&label=dd-trace%40v2&logo=npm)](https://www.npmjs.com/package/dd-trace/v/latest-node12)
5
6
  [![npm dev](https://img.shields.io/npm/v/dd-trace/dev?color=orange&label=dd-trace%40dev&logo=npm)](https://www.npmjs.com/package/dd-trace/v/dev)
6
7
  [![codecov](https://codecov.io/gh/DataDog/dd-trace-js/branch/master/graph/badge.svg)](https://codecov.io/gh/DataDog/dd-trace-js)
@@ -28,27 +29,28 @@ Most of the documentation for `dd-trace` is available on these webpages:
28
29
  | :---: | :---: | :---: | :---: | :---: | :---: |
29
30
  | [`v1`](https://github.com/DataDog/dd-trace-js/tree/v1.x) | ![npm v1](https://img.shields.io/npm/v/dd-trace/legacy-v1?color=white&label=%20&style=flat-square) | `>= v12` | **End of Life** | 2021-07-13 | 2022-02-25 |
30
31
  | [`v2`](https://github.com/DataDog/dd-trace-js/tree/v2.x) | ![npm v2](https://img.shields.io/npm/v/dd-trace/latest-node12?color=white&label=%20&style=flat-square) | `>= v12` | **Maintenance** | 2022-01-28 | 2023-08-15 |
31
- | [`v3`](https://github.com/DataDog/dd-trace-js/tree/v3.x) | ![npm v3](https://img.shields.io/npm/v/dd-trace/latest?color=white&label=%20&style=flat-square) | `>= v14` | **Current** | 2022-08-15 | Unknown |
32
+ | [`v3`](https://github.com/DataDog/dd-trace-js/tree/v3.x) | ![npm v3](https://img.shields.io/npm/v/dd-trace/latest-node14?color=white&label=%20&style=flat-square) | `>= v14` | **Maintenance** | 2022-08-15 | 2024-05-15 |
33
+ | [`v4`](https://github.com/DataDog/dd-trace-js/tree/v4.x) | ![npm v4](https://img.shields.io/npm/v/dd-trace/latest?color=white&label=%20&style=flat-square) | `>= v16` | **Current** | 2023-05-12 | Unknown |
32
34
 
33
- We currently maintain two release lines, namely `v2` and `v3`.
34
- Features and bug fixes that are merged are released to the `v3` line and, if appropriate, also the `v2` line.
35
+ We currently maintain three release lines, namely `v2`, `v3` and `v4`.
36
+ Features and bug fixes that are merged are released to the `v4` line and, if appropriate, also the `v2` and `v3` line.
35
37
 
36
- For any new projects it is recommended to use the `v3` release line:
38
+ For any new projects it is recommended to use the `v4` release line:
37
39
 
38
40
  ```sh
39
41
  $ npm install dd-trace
40
42
  $ yarn add dd-trace
41
43
  ```
42
44
 
43
- However, existing projects that already use the `v2` release line, or projects that need to support Node.js v12, may use the `v2` release line.
45
+ However, existing projects that already use the `v2` or `v3` release lines, or projects that need to support EOL versions of Node.js, may continue to use these release lines.
44
46
  This is done by specifying the version when installing the package.
45
- Note that we also publish to npm using a `latest-node12` tag that can also be used for install:
47
+ Note that we also publish to npm using a `latest-node12` and `latest-node14` tag that can also be used for install:
46
48
 
47
49
  ```sh
48
- $ npm install dd-trace@2
49
- $ yarn add dd-trace@2
50
- $ npm install dd-trace@latest-node12
51
- $ yarn add dd-trace@latest-node12
50
+ $ npm install dd-trace@3
51
+ $ yarn add dd-trace@3
52
+ $ npm install dd-trace@latest-node14
53
+ $ yarn add dd-trace@latest-node14
52
54
  ```
53
55
 
54
56
  Any backwards-breaking functionality that is introduced into the library will result in an increase of the major version of the library and therefore a new release line.
@@ -153,6 +155,11 @@ $ yarn lint
153
155
 
154
156
  ### Experimental ESM Support
155
157
 
158
+ > **Warning**
159
+ >
160
+ > ESM support has been temporarily disabled starting from Node 20 as significant
161
+ > changes are in progress.
162
+
156
163
  ESM support is currently in the experimental stages, while CJS has been supported
157
164
  since inception. This means that code loaded using `require()` should work fine
158
165
  but code loaded using `import` might not always work.
package/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { ClientRequest, IncomingMessage, OutgoingMessage, ServerResponse } from
2
2
  import { LookupFunction } from 'net';
3
3
  import * as opentracing from "opentracing";
4
4
  import { SpanOptions } from "opentracing/lib/tracer";
5
+ import * as otel from "@opentelemetry/api";
5
6
 
6
7
  export { SpanOptions };
7
8
 
@@ -118,6 +119,8 @@ export declare interface Tracer extends opentracing.Tracer {
118
119
  setUser (user: User): Tracer;
119
120
 
120
121
  appsec: Appsec;
122
+
123
+ TracerProvider: opentelemetry.TracerProvider;
121
124
  }
122
125
 
123
126
  export declare interface TraceOptions extends Analyzable {
@@ -756,6 +759,7 @@ interface Plugins {
756
759
  "elasticsearch": plugins.elasticsearch;
757
760
  "express": plugins.express;
758
761
  "fastify": plugins.fastify;
762
+ "fetch": plugins.fetch;
759
763
  "fs": plugins.fs;
760
764
  "generic-pool": plugins.generic_pool;
761
765
  "google-cloud-pubsub": plugins.google_cloud_pubsub;
@@ -1100,6 +1104,12 @@ declare namespace plugins {
1100
1104
  */
1101
1105
  interface fastify extends HttpServer {}
1102
1106
 
1107
+ /**
1108
+ * This plugin automatically instruments the
1109
+ * [fetch](https://nodejs.org/api/globals.html#fetch) global.
1110
+ */
1111
+ interface fetch extends HttpClient {}
1112
+
1103
1113
  /**
1104
1114
  * This plugin automatically instruments the
1105
1115
  * [fs](https://nodejs.org/api/fs.html) module.
@@ -1596,6 +1606,277 @@ declare namespace plugins {
1596
1606
  interface winston extends Integration {}
1597
1607
  }
1598
1608
 
1609
+ export namespace opentelemetry {
1610
+ /**
1611
+ * A registry for creating named {@link Tracer}s.
1612
+ */
1613
+ export interface TracerProvider extends otel.TracerProvider {
1614
+ /**
1615
+ * Construct a new TracerProvider to register with @opentelemetry/api
1616
+ *
1617
+ * @returns TracerProvider A TracerProvider instance
1618
+ */
1619
+ new(): TracerProvider;
1620
+
1621
+ /**
1622
+ * Returns a Tracer, creating one if one with the given name and version is
1623
+ * not already created.
1624
+ *
1625
+ * This function may return different Tracer types (e.g.
1626
+ * {@link NoopTracerProvider} vs. a functional tracer).
1627
+ *
1628
+ * @param name The name of the tracer or instrumentation library.
1629
+ * @param version The version of the tracer or instrumentation library.
1630
+ * @param options The options of the tracer or instrumentation library.
1631
+ * @returns Tracer A Tracer with the given name and version
1632
+ */
1633
+ getTracer(name: string, version?: string): Tracer;
1634
+
1635
+ /**
1636
+ * Register this tracer provider with @opentelemetry/api
1637
+ */
1638
+ register(): void;
1639
+ }
1640
+
1641
+ /**
1642
+ * Tracer provides an interface for creating {@link Span}s.
1643
+ */
1644
+ export interface Tracer extends otel.Tracer {
1645
+ /**
1646
+ * Starts a new {@link Span}. Start the span without setting it on context.
1647
+ *
1648
+ * This method do NOT modify the current Context.
1649
+ *
1650
+ * @param name The name of the span
1651
+ * @param [options] SpanOptions used for span creation
1652
+ * @param [context] Context to use to extract parent
1653
+ * @returns Span The newly created span
1654
+ * @example
1655
+ * const span = tracer.startSpan('op');
1656
+ * span.setAttribute('key', 'value');
1657
+ * span.end();
1658
+ */
1659
+ startSpan(name: string, options?: SpanOptions, context?: Context): Span;
1660
+
1661
+ /**
1662
+ * Starts a new {@link Span} and calls the given function passing it the
1663
+ * created span as first argument.
1664
+ * Additionally the new span gets set in context and this context is activated
1665
+ * for the duration of the function call.
1666
+ *
1667
+ * @param name The name of the span
1668
+ * @param [options] SpanOptions used for span creation
1669
+ * @param [context] Context to use to extract parent
1670
+ * @param fn function called in the context of the span and receives the newly created span as an argument
1671
+ * @returns return value of fn
1672
+ * @example
1673
+ * const something = tracer.startActiveSpan('op', span => {
1674
+ * try {
1675
+ * do some work
1676
+ * span.setStatus({code: SpanStatusCode.OK});
1677
+ * return something;
1678
+ * } catch (err) {
1679
+ * span.setStatus({
1680
+ * code: SpanStatusCode.ERROR,
1681
+ * message: err.message,
1682
+ * });
1683
+ * throw err;
1684
+ * } finally {
1685
+ * span.end();
1686
+ * }
1687
+ * });
1688
+ *
1689
+ * @example
1690
+ * const span = tracer.startActiveSpan('op', span => {
1691
+ * try {
1692
+ * do some work
1693
+ * return span;
1694
+ * } catch (err) {
1695
+ * span.setStatus({
1696
+ * code: SpanStatusCode.ERROR,
1697
+ * message: err.message,
1698
+ * });
1699
+ * throw err;
1700
+ * }
1701
+ * });
1702
+ * do some more work
1703
+ * span.end();
1704
+ */
1705
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): ReturnType<F>;
1706
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): ReturnType<F>;
1707
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: otel.Context, fn: F): ReturnType<F>;
1708
+ }
1709
+
1710
+ /**
1711
+ * An interface that represents a span. A span represents a single operation
1712
+ * within a trace. Examples of span might include remote procedure calls or a
1713
+ * in-process function calls to sub-components. A Trace has a single, top-level
1714
+ * "root" Span that in turn may have zero or more child Spans, which in turn
1715
+ * may have children.
1716
+ *
1717
+ * Spans are created by the {@link Tracer.startSpan} method.
1718
+ */
1719
+ export interface Span extends otel.Span {
1720
+ /**
1721
+ * Returns the {@link SpanContext} object associated with this Span.
1722
+ *
1723
+ * Get an immutable, serializable identifier for this span that can be used
1724
+ * to create new child spans. Returned SpanContext is usable even after the
1725
+ * span ends.
1726
+ *
1727
+ * @returns the SpanContext object associated with this Span.
1728
+ */
1729
+ spanContext(): SpanContext;
1730
+
1731
+ /**
1732
+ * Sets an attribute to the span.
1733
+ *
1734
+ * Sets a single Attribute with the key and value passed as arguments.
1735
+ *
1736
+ * @param key the key for this attribute.
1737
+ * @param value the value for this attribute. Setting a value null or
1738
+ * undefined is invalid and will result in undefined behavior.
1739
+ */
1740
+ setAttribute(key: string, value: SpanAttributeValue): this;
1741
+
1742
+ /**
1743
+ * Sets attributes to the span.
1744
+ *
1745
+ * @param attributes the attributes that will be added.
1746
+ * null or undefined attribute values
1747
+ * are invalid and will result in undefined behavior.
1748
+ */
1749
+ setAttributes(attributes: SpanAttributes): this;
1750
+
1751
+ /**
1752
+ * Adds an event to the Span.
1753
+ *
1754
+ * @param name the name of the event.
1755
+ * @param [attributesOrStartTime] the attributes that will be added; these are
1756
+ * associated with this event. Can be also a start time
1757
+ * if type is {@type TimeInput} and 3rd param is undefined
1758
+ * @param [startTime] start time of the event.
1759
+ */
1760
+ addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this;
1761
+
1762
+ /**
1763
+ * Sets a status to the span. If used, this will override the default Span
1764
+ * status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value
1765
+ * of previous calls to SetStatus on the Span.
1766
+ *
1767
+ * @param status the SpanStatus to set.
1768
+ */
1769
+ setStatus(status: SpanStatus): this;
1770
+
1771
+ /**
1772
+ * Updates the Span name.
1773
+ *
1774
+ * This will override the name provided via {@link Tracer.startSpan}.
1775
+ *
1776
+ * Upon this update, any sampling behavior based on Span name will depend on
1777
+ * the implementation.
1778
+ *
1779
+ * @param name the Span name.
1780
+ */
1781
+ updateName(name: string): this;
1782
+
1783
+ /**
1784
+ * Marks the end of Span execution.
1785
+ *
1786
+ * Call to End of a Span MUST not have any effects on child spans. Those may
1787
+ * still be running and can be ended later.
1788
+ *
1789
+ * Do not return `this`. The Span generally should not be used after it
1790
+ * is ended so chaining is not desired in this context.
1791
+ *
1792
+ * @param [endTime] the time to set as Span's end time. If not provided,
1793
+ * use the current time as the span's end time.
1794
+ */
1795
+ end(endTime?: TimeInput): void;
1796
+
1797
+ /**
1798
+ * Returns the flag whether this span will be recorded.
1799
+ *
1800
+ * @returns true if this Span is active and recording information like events
1801
+ * with the `AddEvent` operation and attributes using `setAttributes`.
1802
+ */
1803
+ isRecording(): boolean;
1804
+
1805
+ /**
1806
+ * Sets exception as a span event
1807
+ * @param exception the exception the only accepted values are string or Error
1808
+ * @param [time] the time to set as Span's event time. If not provided,
1809
+ * use the current time.
1810
+ */
1811
+ recordException(exception: Exception, time?: TimeInput): void;
1812
+ }
1813
+
1814
+ /**
1815
+ * A SpanContext represents the portion of a {@link Span} which must be
1816
+ * serialized and propagated along side of a {@link Baggage}.
1817
+ */
1818
+ export interface SpanContext extends otel.SpanContext {
1819
+ /**
1820
+ * The ID of the trace that this span belongs to. It is worldwide unique
1821
+ * with practically sufficient probability by being made as 16 randomly
1822
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
1823
+ * 128 bits.
1824
+ */
1825
+ traceId: string;
1826
+
1827
+ /**
1828
+ * The ID of the Span. It is globally unique with practically sufficient
1829
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
1830
+ * lowercase hex characters corresponding to 64 bits.
1831
+ */
1832
+ spanId: string;
1833
+
1834
+ /**
1835
+ * Only true if the SpanContext was propagated from a remote parent.
1836
+ */
1837
+ isRemote?: boolean;
1838
+
1839
+ /**
1840
+ * Trace flags to propagate.
1841
+ *
1842
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
1843
+ * sampled or not. When set, the least significant bit documents that the
1844
+ * caller may have recorded trace data. A caller who does not record trace
1845
+ * data out-of-band leaves this flag unset.
1846
+ *
1847
+ * see {@link TraceFlags} for valid flag values.
1848
+ */
1849
+ traceFlags: number;
1850
+
1851
+ /**
1852
+ * Tracing-system-specific info to propagate.
1853
+ *
1854
+ * The tracestate field value is a `list` as defined below. The `list` is a
1855
+ * series of `list-members` separated by commas `,`, and a list-member is a
1856
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
1857
+ * surrounding `list-members` are ignored. There can be a maximum of 32
1858
+ * `list-members` in a `list`.
1859
+ * More Info: https://www.w3.org/TR/trace-context/#tracestate-field
1860
+ *
1861
+ * Examples:
1862
+ * Single tracing system (generic format):
1863
+ * tracestate: rojo=00f067aa0ba902b7
1864
+ * Multiple tracing systems (with different formatting):
1865
+ * tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE
1866
+ */
1867
+ traceState?: TraceState;
1868
+ }
1869
+
1870
+ export type Context = otel.Context;
1871
+ export type Exception = otel.Exception;
1872
+ export type SpanAttributes = otel.SpanAttributes;
1873
+ export type SpanAttributeValue = otel.SpanAttributeValue;
1874
+ export type SpanOptions = otel.SpanOptions;
1875
+ export type SpanStatus = otel.SpanStatus;
1876
+ export type TimeInput = otel.TimeInput;
1877
+ export type TraceState = otel.TraceState;
1878
+ }
1879
+
1599
1880
  /**
1600
1881
  * Singleton returned by the module. It has to be initialized before it will
1601
1882
  * start tracing. If not initialized, or initialized and disabled, it will use
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "2.35.1",
3
+ "version": "2.37.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
20
20
  "test:appsec:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
21
21
  "test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\" -- npm run test:appsec:plugins",
22
- "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,encode,exporters,opentracing,plugins,telemetry}/**/*.spec.js\"",
22
+ "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,config,encode,exporters,opentelemetry,opentracing,plugins,telemetry}/**/*.spec.js\"",
23
23
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
24
24
  "test:instrumentations": "mocha --colors -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
25
25
  "test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
@@ -68,11 +68,13 @@
68
68
  "dependencies": {
69
69
  "@datadog/native-appsec": "^3.2.0",
70
70
  "@datadog/native-iast-rewriter": "2.0.1",
71
- "@datadog/native-iast-taint-tracking": "^1.4.1",
71
+ "@datadog/native-iast-taint-tracking": "^1.5.0",
72
72
  "@datadog/native-metrics": "^1.6.0",
73
- "@datadog/pprof": "^2.2.1",
73
+ "@datadog/pprof": "2.2.3",
74
74
  "@datadog/sketches-js": "^2.1.0",
75
75
  "@types/node": "<18.13",
76
+ "@opentelemetry/api": "^1.0.0",
77
+ "@opentelemetry/core": "<1.4.0",
76
78
  "crypto-randomuuid": "^1.0.0",
77
79
  "diagnostics_channel": "^1.1.0",
78
80
  "ignore": "^5.2.0",
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ const shimmer = require('../../datadog-shimmer')
4
+ const { channel, addHook } = require('./helpers/instrument')
5
+
6
+ const cookieParseCh = channel('datadog:cookie:parse:finish')
7
+
8
+ function wrapParse (originalParse) {
9
+ return function () {
10
+ const cookies = originalParse.apply(this, arguments)
11
+ if (cookieParseCh.hasSubscribers && cookies) {
12
+ cookieParseCh.publish({ cookies })
13
+ }
14
+ return cookies
15
+ }
16
+ }
17
+
18
+ addHook({ name: 'cookie', versions: ['>=0.4'] }, cookie => {
19
+ shimmer.wrap(cookie, 'parse', wrapParse)
20
+ return cookie
21
+ })
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+
3
+ const shimmer = require('../../datadog-shimmer')
4
+ const { channel } = require('./helpers/instrument')
5
+
6
+ const startChannel = channel('apm:fetch:request:start')
7
+ const finishChannel = channel('apm:fetch:request:finish')
8
+ const errorChannel = channel('apm:fetch:request:error')
9
+
10
+ function wrapFetch (fetch, Request) {
11
+ if (typeof fetch !== 'function') return fetch
12
+
13
+ return function (input, init) {
14
+ if (!startChannel.hasSubscribers) return fetch.apply(this, arguments)
15
+
16
+ const req = new Request(input, init)
17
+ const headers = req.headers
18
+ const message = { req, headers }
19
+
20
+ startChannel.publish(message)
21
+
22
+ // Request object is read-only so we need new objects to change headers.
23
+ arguments[0] = message.req
24
+ arguments[1] = { headers: message.headers }
25
+
26
+ return fetch.apply(this, arguments)
27
+ .then(
28
+ res => {
29
+ finishChannel.publish({ req, res })
30
+
31
+ return res
32
+ },
33
+ err => {
34
+ if (err.name !== 'AbortError') {
35
+ errorChannel.publish(err)
36
+ }
37
+
38
+ finishChannel.publish({ req })
39
+
40
+ throw err
41
+ }
42
+ )
43
+ }
44
+ }
45
+
46
+ if (globalThis.fetch) {
47
+ globalThis.fetch = shimmer.wrap(fetch, wrapFetch(fetch, globalThis.Request))
48
+ }
@@ -107,7 +107,7 @@ function wrapStream (call, requestResource, onCancel) {
107
107
  function wrapCallback (callback, call, requestResource, parentResource, onCancel) {
108
108
  return function (err, value, trailer, flags) {
109
109
  requestResource.runInAsyncScope(() => {
110
- if (err instanceof Error) {
110
+ if (err) {
111
111
  errorChannel.publish(err)
112
112
  finishChannel.publish(err)
113
113
  } else {
@@ -14,6 +14,7 @@ module.exports = {
14
14
  '@koa/router': () => require('../koa'),
15
15
  '@node-redis/client': () => require('../redis'),
16
16
  '@opensearch-project/opensearch': () => require('../opensearch'),
17
+ '@opentelemetry/sdk-trace-node': () => require('../otel-sdk-trace'),
17
18
  '@redis/client': () => require('../redis'),
18
19
  'amqp10': () => require('../amqp10'),
19
20
  'amqplib': () => require('../amqplib'),
@@ -25,6 +26,7 @@ module.exports = {
25
26
  'child_process': () => require('../child-process'),
26
27
  'node:child_process': () => require('../child-process'),
27
28
  'connect': () => require('../connect'),
29
+ 'cookie': () => require('../cookie'),
28
30
  'couchbase': () => require('../couchbase'),
29
31
  'crypto': () => require('../crypto'),
30
32
  'cypress': () => require('../cypress'),