Skip to content

Commit f948e56

Browse files
benglrochdev
authored andcommitted
simplify wrap and trace (#5192)
* Remove orphanable option from wrap and trace. They were deprecated in v4, meaning they no longer work in supported versions anyway. * Remove noop check from wrap. The noop check is for internal use only, and we no longer use wrap internally, so it's unneeded in wrap.
1 parent ba63dd0 commit f948e56

File tree

3 files changed

+3
-165
lines changed

3 files changed

+3
-165
lines changed

index.d.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ interface Tracer extends opentracing.Tracer {
8585
* span will finish when that callback is called.
8686
* * The function doesn't accept a callback and doesn't return a promise, in
8787
* which case the span will finish at the end of the function execution.
88-
*
89-
* If the `orphanable` option is set to false, the function will not be traced
90-
* unless there is already an active span or `childOf` option. Note that this
91-
* option is deprecated and has been removed in version 4.0.
9288
*/
9389
trace<T> (name: string, fn: (span: tracer.Span) => T): T;
9490
trace<T> (name: string, fn: (span: tracer.Span, done: (error?: Error) => void) => T): T;
@@ -659,13 +655,13 @@ declare namespace tracer {
659655
* * 'anonymous': will hash user IDs and user logins before collecting them
660656
* * 'anon': alias for 'anonymous'
661657
* * 'safe': deprecated alias for 'anonymous'
662-
*
658+
*
663659
* * 'identification': will collect user IDs and logins without redaction
664660
* * 'ident': alias for 'identification'
665661
* * 'extended': deprecated alias for 'identification'
666-
*
662+
*
667663
* * 'disabled': will not collect user IDs and logins
668-
*
664+
*
669665
* Unknown values will be considered as 'disabled'
670666
* @default 'identification'
671667
*/

packages/dd-trace/src/tracer.js

-14
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
const Tracer = require('./opentracing/tracer')
44
const tags = require('../../../ext/tags')
55
const Scope = require('./scope')
6-
const { storage } = require('../../datadog-core')
76
const { isError } = require('./util')
87
const { setStartupLogConfig } = require('./startup-log')
98
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
109
const { DataStreamsProcessor } = require('./datastreams/processor')
1110
const { DsmPathwayCodec } = require('./datastreams/pathway')
12-
const { DD_MAJOR } = require('../../../version')
1311
const DataStreamsContext = require('./data_streams_context')
1412
const { DataStreamsCheckpointer } = require('./data_streams')
1513
const { flushStartupLogs } = require('../../datadog-instrumentations/src/check_require_cache')
@@ -60,10 +58,6 @@ class DatadogTracer extends Tracer {
6058
childOf: this.scope().active()
6159
}, options)
6260

63-
if (!options.childOf && options.orphanable === false && DD_MAJOR < 4) {
64-
return fn(null, () => {})
65-
}
66-
6761
const span = this.startSpan(name, options)
6862

6963
addTags(span, options)
@@ -106,19 +100,11 @@ class DatadogTracer extends Tracer {
106100
const tracer = this
107101

108102
return function () {
109-
const store = storage.getStore()
110-
111-
if (store && store.noop) return fn.apply(this, arguments)
112-
113103
let optionsObj = options
114104
if (typeof optionsObj === 'function' && typeof fn === 'function') {
115105
optionsObj = optionsObj.apply(this, arguments)
116106
}
117107

118-
if (optionsObj && optionsObj.orphanable === false && !tracer.scope().active() && DD_MAJOR < 4) {
119-
return fn.apply(this, arguments)
120-
}
121-
122108
const lastArgId = arguments.length - 1
123109
const cb = arguments[lastArgId]
124110

packages/dd-trace/test/tracer.spec.js

-144
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
require('./setup/tap')
44

55
const Span = require('../src/opentracing/span')
6-
const { storage } = require('../../datadog-core')
76
const Config = require('../src/config')
87
const tags = require('../../../ext/tags')
98
const { expect } = require('chai')
109
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
11-
const { DD_MAJOR } = require('../../../version')
1210

1311
const SPAN_TYPE = tags.SPAN_TYPE
1412
const RESOURCE_NAME = tags.RESOURCE_NAME
1513
const SERVICE_NAME = tags.SERVICE_NAME
1614
const EXPORT_SERVICE_NAME = 'service'
1715
const BASE_SERVICE = tags.BASE_SERVICE
1816

19-
const describeOrphanable = DD_MAJOR < 4 ? describe : describe.skip
20-
2117
describe('Tracer', () => {
2218
let Tracer
2319
let tracer
@@ -283,64 +279,6 @@ describe('Tracer', () => {
283279
})
284280
})
285281
})
286-
287-
describeOrphanable('when there is no parent span', () => {
288-
it('should not trace if `orphanable: false`', () => {
289-
sinon.spy(tracer, 'startSpan')
290-
291-
tracer.trace('name', { orphanable: false }, () => {})
292-
293-
expect(tracer.startSpan).to.have.not.been.called
294-
})
295-
296-
it('should trace if `orphanable: true`', () => {
297-
sinon.spy(tracer, 'startSpan')
298-
299-
tracer.trace('name', { orhpanable: true }, () => {})
300-
301-
expect(tracer.startSpan).to.have.been.called
302-
})
303-
304-
it('should trace if `orphanable: undefined`', () => {
305-
sinon.spy(tracer, 'startSpan')
306-
307-
tracer.trace('name', {}, () => {})
308-
309-
expect(tracer.startSpan).to.have.been.called
310-
})
311-
})
312-
313-
describeOrphanable('when there is a parent span', () => {
314-
it('should trace if `orphanable: false`', () => {
315-
tracer.scope().activate(tracer.startSpan('parent'), () => {
316-
sinon.spy(tracer, 'startSpan')
317-
318-
tracer.trace('name', { orhpanable: false }, () => {})
319-
320-
expect(tracer.startSpan).to.have.been.called
321-
})
322-
})
323-
324-
it('should trace if `orphanable: true`', () => {
325-
tracer.scope().activate(tracer.startSpan('parent'), () => {
326-
sinon.spy(tracer, 'startSpan')
327-
328-
tracer.trace('name', { orphanable: true }, () => {})
329-
330-
expect(tracer.startSpan).to.have.been.called
331-
})
332-
})
333-
334-
it('should trace if `orphanable: undefined`', () => {
335-
tracer.scope().activate(tracer.startSpan('parent'), () => {
336-
sinon.spy(tracer, 'startSpan')
337-
338-
tracer.trace('name', {}, () => {})
339-
340-
expect(tracer.startSpan).to.have.been.called
341-
})
342-
})
343-
})
344282
})
345283

