dd-trace 4.1.1 → 4.3.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 (61) hide show
  1. package/LICENSE-3rdparty.csv +2 -0
  2. package/index.d.ts +281 -0
  3. package/package.json +6 -4
  4. package/packages/datadog-instrumentations/src/cookie.js +21 -0
  5. package/packages/datadog-instrumentations/src/fetch.js +48 -0
  6. package/packages/datadog-instrumentations/src/grpc/server.js +1 -1
  7. package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -0
  8. package/packages/datadog-instrumentations/src/helpers/register.js +10 -0
  9. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +18 -0
  10. package/packages/datadog-plugin-cypress/src/plugin.js +109 -47
  11. package/packages/datadog-plugin-cypress/src/support.js +3 -2
  12. package/packages/datadog-plugin-fetch/src/index.js +36 -0
  13. package/packages/datadog-plugin-http/src/client.js +24 -8
  14. package/packages/datadog-plugin-mysql/src/index.js +2 -11
  15. package/packages/datadog-plugin-tedious/src/index.js +2 -2
  16. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +3 -0
  17. package/packages/dd-trace/src/appsec/iast/analyzers/cookie-analyzer.js +52 -0
  18. package/packages/dd-trace/src/appsec/iast/analyzers/insecure-cookie-analyzer.js +3 -22
  19. package/packages/dd-trace/src/appsec/iast/analyzers/no-httponly-cookie-analyzer.js +12 -0
  20. package/packages/dd-trace/src/appsec/iast/analyzers/no-samesite-cookie-analyzer.js +12 -0
  21. package/packages/dd-trace/src/appsec/iast/analyzers/set-cookies-header-interceptor.js +7 -3
  22. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +3 -3
  23. package/packages/dd-trace/src/appsec/iast/analyzers/unvalidated-redirect-analyzer.js +48 -0
  24. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +3 -3
  25. package/packages/dd-trace/src/appsec/iast/analyzers/weak-hash-analyzer.js +24 -0
  26. package/packages/dd-trace/src/appsec/iast/index.js +9 -2
  27. package/packages/dd-trace/src/appsec/iast/path-line.js +13 -0
  28. package/packages/dd-trace/src/appsec/iast/tags.js +6 -0
  29. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +2 -1
  30. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +13 -4
  31. package/packages/dd-trace/src/appsec/iast/taint-tracking/origin-types.js +5 -1
  32. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +24 -4
  33. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +3 -1
  34. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +3 -0
  35. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +7 -1
  36. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -3
  37. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +5 -2
  38. package/packages/dd-trace/src/config.js +13 -0
  39. package/packages/dd-trace/src/external-logger/src/index.js +126 -0
  40. package/packages/dd-trace/src/external-logger/test/index.spec.js +147 -0
  41. package/packages/dd-trace/src/lambda/handler.js +3 -15
  42. package/packages/dd-trace/src/noop/proxy.js +4 -0
  43. package/packages/dd-trace/src/opentelemetry/context_manager.js +74 -0
  44. package/packages/dd-trace/src/opentelemetry/sampler.js +18 -0
  45. package/packages/dd-trace/src/opentelemetry/span.js +151 -0
  46. package/packages/dd-trace/src/opentelemetry/span_context.js +44 -0
  47. package/packages/dd-trace/src/opentelemetry/span_processor.js +50 -0
  48. package/packages/dd-trace/src/opentelemetry/tracer.js +124 -0
  49. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +72 -0
  50. package/packages/dd-trace/src/opentracing/span.js +14 -4
  51. package/packages/dd-trace/src/plugin_manager.js +10 -7
  52. package/packages/dd-trace/src/plugins/database.js +7 -3
  53. package/packages/dd-trace/src/plugins/plugin.js +3 -1
  54. package/packages/dd-trace/src/plugins/util/exec.js +2 -2
  55. package/packages/dd-trace/src/plugins/util/git.js +51 -24
  56. package/packages/dd-trace/src/profiling/config.js +2 -0
  57. package/packages/dd-trace/src/profiling/profiler.js +13 -4
  58. package/packages/dd-trace/src/proxy.js +4 -0
  59. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +24 -1
  60. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +18 -1
  61. package/packages/dd-trace/src/util.js +1 -1
