Skip to content

Commit

Permalink
simplify wrap and trace (#5192)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
bengl authored Feb 3, 2025
1 parent 5d6e698 commit c403eee
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 165 deletions.
10 changes: 3 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ interface Tracer extends opentracing.Tracer {
* span will finish when that callback is called.
* * The function doesn't accept a callback and doesn't return a promise, in
* which case the span will finish at the end of the function execution.
*
* If the `orphanable` option is set to false, the function will not be traced
* unless there is already an active span or `childOf` option. Note that this
* option is deprecated and has been removed in version 4.0.
*/
trace<T> (name: string, fn: (span: tracer.Span) => T): T;
trace<T> (name: string, fn: (span: tracer.Span, done: (error?: Error) => void) => T): T;
Expand Down Expand Up @@ -659,13 +655,13 @@ declare namespace tracer {
* * 'anonymous': will hash user IDs and user logins before collecting them
* * 'anon': alias for 'anonymous'
* * 'safe': deprecated alias for 'anonymous'
*
*
* * 'identification': will collect user IDs and logins without redaction
* * 'ident': alias for 'identification'
* * 'extended': deprecated alias for 'identification'
*
*
* * 'disabled': will not collect user IDs and logins
*
*
* Unknown values will be considered as 'disabled'
* @default 'identification'
*/
Expand Down
14 changes: 0 additions & 14 deletions packages/dd-trace/src/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
const Tracer = require('./opentracing/tracer')
const tags = require('../../../ext/tags')
const Scope = require('./scope')
const { storage } = require('../../datadog-core')
const { isError } = require('./util')
const { setStartupLogConfig } = require('./startup-log')
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
const { DataStreamsProcessor } = require('./datastreams/processor')
const { DsmPathwayCodec } = require('./datastreams/pathway')
const { DD_MAJOR } = require('../../../version')
const DataStreamsContext = require('./data_streams_context')
const { DataStreamsCheckpointer } = require('./data_streams')
const { flushStartupLogs } = require('../../datadog-instrumentations/src/check_require_cache')
Expand Down Expand Up @@ -60,10 +58,6 @@ class DatadogTracer extends Tracer {
childOf: this.scope().active()
}, options)

if (!options.childOf && options.orphanable === false && DD_MAJOR < 4) {
return fn(null, () => {})
}

const span = this.startSpan(name, options)

addTags(span, options)
Expand Down Expand Up @@ -106,19 +100,11 @@ class DatadogTracer extends Tracer {
const tracer = this

return function () {
const store = storage.getStore()

if (store && store.noop) return fn.apply(this, arguments)

let optionsObj = options
if (typeof optionsObj === 'function' && typeof fn === 'function') {
optionsObj = optionsObj.apply(this, arguments)
}

if (optionsObj && optionsObj.orphanable === false && !tracer.scope().active() && DD_MAJOR < 4) {
return fn.apply(this, arguments)
}

const lastArgId = arguments.length - 1
const cb = arguments[lastArgId]

Expand Down
144 changes: 0 additions & 144 deletions packages/dd-trace/test/tracer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
require('./setup/tap')

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

const SPAN_TYPE = tags.SPAN_TYPE
const RESOURCE_NAME = tags.RESOURCE_NAME
const SERVICE_NAME = tags.SERVICE_NAME
const EXPORT_SERVICE_NAME = 'service'
const BASE_SERVICE = tags.BASE_SERVICE

const describeOrphanable = DD_MAJOR < 4 ? describe : describe.skip

describe('Tracer', () => {
let Tracer
let tracer
Expand Down Expand Up @@ -283,64 +279,6 @@ describe('Tracer', () => {
})
})
})

describeOrphanable('when there is no parent span', () => {
it('should not trace if `orphanable: false`', () => {
sinon.spy(tracer, 'startSpan')

tracer.trace('name', { orphanable: false }, () => {})

expect(tracer.startSpan).to.have.not.been.called
})

it('should trace if `orphanable: true`', () => {
sinon.spy(tracer, 'startSpan')

tracer.trace('name', { orhpanable: true }, () => {})

expect(tracer.startSpan).to.have.been.called
})

it('should trace if `orphanable: undefined`', () => {
sinon.spy(tracer, 'startSpan')

tracer.trace('name', {}, () => {})

expect(tracer.startSpan).to.have.been.called
})
})

describeOrphanable('when there is a parent span', () => {
it('should trace if `orphanable: false`', () => {
tracer.scope().activate(tracer.startSpan('parent'), () => {
sinon.spy(tracer, 'startSpan')

tracer.trace('name', { orhpanable: false }, () => {})

expect(tracer.startSpan).to.have.been.called
})
})

it('should trace if `orphanable: true`', () => {
tracer.scope().activate(tracer.startSpan('parent'), () => {
sinon.spy(tracer, 'startSpan')

tracer.trace('name', { orphanable: true }, () => {})

expect(tracer.startSpan).to.have.been.called
})
})

it('should trace if `orphanable: undefined`', () => {
tracer.scope().activate(tracer.startSpan('parent'), () => {
sinon.spy(tracer, 'startSpan')

tracer.trace('name', {}, () => {})

expect(tracer.startSpan).to.have.been.called
})
})
})
})

describe('getRumData', () => {
Expand Down Expand Up @@ -470,87 +408,5 @@ describe('Tracer', () => {
tags: { sometag: 'somevalue', invocations: 2 }
})
})

it('should not trace in a noop context', () => {
const fn = tracer.wrap('name', {}, () => {})

sinon.spy(tracer, 'trace')

storage.enterWith({ noop: true })
fn()
storage.enterWith(null)

expect(tracer.trace).to.have.not.been.called
})

describeOrphanable('when there is no parent span', () => {
it('should not trace if `orphanable: false`', () => {
const fn = tracer.wrap('name', { orphanable: false }, () => {})

sinon.spy(tracer, 'trace')

fn()

expect(tracer.trace).to.have.not.been.called
})

it('should trace if `orphanable: true`', () => {
const fn = tracer.wrap('name', { orhpanable: true }, () => {})

sinon.spy(tracer, 'trace')

fn()

expect(tracer.trace).to.have.been.called
})

it('should trace if `orphanable: undefined`', () => {
const fn = tracer.wrap('name', {}, () => {})

sinon.spy(tracer, 'trace')

fn()

expect(tracer.trace).to.have.been.called
})
})

describeOrphanable('when there is a parent span', () => {
it('should trace if `orphanable: false`', () => {
tracer.scope().activate(tracer.startSpan('parent'), () => {
const fn = tracer.wrap('name', { orhpanable: false }, () => {})

sinon.spy(tracer, 'trace')

fn()

expect(tracer.trace).to.have.been.called
})
})

it('should trace if `orphanable: true`', () => {
tracer.scope().activate(tracer.startSpan('parent'), () => {
const fn = tracer.wrap('name', { orphanable: true }, () => {})

sinon.spy(tracer, 'trace')

fn()

expect(tracer.trace).to.have.been.called
})
})

it('should trace if `orphanable: undefined`', () => {
tracer.scope().activate(tracer.startSpan('parent'), () => {
const fn = tracer.wrap('name', {}, () => {})

sinon.spy(tracer, 'trace')

fn()

expect(tracer.trace).to.have.been.called
})
})
})
})
})

0 comments on commit c403eee

Please sign in to comment.