dd-trace 5.0.0-pre-244a0ea → 5.0.0-pre-cd5fbdb

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.0.0-pre-244a0ea",
3
+ "version": "5.0.0-pre-cd5fbdb",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -15,15 +15,14 @@ const consumerStartCh = channel('apm:kafkajs:consume:start')
15
15
  const consumerFinishCh = channel('apm:kafkajs:consume:finish')
16
16
  const consumerErrorCh = channel('apm:kafkajs:consume:error')
17
17
 
18
- addHook({ name: 'kafkajs', versions: ['>=1.4'] }, (obj) => {
19
- class Kafka extends obj.Kafka {
18
+ addHook({ name: 'kafkajs', file: 'src/index.js', versions: ['>=1.4'] }, (BaseKafka) => {
19
+ class Kafka extends BaseKafka {
20
20
  constructor (options) {
21
21
  super(options)
22
22
  this._brokers = (options.brokers && typeof options.brokers !== 'function')
23
23
  ? options.brokers.join(',') : undefined
24
24
  }
25
25
  }
26
- obj.Kafka = Kafka
27
26
 
28
27
  shimmer.wrap(Kafka.prototype, 'producer', createProducer => function () {
29
28
  const producer = createProducer.apply(this, arguments)
@@ -117,5 +116,5 @@ addHook({ name: 'kafkajs', versions: ['>=1.4'] }, (obj) => {
117
116
  }
118
117
  return consumer
119
118
  })
120
- return obj
119
+ return Kafka
121
120
  })
@@ -441,6 +441,9 @@ addHook({
441
441
  file: 'lib/cli/run-helpers.js'
442
442
  }, (run) => {
443
443
  shimmer.wrap(run, 'runMocha', runMocha => async function () {
444
+ if (!testStartCh.hasSubscribers) {
445
+ return runMocha.apply(this, arguments)
446
+ }
444
447
  const mocha = arguments[0]
445
448
  /**
446
449
  * This attaches `run` to the global context, which we'll call after
@@ -25,6 +25,7 @@ const {
25
25
  } = require('../../dd-trace/src/plugins/util/test')
26
26
  const { ORIGIN_KEY, COMPONENT } = require('../../dd-trace/src/constants')
27
27
  const log = require('../../dd-trace/src/log')
28
+ const NoopTracer = require('../../dd-trace/src/noop/tracer')
28
29
 
29
30
  const TEST_FRAMEWORK_NAME = 'cypress'
30
31
 
@@ -119,10 +120,32 @@ function getSkippableTests (isSuitesSkippingEnabled, tracer, testConfiguration)
119
120
  })
120
121
  }
121
122
 
123
+ const noopTask = {
124
+ 'dd:testSuiteStart': () => {
125
+ return null
126
+ },
127
+ 'dd:beforeEach': () => {
128
+ return {}
129
+ },
130
+ 'dd:afterEach': () => {
131
+ return null
132
+ },
133
+ 'dd:addTags': () => {
134
+ return null
135
+ }
136
+ }
137
+
122
138
  module.exports = (on, config) => {
123
139
  let isTestsSkipped = false
124
140
  const skippedTests = []
125
141
  const tracer = require('../../dd-trace')
142
+
143
+ // The tracer was not init correctly for whatever reason (such as invalid DD_SITE)
144
+ if (tracer._tracer instanceof NoopTracer) {
145
+ // We still need to register these tasks or the support file will fail
146
+ return on('task', noopTask)
147
+ }
148
+
126
149
  const testEnvironmentMetadata = getTestEnvironmentMetadata(TEST_FRAMEWORK_NAME)
127
150
 
128
151
  const {
@@ -328,12 +351,16 @@ module.exports = (on, config) => {
328
351
  }
329
352
 
330
353
  return new Promise(resolve => {
331
- if (tracer._tracer._exporter.flush) {
332
- tracer._tracer._exporter.flush(() => {
354
+ const exporter = tracer._tracer._exporter
355
+ if (!exporter) {
356
+ return resolve(null)
357
+ }
358
+ if (exporter.flush) {
359
+ exporter.flush(() => {
333
360
  resolve(null)
334
361
  })
335
- } else {
336
- tracer._tracer._exporter._writer.flush(() => {
362
+ } else if (exporter._writer) {
363
+ exporter._writer.flush(() => {
337
364
  resolve(null)
338
365
  })
339
366
  }
@@ -375,7 +402,7 @@ module.exports = (on, config) => {
375
402
  'dd:afterEach': ({ test, coverage }) => {
376
403
  const { state, error, isRUMActive, testSourceLine, testSuite, testName } = test
377
404
  if (activeSpan) {
378
- if (coverage && tracer._tracer._exporter.exportCoverage && isCodeCoverageEnabled) {
405
+ if (coverage && isCodeCoverageEnabled && tracer._tracer._exporter && tracer._tracer._exporter.exportCoverage) {
379
406
  const coverageFiles = getCoveredFilenamesFromCoverage(coverage)
380
407
  const relativeCoverageFiles = coverageFiles.map(file => getTestSuitePath(file, rootDir))
381
408
  const { _traceId, _spanId } = testSuiteSpan.context()
@@ -36,10 +36,14 @@ class MongodbCorePlugin extends DatabasePlugin {
36
36
  }
37
37
  }
38
38
 
39
+ function sanitizeBigInt (data) {
40
+ return JSON.stringify(data, (_key, value) => typeof value === 'bigint' ? value.toString() : value)
41
+ }
42
+
39
43
  function getQuery (cmd) {
40
44
  if (!cmd || typeof cmd !== 'object' || Array.isArray(cmd)) return
41
- if (cmd.query) return JSON.stringify(limitDepth(cmd.query))
42
- if (cmd.filter) return JSON.stringify(limitDepth(cmd.filter))
45
+ if (cmd.query) return sanitizeBigInt(limitDepth(cmd.query))
46
+ if (cmd.filter) return sanitizeBigInt(limitDepth(cmd.filter))
43
47
  }
44
48
 
45
49
  function getResource (plugin, ns, query, operationName) {
@@ -76,7 +76,18 @@ class SensitiveHandler {
76
76
  while (nextSensitive != null && contains(nextTainted, nextSensitive)) {
77
77
  const redactionStart = nextSensitive.start - nextTainted.start
78
78
  const redactionEnd = nextSensitive.end - nextTainted.start
79
- this.redactSource(sources, redactedSources, redactedSourcesContext, sourceIndex, redactionStart, redactionEnd)
79
+ if (redactionStart === redactionEnd) {
80
+ this.writeRedactedValuePart(valueParts, 0)
81
+ } else {
82
+ this.redactSource(
83
+ sources,
84
+ redactedSources,
85
+ redactedSourcesContext,
86
+ sourceIndex,
87
+ redactionStart,
88
+ redactionEnd
89
+ )
90
+ }
80
91
  nextSensitive = sensitive.shift()
81
92
  }
82
93
 
@@ -139,13 +139,13 @@ function removeInvalidMetadata (metadata) {
139
139
  return Object.keys(metadata).reduce((filteredTags, tag) => {
140
140
  if (tag === GIT_REPOSITORY_URL) {
141
141
  if (!validateGitRepositoryUrl(metadata[GIT_REPOSITORY_URL])) {
142
- log.error('DD_GIT_REPOSITORY_URL must be a valid URL')
142
+ log.error(`Repository URL is not a valid repository URL: ${metadata[GIT_REPOSITORY_URL]}.`)
143
143
  return filteredTags
144
144
  }
145
145
  }
146
146
  if (tag === GIT_COMMIT_SHA) {
147
147
  if (!validateGitCommitSha(metadata[GIT_COMMIT_SHA])) {
148
- log.error('DD_GIT_COMMIT_SHA must be a full-length git SHA')
148
+ log.error(`Git commit SHA must be a full-length git SHA: ${metadata[GIT_COMMIT_SHA]}.`)
149
149
  return filteredTags
150
150
  }
151
151
  }
@@ -15,6 +15,7 @@ const FILE_URI_START = `file://`
15
15
  const moduleLoadStartChannel = dc.channel('dd-trace:moduleLoadStart')
16
16
 
17
17
  let immediate, config, application, host
18
+ let isFirstModule = true
18
19
 
19
20
  function waitAndSend (config, application, host) {
20
21
  if (!immediate) {
@@ -36,7 +37,21 @@ function waitAndSend (config, application, host) {
36
37
  }
37
38
  }
38
39
 
40
+ function loadAllTheLoadedModules () {
41
+ if (require.cache) {
42
+ const filenames = Object.keys(require.cache)
43
+ filenames.forEach(filename => {
44
+ onModuleLoad({ filename })
45
+ })
46
+ }
47
+ }
48
+
39
49
  function onModuleLoad (data) {
50
+ if (isFirstModule) {
51
+ isFirstModule = false
52
+ loadAllTheLoadedModules()
53
+ }
54
+
40
55
  if (data) {
41
56
  let filename = data.filename
42
57
  if (filename && filename.startsWith(FILE_URI_START)) {
@@ -17,6 +17,7 @@ let pluginManager
17
17
  let application
18
18
  let host
19
19
  let interval
20
+ let heartbeatTimeout
20
21
  let heartbeatInterval
21
22
  const sentIntegrations = new Set()
22
23
 
@@ -110,6 +111,14 @@ function getTelemetryData () {
110
111
  return { config, application, host, heartbeatInterval }
111
112
  }
112
113
 
114
+ function heartbeat (config, application, host) {
115
+ heartbeatTimeout = setTimeout(() => {
116
+ sendData(config, application, host, 'app-heartbeat')
117
+ heartbeat(config, application, host)
118
+ }, heartbeatInterval).unref()
119
+ return heartbeatTimeout
120
+ }
121
+
113
122
  function start (aConfig, thePluginManager) {
114
123
  if (!aConfig.telemetry.enabled) {
115
124
  return
@@ -122,9 +131,9 @@ function start (aConfig, thePluginManager) {
122
131
 
123
132
  dependencies.start(config, application, host)
124
133
  sendData(config, application, host, 'app-started', appStarted())
134
+ heartbeat(config, application, host)
125
135
  interval = setInterval(() => {
126
136
  metricsManager.send(config, application, host)
127
- sendData(config, application, host, 'app-heartbeat')
128
137
  }, heartbeatInterval)
129
138
  interval.unref()
130
139
  process.on('beforeExit', onBeforeExit)
@@ -137,6 +146,7 @@ function stop () {
137
146
  return
138
147
  }
139
148
  clearInterval(interval)
149
+ clearTimeout(heartbeatTimeout)
140
150
  process.removeListener('beforeExit', onBeforeExit)
141
151
 
142
152
  telemetryStopChannel.publish(getTelemetryData())