@@ -5,6 +5,8 @@ require,@datadog/native-iast-rewriter,Apache license 2.0,Copyright 2018 Datadog
5
5
  require,@datadog/native-iast-taint-tracking,Apache license 2.0,Copyright 2018 Datadog Inc.
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
+ require,@opentelemetry/api,Apache license 2.0,Copyright OpenTelemetry Authors
9
+ require,@opentelemetry/core,Apache license 2.0,Copyright OpenTelemetry Authors
8
10
  require,crypto-randomuuid,MIT,Copyright 2021 Node.js Foundation and contributors
9
11
  require,diagnostics_channel,MIT,Copyright 2021 Simon D.
10
12
  require,ignore,MIT,Copyright 2013 Kael Zhang and contributors
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 {
@@ -746,6 +749,7 @@ interface Plugins {
746
749
  "elasticsearch": plugins.elasticsearch;
747
750
  "express": plugins.express;
748
751
  "fastify": plugins.fastify;
752
+ "fetch": plugins.fetch;
749
753
  "generic-pool": plugins.generic_pool;
750
754
  "google-cloud-pubsub": plugins.google_cloud_pubsub;
751
755
  "graphql": plugins.graphql;
@@ -1089,6 +1093,12 @@ declare namespace plugins {
1089
1093
  */
1090
1094
  interface fastify extends HttpServer {}
1091
1095
 
1096
+ /**
1097
+ * This plugin automatically instruments the
1098
+ * [fetch](https://nodejs.org/api/globals.html#fetch) global.
1099
+ */
1100
+ interface fetch extends HttpClient {}
1101
+
1092
1102
  /**
1093
1103
  * This plugin patches the [generic-pool](https://github.com/coopernurse/node-pool)
1094
1104
  * module to bind the callbacks the the caller context.
@@ -1579,6 +1589,277 @@ declare namespace plugins {
1579
1589
  interface winston extends Integration {}
1580
1590
  }
1581
1591
 
1592
+ export namespace opentelemetry {
1593
+ /**
1594
+ * A registry for creating named {@link Tracer}s.
1595
+ */
1596
+ export interface TracerProvider extends otel.TracerProvider {
1597
+ /**
1598
+ * Construct a new TracerProvider to register with @opentelemetry/api
1599
+ *
1600
+ * @returns TracerProvider A TracerProvider instance
1601
+ */
1602
+ new(): TracerProvider;
1603
+
1604
+ /**
1605
+ * Returns a Tracer, creating one if one with the given name and version is
1606
+ * not already created.
1607
+ *
1608
+ * This function may return different Tracer types (e.g.
1609
+ * {@link NoopTracerProvider} vs. a functional tracer).
1610
+ *
1611
+ * @param name The name of the tracer or instrumentation library.
1612
+ * @param version The version of the tracer or instrumentation library.
1613
+ * @param options The options of the tracer or instrumentation library.
1614
+ * @returns Tracer A Tracer with the given name and version
1615
+ */
1616
+ getTracer(name: string, version?: string): Tracer;
1617
+
1618
+ /**
1619
+ * Register this tracer provider with @opentelemetry/api
1620
+ */
1621
+ register(): void;
1622
+ }
1623
+
1624
+ /**
1625
+ * Tracer provides an interface for creating {@link Span}s.
1626
+ */
1627
+ export interface Tracer extends otel.Tracer {
1628
+ /**
1629
+ * Starts a new {@link Span}. Start the span without setting it on context.
1630
+ *
1631
+ * This method do NOT modify the current Context.
1632
+ *
1633
+ * @param name The name of the span
1634
+ * @param [options] SpanOptions used for span creation
1635
+ * @param [context] Context to use to extract parent
1636
+ * @returns Span The newly created span
1637
+ * @example
1638
+ * const span = tracer.startSpan('op');
1639
+ * span.setAttribute('key', 'value');
1640
+ * span.end();
1641
+ */
1642
+ startSpan(name: string, options?: SpanOptions, context?: Context): Span;
1643
+
1644
+ /**
1645
+ * Starts a new {@link Span} and calls the given function passing it the
1646
+ * created span as first argument.
1647
+ * Additionally the new span gets set in context and this context is activated
1648
+ * for the duration of the function call.
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
+ * @param fn function called in the context of the span and receives the newly created span as an argument
1654
+ * @returns return value of fn
1655
+ * @example
1656
+ * const something = tracer.startActiveSpan('op', span => {
1657
+ * try {
1658
+ * do some work
1659
+ * span.setStatus({code: SpanStatusCode.OK});
1660
+ * return something;
1661
+ * } catch (err) {
1662
+ * span.setStatus({
1663
+ * code: SpanStatusCode.ERROR,
1664
+ * message: err.message,
1665
+ * });
1666
+ * throw err;
1667
+ * } finally {
1668
+ * span.end();
1669
+ * }
1670
+ * });
1671
+ *
1672
+ * @example
1673
+ * const span = tracer.startActiveSpan('op', span => {
1674
+ * try {
1675
+ * do some work
1676
+ * return span;
1677
+ * } catch (err) {
1678
+ * span.setStatus({
1679
+ * code: SpanStatusCode.ERROR,
1680
+ * message: err.message,
1681
+ * });
1682
+ * throw err;
1683
+ * }
1684
+ * });
1685
+ * do some more work
1686
+ * span.end();
1687
+ */
1688
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): ReturnType<F>;
1689
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): ReturnType<F>;
1690
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: otel.Context, fn: F): ReturnType<F>;
1691
+ }
1692
+
1693
+ /**
1694
+ * An interface that represents a span. A span represents a single operation
1695
+ * within a trace. Examples of span might include remote procedure calls or a
1696
+ * in-process function calls to sub-components. A Trace has a single, top-level
1697
+ * "root" Span that in turn may have zero or more child Spans, which in turn
1698
+ * may have children.
1699
+ *
1700
+ * Spans are created by the {@link Tracer.startSpan} method.
1701
+ */
1702
+ export interface Span extends otel.Span {
1703
+ /**
1704
+ * Returns the {@link SpanContext} object associated with this Span.
1705
+ *
1706
+ * Get an immutable, serializable identifier for this span that can be used
1707
+ * to create new child spans. Returned SpanContext is usable even after the
1708
+ * span ends.
1709
+ *
1710
+ * @returns the SpanContext object associated with this Span.
1711
+ */
1712
+ spanContext(): SpanContext;
1713
+
1714
+ /**
1715
+ * Sets an attribute to the span.
1716
+ *
1717
+ * Sets a single Attribute with the key and value passed as arguments.
1718
+ *
1719
+ * @param key the key for this attribute.
1720
+ * @param value the value for this attribute. Setting a value null or
1721
+ * undefined is invalid and will result in undefined behavior.
1722
+ */
1723
+ setAttribute(key: string, value: SpanAttributeValue): this;
1724
+
1725
+ /**
1726
+ * Sets attributes to the span.
1727
+ *
1728
+ * @param attributes the attributes that will be added.
1729
+ * null or undefined attribute values
1730
+ * are invalid and will result in undefined behavior.
1731
+ */
1732
+ setAttributes(attributes: SpanAttributes): this;
1733
+
1734
+ /**
1735
+ * Adds an event to the Span.
1736
+ *
1737
+ * @param name the name of the event.
1738
+ * @param [attributesOrStartTime] the attributes that will be added; these are
1739
+ * associated with this event. Can be also a start time
1740
+ * if type is {@type TimeInput} and 3rd param is undefined
1741
+ * @param [startTime] start time of the event.
1742
+ */
1743
+ addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this;
1744
+
1745
+ /**
1746
+ * Sets a status to the span. If used, this will override the default Span
1747
+ * status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value
1748
+ * of previous calls to SetStatus on the Span.
1749
+ *
1750
+ * @param status the SpanStatus to set.
1751
+ */
1752
+ setStatus(status: SpanStatus): this;
1753
+
1754
+ /**
1755
+ * Updates the Span name.
1756
+ *
1757
+ * This will override the name provided via {@link Tracer.startSpan}.
1758
+ *
1759
+ * Upon this update, any sampling behavior based on Span name will depend on
1760
+ * the implementation.
1761
+ *
1762
+ * @param name the Span name.
1763
+ */
1764
+ updateName(name: string): this;
1765
+
1766
+ /**
1767
+ * Marks the end of Span execution.
1768
+ *
1769
+ * Call to End of a Span MUST not have any effects on child spans. Those may
1770
+ * still be running and can be ended later.
1771
+ *
1772
+ * Do not return `this`. The Span generally should not be used after it
1773
+ * is ended so chaining is not desired in this context.
1774
+ *
1775
+ * @param [endTime] the time to set as Span's end time. If not provided,
1776
+ * use the current time as the span's end time.
1777
+ */
1778
+ end(endTime?: TimeInput): void;
1779
+
1780
+ /**
1781
+ * Returns the flag whether this span will be recorded.
1782
+ *
1783
+ * @returns true if this Span is active and recording information like events
1784
+ * with the `AddEvent` operation and attributes using `setAttributes`.
1785
+ */
1786
+ isRecording(): boolean;
1787
+
1788
+ /**
1789
+ * Sets exception as a span event
1790
+ * @param exception the exception the only accepted values are string or Error
1791
+ * @param [time] the time to set as Span's event time. If not provided,
1792
+ * use the current time.
1793
+ */
1794
+ recordException(exception: Exception, time?: TimeInput): void;
1795
+ }
1796
+
1797
+ /**
1798
+ * A SpanContext represents the portion of a {@link Span} which must be
1799
+ * serialized and propagated along side of a {@link Baggage}.
1800
+ */
1801
+ export interface SpanContext extends otel.SpanContext {
1802
+ /**
1803
+ * The ID of the trace that this span belongs to. It is worldwide unique
1804
+ * with practically sufficient probability by being made as 16 randomly
1805
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
1806
+ * 128 bits.
1807
+ */
1808
+ traceId: string;
1809
+
1810
+ /**
1811
+ * The ID of the Span. It is globally unique with practically sufficient
1812
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
1813
+ * lowercase hex characters corresponding to 64 bits.
1814
+ */
1815
+ spanId: string;
1816
+
1817
+ /**
1818
+ * Only true if the SpanContext was propagated from a remote parent.
1819
+ */
1820
+ isRemote?: boolean;
1821
+
1822
+ /**
1823
+ * Trace flags to propagate.
1824
+ *
1825
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
1826
+ * sampled or not. When set, the least significant bit documents that the
1827
+ * caller may have recorded trace data. A caller who does not record trace
1828
+ * data out-of-band leaves this flag unset.
1829
+ *
1830
+ * see {@link TraceFlags} for valid flag values.
1831
+ */
1832
+ traceFlags: number;
1833
+
1834
+ /**
1835
+ * Tracing-system-specific info to propagate.
1836
+ *
1837
+ * The tracestate field value is a `list` as defined below. The `list` is a
1838
+ * series of `list-members` separated by commas `,`, and a list-member is a
1839
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
1840
+ * surrounding `list-members` are ignored. There can be a maximum of 32
1841
+ * `list-members` in a `list`.
1842
+ * More Info: https://www.w3.org/TR/trace-context/#tracestate-field
1843
+ *
1844
+ * Examples:
1845
+ * Single tracing system (generic format):
1846
+ * tracestate: rojo=00f067aa0ba902b7
1847
+ * Multiple tracing systems (with different formatting):
1848
+ * tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE
1849
+ */
1850
+ traceState?: TraceState;
1851
+ }
1852
+
1853
+ export type Context = otel.Context;
1854
+ export type Exception = otel.Exception;
1855
+ export type SpanAttributes = otel.SpanAttributes;
1856
+ export type SpanAttributeValue = otel.SpanAttributeValue;
1857
+ export type SpanOptions = otel.SpanOptions;
1858
+ export type SpanStatus = otel.SpanStatus;
1859
+ export type TimeInput = otel.TimeInput;
1860
+ export type TraceState = otel.TraceState;
1861
+ }
1862
+
1582
1863
  /**
1583
1864
  * Singleton returned by the module. It has to be initialized before it will
1584
1865
  * 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": "4.1.1",
3
+ "version": "4.3.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,10 +68,12 @@
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": "^2.0.0",
73
- "@datadog/pprof": "^2.2.1",
73
+ "@datadog/pprof": "2.2.3",
74
74
  "@datadog/sketches-js": "^2.1.0",
75
+ "@opentelemetry/api": "^1.0.0",
76
+ "@opentelemetry/core": "^1.14.0",
75
77
  "crypto-randomuuid": "^1.0.0",
76
78
  "diagnostics_channel": "^1.1.0",
77
79
  "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
+ }
@@ -109,7 +109,7 @@ function wrapStream (call, requestResource, onCancel) {
109
109
  function wrapCallback (callback, call, requestResource, parentResource, onCancel) {
110
110
  return function (err, value, trailer, flags) {
111
111
  requestResource.runInAsyncScope(() => {
112
- if (err instanceof Error) {
112
+ if (err) {
113
113
  errorChannel.publish(err)
114
114
  finishChannel.publish(err)
115
115
  } 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'),
@@ -7,16 +7,26 @@ const Hook = require('./hook')
7
7
  const requirePackageJson = require('../../../dd-trace/src/require-package-json')
8
8
  const log = require('../../../dd-trace/src/log')
9
9
 
10
+ const { DD_TRACE_DISABLED_INSTRUMENTATIONS = '' } = process.env
11
+
10
12
  const hooks = require('./hooks')
11
13
  const instrumentations = require('./instrumentations')
12
14
  const names = Object.keys(hooks)
13
15
  const pathSepExpr = new RegExp(`\\${path.sep}`, 'g')
16
+ const disabledInstrumentations = new Set(
17
+ DD_TRACE_DISABLED_INSTRUMENTATIONS ? DD_TRACE_DISABLED_INSTRUMENTATIONS.split(',') : []
18
+ )
14
19
 
15
20
  const loadChannel = channel('dd-trace:instrumentation:load')
16
21
 
22
+ // Globals
23
+ require('../fetch')
24
+
17
25
  // TODO: make this more efficient
18
26
 
19
27
  for (const packageName of names) {
28
+ if (disabledInstrumentations.has(packageName)) continue
29
+
20
30
  Hook([packageName], (moduleExports, moduleName, moduleBaseDir, moduleVersion) => {
21
31
  moduleName = moduleName.replace(pathSepExpr, '/')
22
32
 
@@ -0,0 +1,18 @@
1
+ 'use strict'
2
+
3
+ const { addHook } = require('./helpers/instrument')
4
+ const shimmer = require('../../datadog-shimmer')
5
+ const tracer = require('../../dd-trace')
6
+
7
+ if (process.env.DD_TRACE_OTEL_ENABLED) {
8
+ addHook({
9
+ name: '@opentelemetry/sdk-trace-node',
10
+ file: 'build/src/NodeTracerProvider.js',
11
+ versions: ['*']
12
+ }, (mod) => {
13
+ shimmer.wrap(mod, 'NodeTracerProvider', () => {
14
+ return tracer.TracerProvider
15
+ })
16
+ return mod
17
+ })
18
+ }