346284
describe('getRumData', () => {
@@ -470,87 +408,5 @@ describe('Tracer', () => {
470408
tags: { sometag: 'somevalue', invocations: 2 }
471409
})
472410
})
473-
474-
it('should not trace in a noop context', () => {
475-
const fn = tracer.wrap('name', {}, () => {})
476-
477-
sinon.spy(tracer, 'trace')
478-
479-
storage.enterWith({ noop: true })
480-
fn()
481-
storage.enterWith(null)
482-
483-
expect(tracer.trace).to.have.not.been.called
484-
})
485-
486-
describeOrphanable('when there is no parent span', () => {
487-
it('should not trace if `orphanable: false`', () => {
488-
const fn = tracer.wrap('name', { orphanable: false }, () => {})
489-
490-
sinon.spy(tracer, 'trace')
491-
492-
fn()
493-
494-
expect(tracer.trace).to.have.not.been.called
495-
})
496-
497-
it('should trace if `orphanable: true`', () => {
498-
const fn = tracer.wrap('name', { orhpanable: true }, () => {})
499-
500-
sinon.spy(tracer, 'trace')
501-
502-
fn()
503-
504-
expect(tracer.trace).to.have.been.called
505-
})
506-
507-
it('should trace if `orphanable: undefined`', () => {
508-
const fn = tracer.wrap('name', {}, () => {})
509-
510-
sinon.spy(tracer, 'trace')
511-
512-
fn()
513-
514-
expect(tracer.trace).to.have.been.called
515-
})
516-
})
517-
518-
describeOrphanable('when there is a parent span', () => {
519-
it('should trace if `orphanable: false`', () => {
520-
tracer.scope().activate(tracer.startSpan('parent'), () => {
521-
const fn = tracer.wrap('name', { orhpanable: false }, () => {})
522-
523-
sinon.spy(tracer, 'trace')
524-
525-
fn()
526-
527-
expect(tracer.trace).to.have.been.called
528-
})
529-
})
530-
531-
it('should trace if `orphanable: true`', () => {
532-
tracer.scope().activate(tracer.startSpan('parent'), () => {
533-
const fn = tracer.wrap('name', { orphanable: true }, () => {})
534-
535-
sinon.spy(tracer, 'trace')
536-
537-
fn()
538-
539-
expect(tracer.trace).to.have.been.called
540-
})
541-
})
542-
543-
it('should trace if `orphanable: undefined`', () => {
544-
tracer.scope().activate(tracer.startSpan('parent'), () => {
545-
const fn = tracer.wrap('name', {}, () => {})
546-
547-
sinon.spy(tracer, 'trace')
548-
549-
fn()
550-
551-
expect(tracer.trace).to.have.been.called
552-
})
553-
})
554-
})
555411
})
556412
})

0 commit comments

Comments
 (0)