dd-trace 0.36.2 → 0.36.6

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 (71) hide show
  1. package/LICENSE-3rdparty.csv +2 -2
  2. package/index.d.ts +10 -0
  3. package/package.json +4 -4
  4. package/packages/datadog-plugin-elasticsearch/src/index.js +23 -26
  5. package/packages/datadog-plugin-fastify/src/fastify.js +53 -0
  6. package/packages/datadog-plugin-graphql/src/index.js +6 -6
  7. package/packages/datadog-plugin-grpc/src/client.js +1 -1
  8. package/packages/datadog-plugin-jest/src/index.js +20 -7
  9. package/packages/datadog-plugin-mocha/src/index.js +7 -2
  10. package/packages/datadog-plugin-next/src/index.js +70 -8
  11. package/packages/dd-trace/lib/version.js +1 -1
  12. package/packages/dd-trace/src/dogstatsd.js +15 -6
  13. package/packages/dd-trace/src/histogram.js +4 -10
  14. package/packages/dd-trace/src/plugins/util/web.js +1 -0
  15. package/packages/dd-trace/src/proxy.js +9 -2
  16. package/prebuilds/darwin-ia32/node-57.node +0 -0
  17. package/prebuilds/darwin-ia32/node-59.node +0 -0
  18. package/prebuilds/darwin-ia32/node-64.node +0 -0
  19. package/prebuilds/darwin-ia32/node-67.node +0 -0
  20. package/prebuilds/darwin-ia32/node-72.node +0 -0
  21. package/prebuilds/darwin-ia32/node-79.node +0 -0
  22. package/prebuilds/darwin-ia32/node-83.node +0 -0
  23. package/prebuilds/darwin-ia32/node-88.node +0 -0
  24. package/prebuilds/darwin-ia32/node-93.node +0 -0
  25. package/prebuilds/darwin-x64/node-57.node +0 -0
  26. package/prebuilds/darwin-x64/node-59.node +0 -0
  27. package/prebuilds/darwin-x64/node-64.node +0 -0
  28. package/prebuilds/darwin-x64/node-67.node +0 -0
  29. package/prebuilds/darwin-x64/node-72.node +0 -0
  30. package/prebuilds/darwin-x64/node-79.node +0 -0
  31. package/prebuilds/darwin-x64/node-83.node +0 -0
  32. package/prebuilds/darwin-x64/node-88.node +0 -0
  33. package/prebuilds/darwin-x64/node-93.node +0 -0
  34. package/prebuilds/linux-ia32/node-57.node +0 -0
  35. package/prebuilds/linux-ia32/node-59.node +0 -0
  36. package/prebuilds/linux-ia32/node-64.node +0 -0
  37. package/prebuilds/linux-ia32/node-67.node +0 -0
  38. package/prebuilds/linux-ia32/node-72.node +0 -0
  39. package/prebuilds/linux-ia32/node-79.node +0 -0
  40. package/prebuilds/linux-x64/node-57.node +0 -0
  41. package/prebuilds/linux-x64/node-59.node +0 -0
  42. package/prebuilds/linux-x64/node-64.node +0 -0
  43. package/prebuilds/linux-x64/node-67.node +0 -0
  44. package/prebuilds/linux-x64/node-72.node +0 -0
  45. package/prebuilds/linux-x64/node-79.node +0 -0
  46. package/prebuilds/linux-x64/node-83.node +0 -0
  47. package/prebuilds/linux-x64/node-88.node +0 -0
  48. package/prebuilds/linux-x64/node-93.node +0 -0
  49. package/prebuilds/win32-ia32/node-57.node +0 -0
  50. package/prebuilds/win32-ia32/node-59.node +0 -0
  51. package/prebuilds/win32-ia32/node-64.node +0 -0
  52. package/prebuilds/win32-ia32/node-67.node +0 -0
  53. package/prebuilds/win32-ia32/node-72.node +0 -0
  54. package/prebuilds/win32-ia32/node-79.node +0 -0
  55. package/prebuilds/win32-ia32/node-83.node +0 -0
  56. package/prebuilds/win32-ia32/node-88.node +0 -0
  57. package/prebuilds/win32-ia32/node-93.node +0 -0
  58. package/prebuilds/win32-x64/node-57.node +0 -0
  59. package/prebuilds/win32-x64/node-59.node +0 -0
  60. package/prebuilds/win32-x64/node-64.node +0 -0
  61. package/prebuilds/win32-x64/node-67.node +0 -0
  62. package/prebuilds/win32-x64/node-72.node +0 -0
  63. package/prebuilds/win32-x64/node-79.node +0 -0
  64. package/prebuilds/win32-x64/node-83.node +0 -0
  65. package/prebuilds/win32-x64/node-88.node +0 -0
  66. package/prebuilds/win32-x64/node-93.node +0 -0
  67. package/scripts/prebuilds.js +2 -2
  68. package/scripts/prepublish.js +1 -1
  69. package/scripts/version.js +2 -2
  70. package/NOTICE +0 -4
  71. package/packages/dd-trace/src/.DS_Store +0 -0
