dd-trace 4.1.0 → 4.1.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.
@@ -51,6 +51,7 @@ dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors
51
51
  dev,graphql,MIT,Copyright 2015 Facebook Inc.
52
52
  dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
53
53
  dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
54
+ dev,knex,MIT,Copyright (c) 2013-present Tim Griesser
54
55
  dev,mkdirp,MIT,Copyright 2010 James Halliday
55
56
  dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
56
57
  dev,multer,MIT,Copyright 2014 Hage Yaapa
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -120,6 +120,7 @@
120
120
  "graphql": "0.13.2",
121
121
  "int64-buffer": "^0.1.9",
122
122
  "jszip": "^3.5.0",
123
+ "knex": "^2.4.2",
123
124
  "mkdirp": "^0.5.1",
124
125
  "mocha": "8",
125
126
  "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) {
@@ -216,8 +216,11 @@ class Config {
216
216
  process.env.DD_TRACE_TELEMETRY_ENABLED,
217
217
  !inServerlessEnvironment
218
218
  )
219
- const DD_TELEMETRY_DEBUG_ENABLED = coalesce(
220
- process.env.DD_TELEMETRY_DEBUG_ENABLED,
219
+ const DD_TELEMETRY_HEARTBEAT_INTERVAL = process.env.DD_TELEMETRY_HEARTBEAT_INTERVAL
220
+ ? parseInt(process.env.DD_TELEMETRY_HEARTBEAT_INTERVAL) * 1000
221
+ : 60000
222
+ const DD_TELEMETRY_DEBUG = coalesce(
223
+ process.env.DD_TELEMETRY_DEBUG,
221
224
  false
222
225
  )
223
226
  const DD_TRACE_AGENT_PROTOCOL_VERSION = coalesce(
@@ -513,8 +516,9 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
513
516
  // Disabled for CI Visibility's agentless
514
517
  this.telemetry = {
515
518
  enabled: DD_TRACE_EXPORTER !== 'datadog' && isTrue(DD_TRACE_TELEMETRY_ENABLED),
519
+ heartbeatInterval: DD_TELEMETRY_HEARTBEAT_INTERVAL,
516
520
  logCollection: isTrue(DD_TELEMETRY_LOG_COLLECTION_ENABLED),
517
- debug: isTrue(DD_TELEMETRY_DEBUG_ENABLED)
521
+ debug: isTrue(DD_TELEMETRY_DEBUG)
518
522
  }
519
523
  this.protocolVersion = DD_TRACE_AGENT_PROTOCOL_VERSION
520
524
  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',