dd-trace 5.0.0-pre-4c05491 → 5.0.0-pre-b37a12e

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.
@@ -32,6 +32,7 @@ require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
32
32
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
33
33
  dev,@types/node,MIT,Copyright Authors
34
34
  dev,autocannon,MIT,Copyright 2016 Matteo Collina
35
+ dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
36
  dev,axios,MIT,Copyright 2014-present Matt Zabriskie
36
37
  dev,benchmark,MIT,Copyright 2010-2016 Mathias Bynens Robert Kieffer John-David Dalton
37
38
  dev,body-parser,MIT,Copyright 2014 Jonathan Ong 2014-2015 Douglas Christopher Wilson
package/index.d.ts CHANGED
@@ -829,6 +829,7 @@ interface Plugins {
829
829
  "mysql2": plugins.mysql2;
830
830
  "net": plugins.net;
831
831
  "next": plugins.next;
832
+ "openai": plugins.openai;
832
833
  "opensearch": plugins.opensearch;
833
834
  "oracledb": plugins.oracledb;
834
835
  "paperplane": plugins.paperplane;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.0.0-pre-4c05491",
3
+ "version": "5.0.0-pre-b37a12e",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "test:integration:cypress": "mocha --colors --timeout 30000 \"integration-tests/cypress/*.spec.js\"",
38
38
  "test:integration:playwright": "mocha --colors --timeout 30000 \"integration-tests/playwright/*.spec.js\"",
39
39
  "test:integration:serverless": "mocha --colors --timeout 30000 \"integration-tests/serverless/*.spec.js\"",
40
- "test:integration:plugins": "mocha --colors --timeout 30000 \"packages/datadog-plugin-*/test/integration-test/*.spec.js\"",
40
+ "test:integration:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
41
41
  "test:unit:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
42
42
  "test:shimmer": "mocha --colors 'packages/datadog-shimmer/test/**/*.spec.js'",
43
43
  "test:shimmer:ci": "nyc --no-clean --include 'packages/datadog-shimmer/src/**/*.js' -- npm run test:shimmer",
@@ -103,6 +103,7 @@
103
103
  "devDependencies": {
104
104
  "@types/node": ">=16",
105
105
  "autocannon": "^4.5.2",
106
+ "aws-sdk": "^2.1446.0",
106
107
  "axios": "^0.21.2",
107
108
  "benchmark": "^2.1.4",
108
109
  "body-parser": "^1.20.2",
@@ -23,11 +23,12 @@ for (const instrumentation of Object.values(instrumentations)) {
23
23
  }
24
24
  }
25
25
 
26
- const NAMESPACE = 'datadog'
27
26
  const NM = 'node_modules/'
28
27
  const INSTRUMENTED = Object.keys(instrumentations)
29
28
  const RAW_BUILTINS = require('module').builtinModules
30
29
  const CHANNEL = 'dd-trace:bundler:load'
30
+ const path = require('path')
31
+ const fs = require('fs')
31
32
 
32
33
  const builtins = new Set()
33
34
 
@@ -109,55 +110,59 @@ module.exports.setup = function (build) {
109
110
  // https://esbuild.github.io/plugins/#on-resolve-arguments
110
111
  return {
111
112
  path: fullPathToModule,
112
- namespace: NAMESPACE,
113
113
  pluginData: {
114
114
  version: packageJson.version,
115
115
  pkg: extracted.pkg,
116
116
  path: extracted.path,
117
117
  full: fullPathToModule,
118
118
  raw: args.path,
119
+ pkgOfInterest: true,
119
120
  internal
120
121
  }
121
122
  }
122
- } else if (args.namespace === NAMESPACE) {
123
- // The datadog namespace is used when requiring files that are injected during the onLoad stage
124
-
125
- if (builtins.has(args.path)) return
126
-
127
- return {
128
- path: require.resolve(args.path, { paths: [ args.resolveDir ] }),
129
- namespace: 'file'
130
- }
131
123
  }
132
124
  })
133
125
 
