dd-trace 4.0.0-pre-1b1c414 → 4.0.0-pre-e7fe5c1

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/index.d.ts CHANGED
@@ -77,9 +77,6 @@ export declare interface Tracer extends opentracing.Tracer {
77
77
  * span will finish when that callback is called.
78
78
  * * The function doesn't accept a callback and doesn't return a promise, in
79
79
  * which case the span will finish at the end of the function execution.
80
- *
81
- * If the `orphanable` option is set to false, the function will not be traced
82
- * unless there is already an active span or `childOf` option.
83
80
  */
84
81
  trace<T> (name: string, fn: (span?: Span, fn?: (error?: Error) => any) => T): T;
85
82
  trace<T> (name: string, options: TraceOptions & SpanOptions, fn: (span?: Span, done?: (error?: Error) => string) => T): T;
@@ -488,12 +485,6 @@ export declare interface TracerOptions {
488
485
  */
489
486
  logLevel?: 'error' | 'debug'
490
487
 
491
- /**
492
- * If false, require a parent in order to trace.
493
- * @default true
494
- */
495
- orphanable?: boolean
496
-
497
488
  /**
498
489
  * Enables DBM to APM link using tag injection.
499
490
  * @default 'disabled'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.0.0-pre-1b1c414",
3
+ "version": "4.0.0-pre-e7fe5c1",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -22,6 +22,10 @@ for (const packageName of names) {
22
22
 
23
23
  hooks[packageName]()
24
24
 
25
+ if (!instrumentations[packageName]) {
26
+ return moduleExports
27
+ }
28
+
25
29
  for (const { name, file, versions, hook } of instrumentations[packageName]) {
26
30
  const fullFilename = filename(name, file)
27
31
 
@@ -1,7 +1,10 @@
1
1
  'use strict'
2
+ const semver = require('semver')
3
+
2
4
  const { addHook, channel, AsyncResource } = require('./helpers/instrument')
3
5
  const shimmer = require('../../datadog-shimmer')
4
6
  const log = require('../../dd-trace/src/log')
7
+ const { version: ddTraceVersion } = require('../../../package.json')
5
8
  const {
6
9
  getCoveredFilenamesFromCoverage,
7
10
  JEST_WORKER_TRACE_PAYLOAD_CODE,
@@ -480,11 +483,13 @@ function jasmineAsyncInstallWraper (jasmineAsyncInstallExport, jestVersion) {
480
483
  }
481
484
  }
482
485
 
483
- addHook({
484
- name: 'jest-jasmine2',
485
- versions: ['>=24.8.0'],
486
- file: 'build/jasmineAsyncInstall.js'
487
- }, jasmineAsyncInstallWraper)
486
+ if (semver.lt(ddTraceVersion, '4.0.0')) {
487
+ addHook({
488
+ name: 'jest-jasmine2',
489
+ versions: ['>=24.8.0'],
490
+ file: 'build/jasmineAsyncInstall.js'
491
+ }, jasmineAsyncInstallWraper)
492
+ }
488
493
 
489
494
  addHook({
490
495
  name: 'jest-worker',
@@ -10,7 +10,7 @@ const {
10
10
  mergeCoverage,
11
11
  getTestSuitePath,
12
12
  fromCoverageMapToCoverage,
13
- getTestLineStart
13
+ getCallSites
14
14
  } = require('../../dd-trace/src/plugins/util/test')
15
15
 
16
16
  const testStartCh = channel('ci:mocha:test:start')
@@ -393,9 +393,13 @@ addHook({
393
393
  file: 'lib/suite.js'
394
394
  }, (Suite) => {
395
395
  shimmer.wrap(Suite.prototype, 'addTest', addTest => function (test) {
396
- // In here, the test definition is in the stack, so we search for it.
397
- const startLine = getTestLineStart(new Error(), test.file)
398
- testToStartLine.set(test, startLine)
396
+ const callSites = getCallSites()
397
+ let startLine
398
+ const testCallSite = callSites.find(site => site.getFileName() === test.file)
399
+ if (testCallSite) {
400
+ startLine = testCallSite.getLineNumber()
401
+ testToStartLine.set(test, startLine)
402
+ }
399
403
  return addTest.apply(this, arguments)
400
404
  })
401
405
  return Suite
@@ -103,7 +103,8 @@ module.exports = {
103
103
  resetCoverage,
104
104
  mergeCoverage,
105
105
  fromCoverageMapToCoverage,
106
- getTestLineStart
106
+ getTestLineStart,
107
+ getCallSites
107
108
  }
108
109
 
109
110
  // Returns pkg manager and its version, separated by '-', e.g. npm-8.15.0 or yarn-1.22.19
@@ -395,3 +396,23 @@ function getTestLineStart (err, testSuitePath) {
395
396
  return null
396
397
  }
397
398
  }
399
+
400
+ // From https://github.com/felixge/node-stack-trace/blob/ba06dcdb50d465cd440d84a563836e293b360427/index.js#L1
401
+ function getCallSites () {
402
+ const oldLimit = Error.stackTraceLimit
403
+ Error.stackTraceLimit = Infinity
404
+
405
+ const dummy = {}
406
+
407
+ const v8Handler = Error.prepareStackTrace
408
+ Error.prepareStackTrace = function (_, v8StackTrace) {
409
+ return v8StackTrace
410
+ }
411
+ Error.captureStackTrace(dummy)
412
+
413
+ const v8StackTrace = dummy.stack
414
+ Error.prepareStackTrace = v8Handler
415
+ Error.stackTraceLimit = oldLimit
416
+
417
+ return v8StackTrace
418
+ }
@@ -1,5 +1,17 @@
1
1
  const request = require('../exporters/common/request')
2
2
  let seqId = 0
3
+
4
+ function getPayload (payload) {
5
+ // Some telemetry endpoints payloads accept collections of elements such as the 'logs' endpoint.
6
+ // 'logs' request type payload is meant to send library logs to Datadog’s backend.
7
+ if (Array.isArray(payload)) {
8
+ return payload
9
+ } else {
10
+ const { logger, tags, serviceMapping, ...trimmedPayload } = payload
11
+ return trimmedPayload
12
+ }
13
+ }
14
+
3
15
  function sendData (config, application, host, reqType, payload = {}) {
4
16
  const {
5
17
  hostname,
@@ -7,8 +19,6 @@ function sendData (config, application, host, reqType, payload = {}) {
7
19
  url
8
20
  } = config
9
21
 
10
- const { logger, tags, serviceMapping, ...trimmedPayload } = payload
11
-
12
22
  const options = {
13
23
  url,
14
24
  hostname,
@@ -27,7 +37,7 @@ function sendData (config, application, host, reqType, payload = {}) {
27
37
  tracer_time: Math.floor(Date.now() / 1000),
28
38
  runtime_id: config.tags['runtime-id'],
29
39
  seq_id: ++seqId,
30
- payload: trimmedPayload,
40
+ payload: getPayload(payload),
31
41
  application,
32
42
  host
33
43
  })
@@ -26,10 +26,6 @@ class DatadogTracer extends Tracer {
26
26
  childOf: this.scope().active()
27
27
  }, options)
28
28
 
29
- if (!options.childOf && options.orphanable === false) {
30
- return fn(null, () => {})
31
- }
32
-
33
29
  const span = this.startSpan(name, options)
34
30
 
35
31
  addTags(span, options)
@@ -81,10 +77,6 @@ class DatadogTracer extends Tracer {
81
77
  optionsObj = optionsObj.apply(this, arguments)
82
78
  }
83
79
 
84
- if (optionsObj && optionsObj.orphanable === false && !tracer.scope().active()) {
85
- return fn.apply(this, arguments)
86
- }
87
-
88
80
  const lastArgId = arguments.length - 1
89
81
  const cb = arguments[lastArgId]
90
82