dd-trace 2.35.0 → 2.35.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.
@@ -50,6 +50,7 @@ dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors
50
50
  dev,graphql,MIT,Copyright 2015 Facebook Inc.
51
51
  dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
52
52
  dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
53
+ dev,knex,MIT,Copyright (c) 2013-present Tim Griesser
53
54
  dev,mkdirp,MIT,Copyright 2010 James Halliday
54
55
  dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
55
56
  dev,multer,MIT,Copyright 2014 Hage Yaapa
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "2.35.0",
3
+ "version": "2.35.1",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -119,6 +119,7 @@
119
119
  "graphql": "0.13.2",
120
120
  "int64-buffer": "^0.1.9",
121
121
  "jszip": "^3.5.0",
122
+ "knex": "^2.4.2",
122
123
  "mkdirp": "^0.5.1",
123
124
  "mocha": "8",
124
125
  "msgpack-lite": "^0.1.26",
@@ -39,7 +39,19 @@ module.exports.setup = function (build) {
39
39
 
40
40
  if (args.namespace === 'file' && packagesOfInterest.has(packageName)) {
41
41
  // The file namespace is used when requiring files from disk in userland
42
- const pathToPackageJson = require.resolve(`${packageName}/package.json`, { paths: [ args.resolveDir ] })
42
+
43
+ let pathToPackageJson
44
+ try {
45
+ pathToPackageJson = require.resolve(`${packageName}/package.json`, { paths: [ args.resolveDir ] })
46
+ } catch (err) {
47
+ if (err.code === 'MODULE_NOT_FOUND') {
48
+ console.warn(`Unable to open "${packageName}/package.json". Is the "${packageName}" package dead code?`)
49
+ return
50
+ } else {
51
+ throw err
52
+ }
53
+ }
54
+
43
55
  const pkg = require(pathToPackageJson)
44
56
 
45
57
  if (DEBUG) {
@@ -31,16 +31,19 @@ function wrapQuery (query) {
31
31
  const asyncResource = new AsyncResource('bound-anonymous-fn')
32
32
  const processId = this.processID
33
33
 
34
- let pgQuery = arguments[0] && typeof arguments[0] === 'object' ? arguments[0] : { text: arguments[0] }
34
+ const pgQuery = arguments[0] && typeof arguments[0] === 'object' ? arguments[0] : { text: arguments[0] }
35
+
36
+ // shallow clone the existing query to swap out .text field
37
+ let newQuery = { ...pgQuery }
35
38
 
36
39
  return asyncResource.runInAsyncScope(() => {
37
40
  startCh.publish({
38
41
  params: this.connectionParameters,
39
- query: pgQuery,
42
+ query: newQuery,
40
43
  processId
41
44
  })
42
45
 
43
- arguments[0] = pgQuery
46
+ arguments[0] = newQuery
44
47
 
45
48
  const finish = asyncResource.bind(function (error) {
46
49
  if (error) {
@@ -53,24 +56,24 @@ function wrapQuery (query) {
53
56
  const queryQueue = this.queryQueue || this._queryQueue
54
57
  const activeQuery = this.activeQuery || this._activeQuery
55
58
 
56
- pgQuery = queryQueue[queryQueue.length - 1] || activeQuery
59
+ newQuery = queryQueue[queryQueue.length - 1] || activeQuery
57
60
 
58
- if (!pgQuery) {
61
+ if (!newQuery) {
59
62
  return retval
60
63
  }
61
64
 
62
- if (pgQuery.callback) {
63
- const originalCallback = callbackResource.bind(pgQuery.callback)
64
- pgQuery.callback = function (err, res) {
65
+ if (newQuery.callback) {
66
+ const originalCallback = callbackResource.bind(newQuery.callback)
67
+ newQuery.callback = function (err, res) {
65
68
  finish(err)
66
69
  return originalCallback.apply(this, arguments)
67
70
  }
68
- } else if (pgQuery.once) {
69
- pgQuery
71
+ } else if (newQuery.once) {
72
+ newQuery
70
73
  .once('error', finish)
71
74
  .once('end', () => finish())
72
75
  } else {
73
- pgQuery.then(() => finish(), finish)
76
+ newQuery.then(() => finish(), finish)
74
77
  }
75
78
 
76
79
  try {
@@ -130,7 +130,7 @@ class RouterPlugin extends WebPlugin {
130
130
  route = context.stack.join('')
131
131
 
132
132
  // Longer route is more likely to be the actual route handler route.
133
- if (route.length > context.route.length) {
133
+ if (isMoreSpecificThan(route, context.route)) {
134
134
  context.route = route
135
135
  }
136
136
  } else {
@@ -148,4 +148,15 @@ class RouterPlugin extends WebPlugin {
148
148
  }
149
149
  }
150
150
 
151
+ function isMoreSpecificThan (routeA, routeB) {
152
+ if (!routeIsRegex(routeA) && routeIsRegex(routeB)) {
153
+ return true
154
+ }
155
+ return routeA.length > routeB.length
156
+ }
157
+
158
+ function routeIsRegex (route) {
159
+ return route.includes('(/') && route.includes('/)')
160
+ }
161
+
151
162
  module.exports = RouterPlugin
@@ -28,7 +28,7 @@ function sendLogs () {
28
28
  }
29
29
 
30
30
  function isLevelEnabled (level) {
31
- return isLogCollectionEnabled(config) && (level !== 'DEBUG' || config.telemetry.debug)
31
+ return isLogCollectionEnabled(config) && level !== 'DEBUG'
32
32
  }
33
33
 
34
34
  function isLogCollectionEnabled (config) {
@@ -213,8 +213,11 @@ class Config {
213
213
  process.env.DD_TRACE_TELEMETRY_ENABLED,
214
214
  !inServerlessEnvironment
215
215
  )
216
- const DD_TELEMETRY_DEBUG_ENABLED = coalesce(
217
- process.env.DD_TELEMETRY_DEBUG_ENABLED,
216
+ const DD_TELEMETRY_HEARTBEAT_INTERVAL = process.env.DD_TELEMETRY_HEARTBEAT_INTERVAL
217
+ ? parseInt(process.env.DD_TELEMETRY_HEARTBEAT_INTERVAL) * 1000
218
+ : 60000
219
+ const DD_TELEMETRY_DEBUG = coalesce(
220
+ process.env.DD_TELEMETRY_DEBUG,
218
221
  false
219
222
  )
220
223
  const DD_TRACE_AGENT_PROTOCOL_VERSION = coalesce(
@@ -510,8 +513,9 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
510
513
  // Disabled for CI Visibility's agentless
511
514
  this.telemetry = {
512
515
  enabled: DD_TRACE_EXPORTER !== 'datadog' && isTrue(DD_TRACE_TELEMETRY_ENABLED),
516
+ heartbeatInterval: DD_TELEMETRY_HEARTBEAT_INTERVAL,
513
517
  logCollection: isTrue(DD_TELEMETRY_LOG_COLLECTION_ENABLED),
514
- debug: isTrue(DD_TELEMETRY_DEBUG_ENABLED)
518
+ debug: isTrue(DD_TELEMETRY_DEBUG)
515
519
  }
516
520
  this.protocolVersion = DD_TRACE_AGENT_PROTOCOL_VERSION
517
521
  this.tagsHeaderMaxLength = parseInt(DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH)
@@ -6,10 +6,6 @@ const os = require('os')
6
6
  const dependencies = require('./dependencies')
7
7
  const { sendData } = require('./send-data')
8
8
 
9
- const HEARTBEAT_INTERVAL = process.env.DD_TELEMETRY_HEARTBEAT_INTERVAL
10
- ? Number(process.env.DD_TELEMETRY_HEARTBEAT_INTERVAL) * 1000
11
- : 60000
12
-
13
9
  const telemetryStartChannel = dc.channel('datadog:telemetry:start')
14
10
  const telemetryStopChannel = dc.channel('datadog:telemetry:stop')
15
11
 
@@ -19,6 +15,7 @@ let pluginManager
19
15
  let application
20
16
  let host
21
17
  let interval
18
+ let heartbeatInterval
22
19
  const sentIntegrations = new Set()
23
20
 
24
21
  function getIntegrations () {
@@ -108,7 +105,7 @@ function createHostObject () {
108
105
  }
109
106
 
110
107
  function getTelemetryData () {
111
- return { config, application, host, heartbeatInterval: HEARTBEAT_INTERVAL }
108
+ return { config, application, host, heartbeatInterval }
112
109
  }
113
110
 
114
111
  function start (aConfig, thePluginManager) {
@@ -119,11 +116,13 @@ function start (aConfig, thePluginManager) {
119
116
  pluginManager = thePluginManager
120
117
  application = createAppObject()
121
118
  host = createHostObject()
119
+ heartbeatInterval = config.telemetry.heartbeatInterval
120
+
122
121
  dependencies.start(config, application, host)
123
122
  sendData(config, application, host, 'app-started', appStarted())
124
123
  interval = setInterval(() => {
125
124
  sendData(config, application, host, 'app-heartbeat')
126
- }, HEARTBEAT_INTERVAL)
125
+ }, heartbeatInterval)
127
126
  interval.unref()
128
127
  process.on('beforeExit', onBeforeExit)
129
128
 
@@ -1,4 +1,20 @@
1
1
  const request = require('../exporters/common/request')
2
+
3
+ function getHeaders (config, application, reqType) {
4
+ const headers = {
5
+ 'content-type': 'application/json',
6
+ 'dd-telemetry-api-version': 'v1',
7
+ 'dd-telemetry-request-type': reqType,
8
+ 'dd-client-library-language': application.language_name,
9
+ 'dd-client-library-version': application.tracer_version
10
+ }
11
+ const debug = config.telemetry && config.telemetry.debug
12
+ if (debug) {
13
+ headers['dd-telemetry-debug-enabled'] = 'true'
14
+ }
15
+ return headers
16
+ }
17
+
2
18
  let seqId = 0
3
19
 
4
20
  function getPayload (payload) {
@@ -25,11 +41,7 @@ function sendData (config, application, host, reqType, payload = {}) {
25
41
  port,
26
42
  method: 'POST',
27
43
  path: '/telemetry/proxy/api/v2/apmtelemetry',
28
- headers: {
29
- 'content-type': 'application/json',
30
- 'dd-telemetry-api-version': 'v1',
31
- 'dd-telemetry-request-type': reqType
32
- }
44
+ headers: getHeaders(config, application, reqType)
33
45
  }
34
46
  const data = JSON.stringify({
35
47
  api_version: 'v1',