134
- build.onLoad({ filter: /.*/, namespace: NAMESPACE }, args => {
126
+ build.onLoad({ filter: /.*/ }, args => {
127
+ if (!args.pluginData?.pkgOfInterest) {
128
+ return
129
+ }
130
+
135
131
  const data = args.pluginData
136
132
 
137
133
  if (DEBUG) console.log(`LOAD: ${data.pkg}@${data.version}, pkg "${data.path}"`)
138
134
 
139
- const path = data.raw !== data.pkg
135
+ const pkgPath = data.raw !== data.pkg
140
136
  ? `${data.pkg}/${data.path}`
141
137
  : data.pkg
142
138
 
139
+ // Read the content of the module file of interest
140
+ const fileCode = fs.readFileSync(args.path, 'utf8')
141
+
143
142
  const contents = `
144
- const dc = require('diagnostics_channel');
145
- const ch = dc.channel('${CHANNEL}');
146
- const mod = require('${args.path}');
147
- const payload = {
148
- module: mod,
149
- version: '${data.version}',
150
- package: '${data.pkg}',
151
- path: '${path}'
152
- };
153
- ch.publish(payload);
154
- module.exports = payload.module;
143
+ (function() {
144
+ ${fileCode}
145
+ })(...arguments);
146
+ {
147
+ const dc = require('diagnostics_channel');
148
+ const ch = dc.channel('${CHANNEL}');
149
+ const mod = module.exports
150
+ const payload = {
151
+ module: mod,
152
+ version: '${data.version}',
153
+ package: '${data.pkg}',
154
+ path: '${pkgPath}'
155
+ };
156
+ ch.publish(payload);
157
+ module.exports = payload.module;
158
+ }
155
159
  `
156
160
 
157
161
  // https://esbuild.github.io/plugins/#on-load-results
158
162
  return {
159
163
  contents,
160
- loader: 'js'
164
+ loader: 'js',
165
+ resolveDir: path.dirname(args.path)
161
166
  }
162
167
  })
163
168
  }
@@ -350,6 +350,11 @@ function finishResolvers ({ fields }) {
350
350
  })
351
351
  }
352
352
 
