dd-trace 3.13.0 → 4.0.0-pre-e22d438

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": "3.13.0",
3
+ "version": "4.0.0-pre-e22d438",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -85,36 +85,37 @@ const paramsByFileHandleMethods = {
85
85
  writeFile: ['data', 'options'],
86
86
  writev: ['buffers', 'position']
87
87
  }
88
+ const names = ['fs', 'node:fs']
89
+ names.forEach(name => {
90
+ addHook({ name }, fs => {
91
+ const asyncMethods = Object.keys(paramsByMethod)
92
+ const syncMethods = asyncMethods.map(name => `${name}Sync`)
93
+
94
+ massWrap(fs, asyncMethods, createWrapFunction())
95
+ massWrap(fs, syncMethods, createWrapFunction())
96
+ massWrap(fs.promises, asyncMethods, createWrapFunction('promises.'))
97
+
98
+ wrap(fs.realpath, 'native', createWrapFunction('', 'realpath.native'))
99
+ wrap(fs.realpathSync, 'native', createWrapFunction('', 'realpath.native'))
100
+ wrap(fs.promises.realpath, 'native', createWrapFunction('', 'realpath.native'))
101
+
102
+ wrap(fs, 'createReadStream', wrapCreateStream)
103
+ wrap(fs, 'createWriteStream', wrapCreateStream)
104
+ if (fs.Dir) {
105
+ wrap(fs.Dir.prototype, 'close', createWrapFunction('dir.'))
106
+ wrap(fs.Dir.prototype, 'closeSync', createWrapFunction('dir.'))
107
+ wrap(fs.Dir.prototype, 'read', createWrapFunction('dir.'))
108
+ wrap(fs.Dir.prototype, 'readSync', createWrapFunction('dir.'))
109
+ wrap(fs.Dir.prototype, Symbol.asyncIterator, createWrapDirAsyncIterator())
110
+ }
88
111
 
89
- addHook({ name: 'fs' }, fs => {
90
- const asyncMethods = Object.keys(paramsByMethod)
91
- const syncMethods = asyncMethods.map(name => `${name}Sync`)
92
-
93
- massWrap(fs, asyncMethods, createWrapFunction())
94
- massWrap(fs, syncMethods, createWrapFunction())
95
- massWrap(fs.promises, asyncMethods, createWrapFunction('promises.'))
96
-
97
- wrap(fs.realpath, 'native', createWrapFunction('', 'realpath.native'))
98
- wrap(fs.realpathSync, 'native', createWrapFunction('', 'realpath.native'))
99
- wrap(fs.promises.realpath, 'native', createWrapFunction('', 'realpath.native'))
100
-
101
- wrap(fs, 'createReadStream', wrapCreateStream)
102
- wrap(fs, 'createWriteStream', wrapCreateStream)
103
- if (fs.Dir) {
104
- wrap(fs.Dir.prototype, 'close', createWrapFunction('dir.'))
105
- wrap(fs.Dir.prototype, 'closeSync', createWrapFunction('dir.'))
106
- wrap(fs.Dir.prototype, 'read', createWrapFunction('dir.'))
107
- wrap(fs.Dir.prototype, 'readSync', createWrapFunction('dir.'))
108
- wrap(fs.Dir.prototype, Symbol.asyncIterator, createWrapDirAsyncIterator())
109
- }
110
-
111
- wrap(fs, 'unwatchFile', createWatchWrapFunction())
112
- wrap(fs, 'watch', createWatchWrapFunction())
113
- wrap(fs, 'watchFile', createWatchWrapFunction())
112
+ wrap(fs, 'unwatchFile', createWatchWrapFunction())
113
+ wrap(fs, 'watch', createWatchWrapFunction())
114
+ wrap(fs, 'watchFile', createWatchWrapFunction())
114
115
 
115
- return fs
116
+ return fs
117
+ })
116
118
  })
117
-
118
119
  function isFirstMethodReturningFileHandle (original) {
119
120
  return !kHandle && original.name === 'open'
120
121
  }
@@ -418,8 +418,13 @@ addHook({
418
418
 
419
419
  // we store the original function, not to lose it
420
420
  originalFns.set(newFn, this.fn)
421
-
422
421
  this.fn = newFn
422
+
423
+ // Temporarily keep functionality when .asyncResource is removed from node
424
+ // in https://github.com/nodejs/node/pull/46432
425
+ if (!this.fn.asyncResource) {
426
+ this.fn.asyncResource = asyncResource
427
+ }
423
428
  }
424
429
  }
425
430
 
@@ -98,9 +98,16 @@ function request (data, options, callback) {
98
98
  if (res.statusCode >= 200 && res.statusCode <= 299) {
99
99
  callback(null, responseData, res.statusCode)
100
100
  } else {
101
- const fullUrl = `${options.url || options.hostname || `localhost:${options.port}`}${options.path}`
102
- // eslint-disable-next-line
103
- let errorMessage = `Error from ${fullUrl}: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}.`
101
+ let errorMessage = ''
102
+ try {
103
+ const fullUrl = new URL(
104
+ options.path,
105
+ options.url || options.hostname || `http://localhost:${options.port}`
106
+ ).href
107
+ errorMessage = `Error from ${fullUrl}: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}.`
108
+ } catch (e) {
109
+ // ignore error
110
+ }
104
111
  if (responseData) {
105
112
  errorMessage += ` Response from the endpoint: "${responseData}"`
106
113
  }