@@ -1,7 +1,7 @@
1
1
  Component,Origin,License,Copyright
2
+ require,@datadog/sketches-js,Apache license 2.0,Copyright 2020 Datadog Inc.
2
3
  require,@types/node,MIT,Copyright Authors
3
4
  require,form-data,MIT,Copyright 2012 Felix Geisendörfer and contributors
4
- require,hdr-histogram-js,BSD-2-Clause,Copyright 2016 Alexandre Victoor
5
5
  require,koalas,MIT,Copyright 2013-2017 Brian Woodward
6
6
  require,limiter,MIT,Copyright 2011 John Hurliman
7
7
  require,lodash.kebabcase,MIT,Copyright JS Foundation and other contributors
@@ -10,7 +10,6 @@ require,lodash.sortby,MIT,Copyright JS Foundation and other contributors
10
10
  require,lodash.uniq,MIT,Copyright JS Foundation and other contributors
11
11
  require,methods,MIT,Copyright 2013-2014 TJ Holowaychuk
12
12
  require,module-details-from-path,MIT,Copyright 2016 Thomas Watson Steen
13
- require,multer,MIT,Copyright 2014 Hage Yaapa
14
13
  require,nan,MIT,Copyright 2018 NAN contributors
15
14
  require,node-gyp-build,MIT,Copyright 2017 Mathias Buus
16
15
  require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
@@ -47,6 +46,7 @@ dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
47
46
  dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
48
47
  dev,mkdirp,MIT,Copyright 2010 James Halliday
49
48
  dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
49
+ dev,multer,MIT,Copyright 2014 Hage Yaapa
50
50
  dev,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
51
51
  dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
52
52
  dev,nyc,ISC,Copyright 2015 Contributors