353
+ addHook({ name: '@graphql-tools/executor', file: 'cjs/execution/execute.js', versions: ['>=0.0.14'] }, execute => {
354
+ shimmer.wrap(execute, 'execute', wrapExecute(execute))
355
+ return execute
356
+ })
357
+
353
358
  addHook({ name: 'graphql', file: 'execution/execute.js', versions: ['>=0.10'] }, execute => {
354
359
  shimmer.wrap(execute, 'execute', wrapExecute(execute))
355
360
  return execute
@@ -7,6 +7,7 @@ module.exports = {
7
7
  '@elastic/elasticsearch': () => require('../elasticsearch'),
8
8
  '@elastic/transport': () => require('../elasticsearch'),
9
9
  '@google-cloud/pubsub': () => require('../google-cloud-pubsub'),
10
+ '@graphql-tools/executor': () => require('../graphql'),
10
11
  '@grpc/grpc-js': () => require('../grpc'),
11
12
  '@hapi/hapi': () => require('../hapi'),
12
13
  '@jest/core': () => require('../jest'),
@@ -9,7 +9,7 @@ class MySQLPlugin extends DatabasePlugin {
9
9
 
10
10
  start (payload) {
11
11
  const service = this.serviceName({ pluginConfig: this.config, dbConfig: payload.conf, system: this.system })
12
- this.startSpan(this.operationName(), {
12
+ const span = this.startSpan(this.operationName(), {
13
13
  service,
14
14
  resource: payload.sql,
15
15
  type: 'sql',
@@ -22,7 +22,7 @@ class MySQLPlugin extends DatabasePlugin {
22
22
  [CLIENT_PORT_KEY]: payload.conf.port
23
23
  }
24
24
  })
25
- payload.sql = this.injectDbmQuery(payload.sql, service)
25
+ payload.sql = this.injectDbmQuery(span, payload.sql, service)
26
26
  }
27
27
  }
28
28
 
@@ -12,7 +12,7 @@ class PGPlugin extends DatabasePlugin {
12
12
  const service = this.serviceName({ pluginConfig: this.config, params })
13
13
  const originalStatement = this.maybeTruncate(query.text)
14
14
 
15
- this.startSpan(this.operationName(), {
15
+ const span = this.startSpan(this.operationName(), {
16
16
  service,
17
17
  resource: originalStatement,
18
18
  type: 'sql',
@@ -27,7 +27,7 @@ class PGPlugin extends DatabasePlugin {
27
27
  }
28
28
  })
29
29
 
30
- query.__ddInjectableQuery = this.injectDbmQuery(query.text, service, !!query.name)
30
+ query.__ddInjectableQuery = this.injectDbmQuery(span, query.text, service, !!query.name)
31
31
  }
32
32
  }
33
33
 
@@ -28,25 +28,12 @@ function getItrConfiguration ({
28
28
  if (isEvpProxy) {
29
29
  options.path = '/evp_proxy/v2/api/v2/libraries/tests/services/setting'
30
30
  options.headers['X-Datadog-EVP-Subdomain'] = 'api'
31
- options.headers['X-Datadog-NeedsAppKey'] = 'true'
32
31
  } else {
33
32
  const apiKey = process.env.DATADOG_API_KEY || process.env.DD_API_KEY
34
- const appKey = process.env.DATADOG_APP_KEY ||
35
- process.env.DD_APP_KEY ||
36
- process.env.DATADOG_APPLICATION_KEY ||
37
- process.env.DD_APPLICATION_KEY
38
-
39
- const messagePrefix = 'Request to settings endpoint was not done because Datadog'
40
-
41
- if (!appKey) {
42
- return done(new Error(`${messagePrefix} application key is not defined.`))
43
- }
44
33
  if (!apiKey) {
45
- return done(new Error(`${messagePrefix} API key is not defined.`))
34
+ return done(new Error('Request to settings endpoint was not done because Datadog API key is not defined.'))
46
35
  }
47
-
48
36
  options.headers['dd-api-key'] = apiKey
49
- options.headers['dd-application-key'] = appKey
50
37
  }
51
38
 
52
39
  const data = JSON.stringify({
@@ -28,25 +28,13 @@ function getSkippableSuites ({
28
28
  if (isEvpProxy) {
29
29
  options.path = '/evp_proxy/v2/api/v2/ci/tests/skippable'
30
30
  options.headers['X-Datadog-EVP-Subdomain'] = 'api'
31
- options.headers['X-Datadog-NeedsAppKey'] = 'true'
32
31
  } else {
33
32
  const apiKey = process.env.DATADOG_API_KEY || process.env.DD_API_KEY
34
- const appKey = process.env.DATADOG_APP_KEY ||
35
- process.env.DD_APP_KEY ||
36
- process.env.DATADOG_APPLICATION_KEY ||
37
- process.env.DD_APPLICATION_KEY
38
-
39
- const messagePrefix = 'Skippable suites were not fetched because Datadog'
40
-
41
- if (!appKey) {
42
- return done(new Error(`${messagePrefix} application key is not defined.`))
43
- }
44
33
  if (!apiKey) {
45
- return done(new Error(`${messagePrefix} API key is not defined.`))
34
+ return done(new Error('Skippable suites were not fetched because Datadog API key is not defined.'))
46
35
  }
47
36
 
48
37
  options.headers['dd-api-key'] = apiKey
49
- options.headers['dd-application-key'] = appKey
50
38
  }
51
39
 
52
40
  const data = JSON.stringify({
@@ -343,10 +343,10 @@ class TextMapPropagator {
343
343
  spanContext._trace.origin = value
344
344
  break
345
345
  case 't.dm': {
346
- const mechanism = -Math.abs(parseInt(value, 10))
346
+ const mechanism = Math.abs(parseInt(value, 10))
347
347
  if (Number.isInteger(mechanism)) {
348
348
  spanContext._sampling.mechanism = mechanism
349
- spanContext._trace.tags['_dd.p.dm'] = String(mechanism)
349
+ spanContext._trace.tags['_dd.p.dm'] = `-${mechanism}`
350
350
  }
351
351
  break
352
352
  }
@@ -26,8 +26,6 @@ class DatadogTracer {
26
26
  this._version = config.version
27
27
  this._env = config.env
28
28
  this._tags = config.tags
29
- this._computePeerService = config.spanComputePeerService
30
- this._peerServiceMapping = config.peerServiceMapping
31
29
  this._logInjection = config.logInjection
32
30
  this._debug = config.debug
33
31
  this._prioritySampler = new PrioritySampler(config.env, config.sampler)
@@ -72,11 +72,10 @@ module.exports = class PluginManager {
72
72
  const Plugin = pluginClasses[name]
73
73
 
74
74
  if (!Plugin) return
75
+ if (!this._tracerConfig) return // TODO: don't wait for tracer to be initialized
75
76
  if (!this._pluginsByName[name]) {
76
77
  this._pluginsByName[name] = new Plugin(this._tracer, this._tracerConfig)
77
78
  }
78
- if (!this._tracerConfig) return // TODO: don't wait for tracer to be initialized
79
-
80
79
  const pluginConfig = this._configsByName[name] || {
81
80
  enabled: this._tracerConfig.plugins !== false
82
81
  }
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const StoragePlugin = require('./storage')
4
+ const { PEER_SERVICE_KEY } = require('../constants')
4
5
 
5
6
  class DatabasePlugin extends StoragePlugin {
6
7
  static get operation () { return 'query' }
@@ -38,20 +39,29 @@ class DatabasePlugin extends StoragePlugin {
38
39
  `ddps='${encodedDdps}',ddpv='${encodedDdpv}'`
39
40
  }
40
41
 
41
- injectDbmQuery (query, serviceName, isPreparedStatement = false) {
42
+ getDbmServiceName (span, tracerService) {
43
+ if (this._tracerConfig.spanComputePeerService) {
44
+ const peerData = this.getPeerService(span.context()._tags)
45
+ return this.getPeerServiceRemap(peerData)[PEER_SERVICE_KEY] || tracerService
46
+ }
47
+ return tracerService
48
+ }
49
+
50
+ injectDbmQuery (span, query, serviceName, isPreparedStatement = false) {
42
51
  const mode = this.config.dbmPropagationMode
52
+ const dbmService = this.getDbmServiceName(span, serviceName)
43
53
 
44
54
  if (mode === 'disabled') {
45
55
  return query
46
56
  }
47
57
 
48
- const servicePropagation = this.createDBMPropagationCommentService(serviceName)
58
+ const servicePropagation = this.createDBMPropagationCommentService(dbmService)
49
59
 
50
60
  if (isPreparedStatement || mode === 'service') {
51
61
  return `/*${servicePropagation}*/ ${query}`
52
62
  } else if (mode === 'full') {
53
- this.activeSpan.setTag('_dd.dbm_trace_injected', 'true')
54
- const traceparent = this.activeSpan._spanContext.toTraceparent()
63
+ span.setTag('_dd.dbm_trace_injected', 'true')
64
+ const traceparent = span._spanContext.toTraceparent()
55
65
  return `/*${servicePropagation},traceparent='${traceparent}'*/ ${query}`
56
66
  }
57
67
  }
@@ -64,10 +64,11 @@ class OutboundPlugin extends TracingPlugin {
64
64
  * peer service and add the value we overrode.
65
65
  */
66
66
  const peerService = peerData[PEER_SERVICE_KEY]
67
- if (peerService && this.tracer._peerServiceMapping[peerService]) {
67
+ const mappedService = this._tracerConfig.peerServiceMapping?.[peerService]
68
+ if (peerService && mappedService) {
68
69
  return {
69
70
  ...peerData,
70
- [PEER_SERVICE_KEY]: this.tracer._peerServiceMapping[peerService],
71
+ [PEER_SERVICE_KEY]: mappedService,
71
72
  [PEER_SERVICE_REMAP_KEY]: peerService
72
73
  }
73
74
  }
@@ -80,7 +81,7 @@ class OutboundPlugin extends TracingPlugin {
80
81
  }
81
82
 
82
83
  tagPeerService (span) {
83
- if (this.tracer._computePeerService) {
84
+ if (this._tracerConfig.spanComputePeerService) {
84
85
  const peerData = this.getPeerService(span.context()._tags)
85
86
  if (peerData !== undefined) {
86
87
  span.addTags(this.getPeerServiceRemap(peerData))