package/index.d.ts CHANGED
@@ -886,6 +886,16 @@ declare namespace plugins {
886
886
  */
887
887
  depth?: number;
888
888
 
889
+ /**
890
+ * Whether to include the source of the operation within the query as a tag
891
+ * on every span. This may contain sensitive information and sould only be
892
+ * enabled if sensitive data is always sent as variables and not in the
893
+ * query text.
894
+ *
895
+ * @default false
896
+ */
897
+ source?: boolean;
898
+
889
899
  /**
890
900
  * An array of variable names to record. Can also be a callback that returns
891
901
  * the key/value pairs to record. For example, using
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "0.36.2",
3
+ "version": "0.36.6",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "bench:e2e": "SERVICES=mongo yarn services && cd benchmark/e2e && node benchmark-run.js --duration=30",
18
18
  "type:doc": "cd docs && yarn && yarn build",
19
19
  "type:test": "cd docs && yarn && yarn test",
20
- "lint": "node scripts/check_licenses.js && eslint .",
20
+ "lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
21
21
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
22
22
  "tdd": "node scripts/tdd.js",
23
23
  "test": "SERVICES=* yarn services && mocha --exit --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
@@ -55,9 +55,9 @@
55
55
  "node": ">=8"
56
56
  },
57
57
  "dependencies": {
58
+ "@datadog/sketches-js": "^1.0.4",
58
59
  "@types/node": "^10.12.18",
59
60
  "form-data": "^3.0.0",
60
- "hdr-histogram-js": "^2.0.1",
61
61
  "koalas": "^1.0.2",
62
62
  "limiter": "^1.1.4",
63
63
  "lodash.kebabcase": "^4.1.1",
@@ -66,7 +66,6 @@
66
66
  "lodash.uniq": "^4.5.0",
67
67
  "methods": "^1.1.2",
68
68
  "module-details-from-path": "^1.0.3",
69
- "multer": "^1.4.2",
70
69
  "nan": "^2.12.1",
71
70
  "node-gyp-build": "^3.8.0",
72
71
  "opentracing": ">=0.12.1",
@@ -105,6 +104,7 @@
105
104
  "mocha": "^5.2.0",
106
105
  "mocha-junit-reporter": "^2.0.0",
107
106
  "mocha-multi-reporters": "^1.5.1",
107
+ "multer": "^1.4.2",
108
108
  "msgpack-lite": "^0.1.26",
109
109
  "nock": "^11.3.3",
110
110
  "nyc": "^14.1.1",
@@ -9,6 +9,8 @@ function createWrapRequest (tracer, config) {
9
9
  return function requestWithTrace (params, options, cb) {
10
10
  if (!params) return request.apply(this, arguments)
11
11
 
12
+ const lastIndex = arguments.length - 1
13
+ const body = getBody(params.body || params.bulkBody)
12
14
  const childOf = tracer.scope().active()
13
15
  const span = tracer.startSpan('elasticsearch.query', {
14
16
  childOf,
@@ -20,48 +22,39 @@ function createWrapRequest (tracer, config) {
20
22
  'span.type': 'elasticsearch',
21
23
  'elasticsearch.url': params.path,
22
24
  'elasticsearch.method': params.method,
25
+ 'elasticsearch.body': body,
23
26
  'elasticsearch.params': JSON.stringify(params.querystring || params.query)
24
27
  }
25
28
  })
26
29
 
27
- if (params.body || params.bulkBody) {
28
- span.setTag('elasticsearch.body', JSON.stringify(params.body || params.bulkBody))
29
- }
30
-
31
30
  analyticsSampler.sample(span, config.analytics)
32
31
 
33
- cb = request.length === 2 || typeof options === 'function'
34
- ? tracer.scope().bind(options, childOf)
35
- : tracer.scope().bind(cb, childOf)
36
-
37
- return tracer.scope().activate(span, () => {
38
- if (typeof cb === 'function') {
39
- if (request.length === 2) {
40
- return request.call(this, params, wrapCallback(tracer, span, params, config, cb))
41
- } else {
42
- return request.call(this, params, options, wrapCallback(tracer, span, params, config, cb))
43
- }
44
- } else {
45
- const promise = request.apply(this, arguments)
32
+ cb = arguments[lastIndex]
46
33
 
47
- if (promise && typeof promise.then === 'function') {
48
- promise.then(() => finish(span, params, config), e => finish(span, params, config, e))
49
- } else {
50
- finish(span, params, config)
51
- }
34
+ if (typeof cb === 'function') {
35
+ arguments[lastIndex] = wrapCallback(tracer, span, params, config, cb)
52
36
 
53
- return promise
37
+ return tracer.scope().activate(span, () => request.apply(this, arguments))
38
+ } else {
39
+ const promise = request.apply(this, arguments)
40
+
41
+ if (promise && typeof promise.then === 'function') {
42
+ promise.then(() => finish(span, params, config), e => finish(span, params, config, e))
43
+ } else {
44
+ finish(span, params, config)
54
45
  }
55
- })
46
+
47
+ return promise
48
+ }
56
49
  }
57
50
  }
58
51
  }
59
52
 
60
53
  function wrapCallback (tracer, span, params, config, done) {
61
- return function (err) {
54
+ return tracer.scope().bind(function (err) {
62
55
  finish(span, params, config, err)
63
56
  done.apply(null, arguments)
64
- }
57
+ })
65
58
  }
66
59
 
67
60
  function finish (span, params, config, err) {
@@ -82,6 +75,10 @@ function quantizePath (path) {
82
75
  return path && path.replace(/[0-9]+/g, '?')
83
76
  }
84
77
 
78
+ function getBody (body) {
79
+ return body && JSON.stringify(body)
80
+ }
81
+
85
82
  function normalizeConfig (config) {
86
83
  const hooks = getHooks(config)
87
84
 
@@ -17,6 +17,7 @@ function createWrapFastify (tracer, config) {
17
17
  if (typeof app.addHook === 'function') {
18
18
  app.addHook('onRequest', createOnRequest(tracer, config))
19
19
  app.addHook('preHandler', preHandler)
20
+ app.addHook = createWrapAddHook(tracer, config)(app.addHook)
20
21
  }
21
22
 
22
23
  methods.forEach(method => {
@@ -30,6 +31,51 @@ function createWrapFastify (tracer, config) {
30
31
  }
31
32
  }
32
33
 
34
+ function createWrapAddHook (tracer, config) {
35
+ return function wrapAddHook (addHook) {
36
+ return function addHookWithTrace (name, fn) {
37
+ fn = arguments[arguments.length - 1]
38
+
39
+ if (typeof fn !== 'function') return addHook.apply(this, arguments)
40
+
41
+ arguments[arguments.length - 1] = safeWrap(fn, function (request, reply, done) {
42
+ const req = getReq(request)
43
+
44
+ if (!req) return fn.apply(this, arguments)
45
+
46
+ done = arguments[arguments.length - 1]
47
+
48
+ try {
49
+ if (typeof done === 'function') {
50
+ arguments[arguments.length - 1] = function (err) {
51
+ web.addError(req, err)
52
+ return done.apply(this, arguments)
53
+ }
54
+
55
+ return fn.apply(this, arguments)
56
+ } else {
57
+ const promise = fn.apply(this, arguments)
58
+
59
+ if (promise && typeof promise.catch === 'function') {
60
+ return promise.catch(err => {
61
+ web.addError(req, err)
62
+ throw err
63
+ })
64
+ }
65
+
66
+ return promise
67
+ }
68
+ } catch (e) {
69
+ web.addError(req, e)
70
+ throw e
71
+ }
72
+ })
73
+
74
+ return addHook.apply(this, arguments)
75
+ }
76
+ }
77
+ }
78
+
33
79
  function createOnRequest (tracer, config) {
34
80
  return function onRequest (request, reply, next) {
35
81
  if (typeof next !== 'function') return
@@ -101,6 +147,13 @@ function wrapHandler (handler) {
101
147
  }
102
148
  }
103
149
 
150
+ // TODO: move this to a common util
151
+ function safeWrap (fn, wrapper) {
152
+ Object.defineProperty(wrapper, 'length', Object.getOwnPropertyDescriptor(fn, 'length'))
153
+
154
+ return wrapper
155
+ }
156
+
104
157
  function getReq (request) {
105
158
  return request && (request.raw || request.req || request)
106
159
  }
@@ -60,7 +60,7 @@ function createWrapParse (tracer, config) {
60
60
  document._datadog_source = source.body || source
61
61
  }
62
62
 
63
- addDocumentTags(span, document)
63
+ addDocumentTags(span, document, config)
64
64
 
65
65
  return document
66
66
  } catch (e) {
@@ -82,7 +82,7 @@ function createWrapValidate (tracer, config) {
82
82
 
83
83
  // skip for schema stitching nested validation
84
84
  if (document && document.loc) {
85
- addDocumentTags(span, document)
85
+ addDocumentTags(span, document, config)
86
86
  }
87
87
 
88
88
  try {
@@ -228,7 +228,7 @@ function startExecutionSpan (tracer, config, operation, args) {
228
228
  const span = startSpan(tracer, config, 'execute')
229
229
 
230
230
  addExecutionTags(span, config, operation, args.document, args.operationName)
231
- addDocumentTags(span, args.document)
231
+ addDocumentTags(span, args.document, config)
232
232
  addVariableTags(tracer, config, span, args.variableValues)
233
233
 
234
234
  analyticsSampler.sample(span, config.analytics)
@@ -255,10 +255,10 @@ function addExecutionTags (span, config, operation, document, operationName) {
255
255
  span.addTags(tags)
256
256
  }
257
257
 
258
- function addDocumentTags (span, document) {
258
+ function addDocumentTags (span, document, config) {
259
259
  const tags = {}
260
260
 
261
- if (document && document._datadog_source) {
261
+ if (config.source && document && document._datadog_source) {
262
262
  tags['graphql.source'] = document._datadog_source
263
263
  }
264
264
 
@@ -304,7 +304,7 @@ function startResolveSpan (tracer, config, childOf, path, info, contextValue) {
304
304
  })
305
305
 
306
306
  if (fieldNode) {
307
- if (document && fieldNode.loc) {
307
+ if (config.source && document && fieldNode.loc) {
308
308
  span.setTag('graphql.source', document.substring(fieldNode.loc.start, fieldNode.loc.end))
309
309
  }
310
310
 
@@ -47,7 +47,7 @@ function createWrapMakeClientConstructor (tracer, config) {
47
47
  function wrapPackageDefinition (tracer, config, def) {
48
48
  for (const name in def) {
49
49
  if (def[name].format) continue
50
- if (def[name].service) {
50
+ if (def[name].service && def[name].prototype) {
51
51
  wrapClientConstructor(tracer, config, def[name], def[name].service)
52
52
  } else {
53
53
  wrapPackageDefinition(tracer, config, def[name])
@@ -19,6 +19,13 @@ const {
19
19
  } = require('../../dd-trace/src/plugins/util/test')
20
20
  const { getFormattedJestTestParameters } = require('./util')
21
21
 
22
+ function getVmContext (environment) {
23
+ if (typeof environment.getVmContext === 'function') {
24
+ return environment.getVmContext()
25
+ }
26
+ return null
27
+ }
28
+
22
29
  function wrapEnvironment (BaseEnvironment) {
23
30
  return class DatadogJestEnvironment extends BaseEnvironment {
24
31
  constructor (config, context) {
@@ -54,11 +61,15 @@ const isTimeout = (event) => {
54
61
  function createHandleTestEvent (tracer, testEnvironmentMetadata, instrumenter) {
55
62
  return async function handleTestEventWithTrace (event) {
56
63
  if (event.name === 'test_retry') {
57
- const context = this.getVmContext()
58
- const { currentTestName } = context.expect.getState()
64
+ let testName = event.test && event.test.name
65
+ const context = getVmContext(this)
66
+ if (context) {
67
+ const { currentTestName } = context.expect.getState()
68
+ testName = currentTestName
69
+ }
59
70
  // If it's a retry, we restore the original test function so that it is not wrapped again
60
- if (this.originalTestFnByTestName[currentTestName]) {
61
- event.test.fn = this.originalTestFnByTestName[currentTestName]
71
+ if (this.originalTestFnByTestName[testName]) {
72
+ event.test.fn = this.originalTestFnByTestName[testName]
62
73
  }
63
74
  return
64
75
  }
@@ -66,7 +77,7 @@ function createHandleTestEvent (tracer, testEnvironmentMetadata, instrumenter) {
66
77
  if (!isTimeout(event)) {
67
78
  return
68
79
  }
69
- const context = this.getVmContext()
80
+ const context = getVmContext(this)
70
81
  if (context) {
71
82
  const { currentTestName } = context.expect.getState()
72
83
  const testSpan = this.testSpansByTestName[`${currentTestName}_${event.test.invocations}`]
@@ -111,11 +122,13 @@ function createHandleTestEvent (tracer, testEnvironmentMetadata, instrumenter) {
111
122
  'x-datadog-sampled': 1
112
123
  })
113
124
  let testName = event.test.name
114
- const context = this.getVmContext()
125
+ const context = getVmContext(this)
126
+
115
127
  if (context) {
116
128
  const { currentTestName } = context.expect.getState()
117
129
  testName = currentTestName
118
130
  }
131
+
119
132
  const commonSpanTags = {
120
133
  [TEST_TYPE]: 'test',
121
134
  [TEST_NAME]: testName,
@@ -194,7 +207,7 @@ function createHandleTestEvent (tracer, testEnvironmentMetadata, instrumenter) {
194
207
  result = await specFunction()
195
208
  // it may have been set already if the test timed out
196
209
  let suppressedErrors = []
197
- const context = environment.getVmContext()
210
+ const context = getVmContext(environment)
198
211
  if (context) {
199
212
  suppressedErrors = context.expect.getState().suppressedErrors
200
213
  }
@@ -79,8 +79,13 @@ function createWrapRunTest (tracer, testEnvironmentMetadata, sourceRoot) {
79
79
  activeSpan.setTag(TEST_STATUS, 'fail')
80
80
  }
81
81
  } catch (error) {
82
- activeSpan.setTag(TEST_STATUS, 'fail')
83
- activeSpan.setTag('error', error)
82
+ // this.skip has been called
83
+ if (error.constructor.name === 'Pending' && !this.forbidPending) {
84
+ activeSpan.setTag(TEST_STATUS, 'skip')
85
+ } else {
86
+ activeSpan.setTag(TEST_STATUS, 'fail')
87
+ activeSpan.setTag('error', error)
88
+ }
84
89
  throw error
85
90
  } finally {
86
91
  finishAllTraceSpans(activeSpan)
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ // TODO: either instrument all or none of the render functions
4
+
3
5
  function createWrapHandleRequest (tracer, config) {
4
6
  return function wrapHandleRequest (handleRequest) {
5
7
  return function handleRequestWithTrace (req, res, pathname, query) {
@@ -28,6 +30,22 @@ function createWrapHandleApiRequest (tracer, config) {
28
30
  }
29
31
  }
30
32
 
33
+ function createWrapRenderToResponse (tracer, config) {
34
+ return function wrapRenderToResponse (renderToResponse) {
35
+ return function renderToResponseWithTrace (ctx) {
36
+ return trace(tracer, config, ctx.req, ctx.res, () => renderToResponse.apply(this, arguments))
37
+ }
38
+ }
39
+ }
40
+
41
+ function createWrapRenderErrorToResponse (tracer, config) {
42
+ return function wrapRenderErrorToResponse (renderErrorToResponse) {
43
+ return function renderErrorToResponseWithTrace (ctx) {
44
+ return trace(tracer, config, ctx.req, ctx.res, () => renderErrorToResponse.apply(this, arguments))
45
+ }
46
+ }
47
+ }
48
+
31
49
  function createWrapRenderToHTML (tracer, config) {
32
50
  return function wrapRenderToHTML (renderToHTML) {
33
51
  return function renderToHTMLWithTrace (req, res, pathname, query, parsedUrl) {
@@ -36,12 +54,26 @@ function createWrapRenderToHTML (tracer, config) {
36
54
  }
37
55
  }
38
56
 
39
- function createWrapRenderToHTMLWithComponents (tracer, config) {
40
- return function wrapHandleRenderToHTMLWithComponents (renderToHTMLWithComponents) {
41
- return function renderToHTMLWithComponentsWithTrace (req, res, page) {
42
- addPage(req, page)
57
+ function createWrapRenderErrorToHTML (tracer, config) {
58
+ return function wrapRenderErrorToHTML (renderErrorToHTML) {
59
+ return function renderErrorToHTMLWithTrace (err, req, res, pathname, query) {
60
+ return trace(tracer, config, req, res, () => renderErrorToHTML.apply(this, arguments))
61
+ }
62
+ }
63
+ }
43
64
 
44
- return renderToHTMLWithComponents.apply(this, arguments)
65
+ function createWrapFindPageComponents (tracer, config) {
66
+ return function wrapFindPageComponents (findPageComponents) {
67
+ return function findPageComponentsWithTrace (pathname, query) {
68
+ const result = findPageComponents.apply(this, arguments)
69
+ const span = tracer.scope().active()
70
+ const req = span && span._nextReq
71
+
72
+ if (result) {
73
+ addPage(req, pathname)
74
+ }
75
+
76
+ return result
45
77
  }
46
78
  }
47
79
  }
@@ -75,6 +107,10 @@ function trace (tracer, config, req, res, handler) {
75
107
 
76
108
  const promise = scope.activate(span, handler)
77
109
 
110
+ // HACK: Store the request object on the span for findPageComponents.
111
+ // TODO: Use CLS when it will be available in core.
112
+ span._nextReq = req
113
+
78
114
  promise.then(() => finish(span, config, req, res), err => {
79
115
  span.setTag('error', err)
80
116
  finish(span, config, req, res)
@@ -84,6 +120,8 @@ function trace (tracer, config, req, res, handler) {
84
120
  }
85
121
 
86
122
  function addPage (req, page) {
123
+ if (!req || !req._datadog_next) return
124
+
87
125
  req._datadog_next.span.addTags({
88
126
  'resource.name': `${req.method} ${page}`.trim(),
89
127
  'next.page': page
@@ -114,7 +152,7 @@ function getHooks (config) {
114
152
  module.exports = [
115
153
  {
116
154
  name: 'next',
117
- versions: ['>=9.5'],
155
+ versions: ['>=9.5 <11.1'],
118
156
  file: 'dist/next-server/server/next-server.js',
119
157
  patch ({ default: Server }, tracer, config) {
120
158
  config = normalizeConfig(config)
@@ -122,13 +160,37 @@ module.exports = [
122
160
  this.wrap(Server.prototype, 'handleRequest', createWrapHandleRequest(tracer, config))
123
161
  this.wrap(Server.prototype, 'handleApiRequest', createWrapHandleApiRequest(tracer, config))
124
162
  this.wrap(Server.prototype, 'renderToHTML', createWrapRenderToHTML(tracer, config))
125
- this.wrap(Server.prototype, 'renderToHTMLWithComponents', createWrapRenderToHTMLWithComponents(tracer, config))
163
+ this.wrap(Server.prototype, 'renderErrorToHTML', createWrapRenderErrorToHTML(tracer, config))
164
+ this.wrap(Server.prototype, 'findPageComponents', createWrapFindPageComponents(tracer, config))
126
165
  },
127
166
  unpatch ({ default: Server }) {
128
167
  this.unwrap(Server.prototype, 'handleRequest')
129
168
  this.unwrap(Server.prototype, 'handleApiRequest')
130
169
  this.unwrap(Server.prototype, 'renderToHTML')
131
- this.unwrap(Server.prototype, 'renderToHTMLWithComponents')
170
+ this.unwrap(Server.prototype, 'renderErrorToHTML')
171
+ this.unwrap(Server.prototype, 'findPageComponents')
172
+ }
173
+ },
174
+
175
+ {
176
+ name: 'next',
177
+ versions: ['>=11.1'],
178
+ file: 'dist/server/next-server.js',
179
+ patch ({ default: Server }, tracer, config) {
180
+ config = normalizeConfig(config)
181
+
182
+ this.wrap(Server.prototype, 'handleRequest', createWrapHandleRequest(tracer, config))
183
+ this.wrap(Server.prototype, 'handleApiRequest', createWrapHandleApiRequest(tracer, config))
184
+ this.wrap(Server.prototype, 'renderToResponse', createWrapRenderToResponse(tracer, config))
185
+ this.wrap(Server.prototype, 'renderErrorToResponse', createWrapRenderErrorToResponse(tracer, config))
186
+ this.wrap(Server.prototype, 'findPageComponents', createWrapFindPageComponents(tracer, config))
187
+ },
188
+ unpatch ({ default: Server }) {
189
+ this.unwrap(Server.prototype, 'handleRequest')
190
+ this.unwrap(Server.prototype, 'handleApiRequest')
191
+ this.unwrap(Server.prototype, 'renderToResponse')
192
+ this.unwrap(Server.prototype, 'renderErrorToResponse')
193
+ this.unwrap(Server.prototype, 'findPageComponents')
132
194
  }
133
195
  }
134
196
  ]
@@ -1 +1 @@
1
- module.exports = '0.36.2'
1
+ module.exports = '0.36.6'
@@ -1,7 +1,8 @@
1
1
  'use strict'
2
2
 
3
- const dgram = require('dgram')
4
3
  const lookup = require('dns').lookup // cache to avoid instrumentation
4
+ const dgram = require('dgram')
5
+ const isIP = require('net').isIP
5
6
  const log = require('./log')
6
7
 
7
8
  const MAX_BUFFER_SIZE = 1024 // limit from the agent
@@ -11,6 +12,7 @@ class Client {
11
12
  options = options || {}
12
13
 
13
14
  this._host = options.host || 'localhost'
15
+ this._family = isIP(this._host)
14
16
  this._port = options.port || 8125
15
17
  this._prefix = options.prefix || ''
16
18
  this._tags = options.tags || []
@@ -36,11 +38,14 @@ class Client {
36
38
 
37
39
  this._queue = []
38
40
 
39
- lookup(this._host, (err, address, family) => {
40
- if (err) return log.error(err)
41
-
42
- queue.forEach(buffer => this._send(address, family, buffer))
43
- })
41
+ if (this._family !== 0) {
42
+ this._sendAll(queue, this._host, this._family)
43
+ } else {
44
+ lookup(this._host, (err, address, family) => {
45
+ if (err) return log.error(err)
46
+ this._sendAll(queue, address, family)
47
+ })
48
+ }
44
49
  }
45
50
 
46
51
  _send (address, family, buffer) {
@@ -51,6 +56,10 @@ class Client {
51
56
  socket.send(buffer, 0, buffer.length, this._port, address)
52
57
  }
53
58
 
59
+ _sendAll (queue, address, family) {
60
+ queue.forEach((buffer) => this._send(address, family, buffer))
61
+ }
62
+
54
63
  _add (stat, value, type, tags) {
55
64
  const message = `${this._prefix + stat}:${value}|${type}`
56
65
 
@@ -1,15 +1,9 @@
1
1
  'use strict'
2
2
 
3
- const hdr = require('hdr-histogram-js')
4
-
5
- const highestTrackableValue = 3.6e12 // 1 hour
3
+ const { DDSketch } = require('@datadog/sketches-js')
6
4
 
7
5
  class Histogram {
8
6
  constructor () {
9
- this._histogram = hdr.build({
10
- highestTrackableValue
11
- })
12
-
13
7
  this.reset()
14
8
  }
15
9
 
@@ -22,7 +16,7 @@ class Histogram {
22
16
  get p95 () { return this.percentile(95) }
23
17
 
24
18
  percentile (percentile) {
25
- return this._histogram.getValueAtPercentile(percentile)
19
+ return this._histogram.getValueAtQuantile(percentile / 100) || 0
26
20
  }
27
21
 
28
22
  record (value) {
@@ -36,7 +30,7 @@ class Histogram {
36
30
  this._count++
37
31
  this._sum += value
38
32
 
39
- this._histogram.recordValue(value)
33
+ this._histogram.accept(value)
40
34
  }
41
35
 
42
36
  reset () {
@@ -45,7 +39,7 @@ class Histogram {
45
39
  this._sum = 0
46
40
  this._count = 0
47
41
 
48
- this._histogram.reset()
42
+ this._histogram = new DDSketch()
49
43
  }
50
44
  }
51
45
 
@@ -302,6 +302,7 @@ function addAllowHeaders (req, headers) {
302
302
  const allowHeaders = splitHeader(headers['access-control-allow-headers'])
303
303
  const requestHeaders = splitHeader(req.headers['access-control-request-headers'])
304
304
  const contextHeaders = [
305
+ 'x-datadog-origin',
305
306
  'x-datadog-parent-id',
306
307
  'x-datadog-sampled',
307
308
  'x-datadog-sampling-priority',
@@ -6,7 +6,6 @@ const DatadogTracer = require('./tracer')
6
6
  const Config = require('./config')
7
7
  const Instrumenter = require('./instrumenter')
8
8
  const metrics = require('./metrics')
9
- const profiler = require('./profiler')
10
9
  const log = require('./log')
11
10
  const { setStartupLogInstrumenter } = require('./startup-log')
12
11
  const analyticsSampler = require('./analytics_sampler')
@@ -33,7 +32,15 @@ class Tracer extends BaseTracer {
33
32
  log.use(config.logger)
34
33
  log.toggle(config.debug, config.logLevel, this)
35
34
 
36
- profiler.start(config)
35
+ if (config.hasOwnProperty('profiling') && config.profiling.enabled) {
36
+ // do not stop tracer initialization if the profiler fails to be imported
37
+ try {
38
+ const profiler = require('./profiler')
39
+ profiler.start(config)
40
+ } catch (e) {
41
+ log.error(e)
42
+ }
43
+ }
37
44
 
38
45
  if (config.enabled) {
39
46
  if (config.runtimeMetrics) {
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -50,7 +50,7 @@ function validatePrebuilds () {
50
50
  const content = fs.readFileSync(path.join('prebuilds', platform, file))
51
51
  const sum = fs.readFileSync(path.join('prebuilds', platform, `${file}.sha1`), 'ascii')
52
52
 
53
- if (sum !== checksum(content)) {
53
+ if (sum !== checksum(content, { algorithm: 'sha256' })) {
54
54
  throw new Error(`Invalid checksum for "prebuilds/${platform}/${file}".`)
55
55
  }
56
56
  })
@@ -62,7 +62,7 @@ function validatePrebuilds () {
62
62
 
63
63
  function createChecksum () {
64
64
  const file = path.join(os.tmpdir(), 'prebuilds.tgz')
65
- const sum = checksum(fs.readFileSync(file))
65
+ const sum = checksum(fs.readFileSync(file), { algorithm: 'sha256' })
66
66
 
67
67
  fs.writeFileSync(`${file}.sha1`, sum)
68
68
  }
@@ -145,7 +145,7 @@ function validatePrebuilds () {
145
145
  const content = fs.readFileSync(file)
146
146
  const sum = fs.readFileSync(path.join(`${file}.sha1`), 'ascii')
147
147
 
148
- if (sum !== checksum(content)) {
148
+ if (sum !== checksum(content, { algorithm: 'sha256' })) {
149
149
  throw new Error('Invalid checksum for "prebuilds.tgz".')
150
150
  }
151
151
  }
@@ -33,12 +33,12 @@ exec(`git checkout ${currentBranch}`)
33
33
  function bump (newVersion) {
34
34
  pkg.version = newVersion
35
35
 
36
- exec(`git checkout -b v${newVersion}`)
36
+ exec(`git checkout -b v${newVersion}-bump`)
37
37
  write('package.json', JSON.stringify(pkg, null, 2) + '\n')
38
38
  write('packages/dd-trace/lib/version.js', `module.exports = '${newVersion}'\n`)
39
39
  add('package.json')
40
40
  add('packages/dd-trace/lib/version.js')
41
- exec(`git commit -m v"${newVersion}"`)
41
+ exec(`git commit -m "v${newVersion}"`)
42
42
  exec(`git push -u origin HEAD`)
43
43
  }
44
44
 
package/NOTICE DELETED
@@ -1,4 +0,0 @@
1
- Datadog dd-trace-js
2
- Copyright 2016-Present Datadog, Inc.
3
-
4
- This product includes software developed at Datadog, Inc. (https://www.datadoghq.com/).
Binary file