dd-trace 2.12.1 → 2.12.2

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.
@@ -18,7 +18,6 @@ require,methods,MIT,Copyright 2013-2014 TJ Holowaychuk
18
18
  require,module-details-from-path,MIT,Copyright 2016 Thomas Watson Steen
19
19
  require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
20
20
  require,path-to-regexp,MIT,Copyright 2014 Blake Embrey
21
- require,performance-now,MIT,Copyright 2013 Braveg1rl
22
21
  require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
23
22
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
24
23
  dev,autocannon,MIT,Copyright 2016 Matteo Collina
package/ext/formats.js CHANGED
@@ -1,10 +1,8 @@
1
1
  'use strict'
2
2
 
3
- const opentracing = require('opentracing')
4
-
5
3
  module.exports = {
6
- TEXT_MAP: opentracing.FORMAT_TEXT_MAP,
7
- HTTP_HEADERS: opentracing.FORMAT_HTTP_HEADERS,
8
- BINARY: opentracing.FORMAT_BINARY,
4
+ TEXT_MAP: 'text_map',
5
+ HTTP_HEADERS: 'http_headers',
6
+ BINARY: 'binary',
9
7
  LOG: 'log'
10
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "2.12.1",
3
+ "version": "2.12.2",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -59,8 +59,8 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@datadog/native-appsec": "^1.2.1",
62
- "@datadog/native-metrics": "^1.4.1",
63
- "@datadog/pprof": "^1.0.0",
62
+ "@datadog/native-metrics": "^1.4.2",
63
+ "@datadog/pprof": "^1.0.2",
64
64
  "@datadog/sketches-js": "^1.0.5",
65
65
  "@types/node": ">=12",
66
66
  "crypto-randomuuid": "^1.0.0",
@@ -77,7 +77,6 @@
77
77
  "module-details-from-path": "^1.0.3",
78
78
  "opentracing": ">=0.12.1",
79
79
  "path-to-regexp": "^0.1.2",
80
- "performance-now": "^2.1.0",
81
80
  "retry": "^0.10.1",
82
81
  "semver": "^5.5.0"
83
82
  },
@@ -98,7 +98,7 @@ function wrapNext (req, next) {
98
98
  nextChannel.publish({ req })
99
99
  exitChannel.publish({ req })
100
100
 
101
- next.apply(null, arguments)
101
+ next.apply(this, arguments)
102
102
  }
103
103
  }
104
104
 
@@ -145,7 +145,7 @@ function wrapNext (req, next) {
145
145
  return function () {
146
146
  nextChannel.publish({ req })
147
147
 
148
- return next.apply(null, arguments)
148
+ return next.apply(this, arguments)
149
149
  }
150
150
  }
151
151
 
@@ -153,7 +153,10 @@ function mochaHook (Runner) {
153
153
  if (isHook && testOrHook.ctx) {
154
154
  test = testOrHook.ctx.currentTest
155
155
  }
156
- const asyncResource = getTestAsyncResource(test)
156
+ let asyncResource
157
+ if (test) {
158
+ asyncResource = getTestAsyncResource(test)
159
+ }
157
160
  if (asyncResource) {
158
161
  asyncResource.runInAsyncScope(() => {
159
162
  if (isHook) {
@@ -6,7 +6,10 @@ const handlers = ['use', 'pre']
6
6
  const methods = ['del', 'get', 'head', 'opts', 'post', 'put', 'patch']
7
7
 
8
8
  const handleChannel = channel('apm:restify:request:handle')
9
- const routeChannel = channel('apm:restify:request:route')
9
+ const errorChannel = channel('apm:restify:middleware:error')
10
+ const enterChannel = channel('apm:restify:middleware:enter')
11
+ const exitChannel = channel('apm:restify:middleware:exit')
12
+ const nextChannel = channel('apm:restify:middleware:next')
10
13
 
11
14
  function wrapSetupRequest (setupRequest) {
12
15
  return function (req, res) {
@@ -37,18 +40,37 @@ function wrapFn (fn) {
37
40
  if (Array.isArray(fn)) return wrapMiddleware(fn)
38
41
 
39
42
  return function (req, res, next) {
40
- if (req.route) {
41
- routeChannel.publish({ req, route: req.route })
43
+ if (typeof next === 'function') {
44
+ arguments[2] = wrapNext(req, next)
42
45
  }
43
46
 
44
- return fn.apply(this, arguments)
47
+ const route = req.route && req.route.path
48
+
49
+ enterChannel.publish({ req, route })
50
+
51
+ try {
52
+ return fn.apply(this, arguments)
53
+ } catch (error) {
54
+ errorChannel.publish({ req, error })
55
+ nextChannel.publish({ req })
56
+ exitChannel.publish({ req })
57
+ }
58
+ }
59
+ }
60
+
61
+ function wrapNext (req, next) {
62
+ return function () {
63
+ nextChannel.publish({ req })
64
+ exitChannel.publish({ req })
65
+
66
+ next.apply(this, arguments)
45
67
  }
46
68
  }
47
69
 
48
70
  addHook({ name: 'restify', versions: ['>=3'], file: 'lib/server.js' }, Server => {
49
71
  shimmer.wrap(Server.prototype, '_setupRequest', wrapSetupRequest)
50
72
  shimmer.massWrap(Server.prototype, handlers, wrapHandler)
51
- shimmer.wrap(Server.prototype, methods, wrapMethod)
73
+ shimmer.massWrap(Server.prototype, methods, wrapMethod)
52
74
 
53
75
  return Server
54
76
  })
@@ -97,7 +97,7 @@ function createWrapRouterMethod (name) {
97
97
  nextChannel.publish({ req })
98
98
  exitChannel.publish({ req })
99
99
 
100
- next.apply(null, arguments)
100
+ next.apply(this, arguments)
101
101
  }
102
102
  }
103
103
 
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const Tags = require('opentracing').Tags
4
3
  const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
5
4
  const Plugin = require('../../dd-trace/src/plugins/plugin')
6
5
  const { storage } = require('../../datadog-core')
@@ -33,7 +32,7 @@ class BaseAwsSdkPlugin extends Plugin {
33
32
  const serviceName = this.getServiceName(serviceIdentifier)
34
33
  const childOf = this.tracer.scope().active()
35
34
  const tags = {
36
- [Tags.SPAN_KIND]: 'client',
35
+ 'span.kind': 'client',
37
36
  'service.name': serviceName,
38
37
  'aws.operation': operation,
39
38
  'aws.region': awsRegion,
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const Tags = require('opentracing').Tags
4
3
  const log = require('../../../dd-trace/src/log')
5
4
  const BaseAwsSdkPlugin = require('../base')
6
5
  const { storage } = require('../../../datadog-core')
@@ -25,7 +24,7 @@ class Sqs extends BaseAwsSdkPlugin {
25
24
  tags: Object.assign(
26
25
  {},
27
26
  this.requestTags.get(request) || {},
28
- { [Tags.SPAN_KIND]: 'server' }
27
+ { 'span.kind': 'server' }
29
28
  )
30
29
  }
31
30
  const span = plugin.tracer.startSpan('aws.response', options)
@@ -19,6 +19,13 @@ class RestifyPlugin extends RouterPlugin {
19
19
  web.setRoute(req, route)
20
20
  })
21
21
  }
22
+
23
+ configure (config) {
24
+ return super.configure({
25
+ ...config,
26
+ middleware: false // not supported
27
+ })
28
+ }
22
29
  }
23
30
 
24
31
  module.exports = RestifyPlugin
@@ -57,6 +57,10 @@ class AgentEncoder {
57
57
  return buffer
58
58
  }
59
59
 
60
+ reset () {
61
+ this._reset()
62
+ }
63
+
60
64
  _encode (bytes, trace) {
61
65
  this._encodeArrayPrefix(bytes, trace)
62
66
 
@@ -1,22 +1,33 @@
1
1
  'use strict'
2
2
 
3
+ // TODO: Add test with slow or unresponsive agent.
4
+ // TODO: Add telemetry for things like dropped requests, errors, etc.
5
+
3
6
  const http = require('http')
4
7
  const https = require('https')
5
- const log = require('../../log')
6
8
  const docker = require('./docker')
7
9
  const { storage } = require('../../../../datadog-core')
8
10
 
9
- const httpAgent = new http.Agent({ keepAlive: true })
10
- const httpsAgent = new https.Agent({ keepAlive: true })
11
+ const keepAlive = true
12
+ const maxTotalSockets = 1
13
+ const maxActiveRequests = 8
14
+ const httpAgent = new http.Agent({ keepAlive, maxTotalSockets })
15
+ const httpsAgent = new https.Agent({ keepAlive, maxTotalSockets })
11
16
  const containerId = docker.id()
12
17
 
18
+ let activeRequests = 0
19
+
13
20
  function request (data, options, keepAlive, callback) {
14
21
  if (!options.headers) {
15
22
  options.headers = {}
16
23
  }
24
+
25
+ // The timeout should be kept low to avoid excessive queueing.
26
+ const timeout = options.timeout || 2000
17
27
  const isSecure = options.protocol === 'https:'
18
28
  const client = isSecure ? https : http
19
29
  const dataArray = [].concat(data)
30
+
20
31
  options.headers['Content-Length'] = byteLength(dataArray)
21
32
 
22
33
  if (containerId) {
@@ -27,39 +38,15 @@ function request (data, options, keepAlive, callback) {
27
38
  options.agent = isSecure ? httpsAgent : httpAgent
28
39
  }
29
40
 
30
- const firstRequest = retriableRequest(options, client, callback)
31
- dataArray.forEach(buffer => firstRequest.write(buffer))
32
-
33
- // The first request will be retried
34
- const firstRequestErrorHandler = () => {
35
- log.debug('Retrying request to the intake')
36
- const retriedReq = retriableRequest(options, client, callback)
37
- dataArray.forEach(buffer => retriedReq.write(buffer))
38
- // The retried request will fail normally
39
- retriedReq.on('error', e => callback(new Error(`Network error trying to reach the intake: ${e.message}`)))
40
- retriedReq.end()
41
- }
42
-
43
- firstRequest.on('error', firstRequestErrorHandler)
44
- firstRequest.end()
45
-
46
- return firstRequest
47
- }
48
-
49
- function retriableRequest (options, client, callback) {
50
- const store = storage.getStore()
51
-
52
- storage.enterWith({ noop: true })
53
-
54
- const timeout = options.timeout || 15000
55
-
56
- const request = client.request(options, res => {
41
+ const onResponse = res => {
57
42
  let responseData = ''
58
43
 
59
44
  res.setTimeout(timeout)
60
45
 
61
46
  res.on('data', chunk => { responseData += chunk })
62
47
  res.on('end', () => {
48
+ activeRequests--
49
+
63
50
  if (res.statusCode >= 200 && res.statusCode <= 299) {
64
51
  callback(null, responseData, res.statusCode)
65
52
  } else {
@@ -69,15 +56,43 @@ function retriableRequest (options, client, callback) {
69
56
  callback(error, null, res.statusCode)
70
57
  }
71
58
  })
72
- })
73
- request.setTimeout(timeout, request.abort)
74
- storage.enterWith(store)
59
+ }
75
60
 
76
- return request
61
+ const makeRequest = onError => {
62
+ if (!request.writable) return callback(null)
63
+
64
+ activeRequests++
65
+
66
+ const store = storage.getStore()
67
+
68
+ storage.enterWith({ noop: true })
69
+
70
+ const req = client.request(options, onResponse)
71
+
72
+ req.once('error', err => {
73
+ activeRequests--
74
+ onError(err)
75
+ })
76
+
77
+ dataArray.forEach(buffer => req.write(buffer))
78
+
79
+ req.setTimeout(timeout, req.abort)
80
+ req.end()
81
+
82
+ storage.enterWith(store)
83
+ }
84
+
85
+ makeRequest(() => makeRequest(callback))
77
86
  }
78
87
 
79
88
  function byteLength (data) {
80
89
  return data.length > 0 ? data.reduce((prev, next) => prev + next.length, 0) : 0
81
90
  }
82
91
 
92
+ Object.defineProperty(request, 'writable', {
93
+ get () {
94
+ return activeRequests < maxActiveRequests
95
+ }
96
+ })
97
+
83
98
  module.exports = request
@@ -1,4 +1,6 @@
1
1
  'use strict'
2
+
3
+ const request = require('./request')
2
4
  const log = require('../../log')
3
5
 
4
6
  class Writer {
@@ -9,7 +11,10 @@ class Writer {
9
11
  flush (done = () => {}) {
10
12
  const count = this._encoder.count()
11
13
 
12
- if (count > 0) {
14
+ if (!request.writable) {
15
+ this._encoder.reset()
16
+ done()
17
+ } else if (count > 0) {
13
18
  const payload = this._encoder.makePayload()
14
19
 
15
20
  this._sendPayload(payload, count, done)
@@ -19,6 +24,8 @@ class Writer {
19
24
  }
20
25
 
21
26
  append (spans) {
27
+ if (!request.writable) return
28
+
22
29
  log.debug(() => `Encoding trace: ${JSON.stringify(spans)}`)
23
30
 
24
31
  this._encode(spans)
@@ -1,26 +1,26 @@
1
1
  'use strict'
2
2
 
3
- const Span = require('opentracing').Span
4
- const NoopSpanContext = require('../noop/span_context')
3
+ const NoopSpanContext = require('./span_context')
5
4
  const id = require('../id')
6
5
  const { storage } = require('../../../datadog-core') // TODO: noop storage?
7
6
 
8
- class NoopSpan extends Span {
7
+ class NoopSpan {
9
8
  constructor (tracer, parent) {
10
- super()
11
-
12
9
  this._store = storage.getStore()
13
10
  this._noopTracer = tracer
14
11
  this._noopContext = this._createContext(parent)
15
12
  }
16
13
 
17
- _context () {
18
- return this._noopContext
19
- }
20
-
21
- _tracer () {
22
- return this._noopTracer
23
- }
14
+ context () { return this._noopContext }
15
+ tracer () { return this._noopTracer }
16
+ setOperationName (name) { return this }
17
+ setBaggageItem (key, value) { return this }
18
+ getBaggageItem (key) {}
19
+ setTag (key, value) { return this }
20
+ addTags (keyValueMap) { return this }
21
+ log () { return this }
22
+ logEvent () {}
23
+ finish (finishTime) {}
24
24
 
25
25
  _createContext (parent) {
26
26
  const spanId = id()
@@ -1,13 +1,10 @@
1
1
  'use strict'
2
2
 
3
- const Tracer = require('opentracing').Tracer
4
3
  const Scope = require('../noop/scope')
5
4
  const Span = require('./span')
6
5
 
7
- class NoopTracer extends Tracer {
6
+ class NoopTracer {
8
7
  constructor (config) {
9
- super(config)
10
-
11
8
  this._scope = new Scope()
12
9
  this._span = new Span(this)
13
10
  }
@@ -35,10 +32,16 @@ class NoopTracer extends Tracer {
35
32
  setUrl () {
36
33
  }
37
34
 
38
- _startSpan (name, options) {
35
+ startSpan (name, options) {
39
36
  return this._span
40
37
  }
41
38
 
39
+ inject (spanContext, format, carrier) {}
40
+
41
+ extract (format, carrier) {
42
+ return this._span.context()
43
+ }
44
+
42
45
  setUser () {
43
46
  return this
44
47
  }
@@ -1,11 +1,9 @@
1
1
  'use strict'
2
2
 
3
3
  // TODO (new internal tracer): use DC events for lifecycle metrics and test them
4
-
5
- const opentracing = require('opentracing')
6
- const now = require('performance-now')
4
+ const now = require('perf_hooks').performance.now
5
+ const dateNow = Date.now
7
6
  const semver = require('semver')
8
- const Span = opentracing.Span
9
7
  const SpanContext = require('./span_context')
10
8
  const id = require('../id')
11
9
  const tagger = require('../tagger')
@@ -21,10 +19,8 @@ const {
21
19
  const unfinishedRegistry = createRegistry('unfinished')
22
20
  const finishedRegistry = createRegistry('finished')
23
21
 
24
- class DatadogSpan extends Span {
22
+ class DatadogSpan {
25
23
  constructor (tracer, processor, prioritySampler, fields, debug) {
26
- super()
27
-
28
24
  const operationName = fields.operationName
29
25
  const parent = fields.parent || null
30
26
  const tags = Object.assign({}, fields.tags)
@@ -70,66 +66,45 @@ class DatadogSpan extends Span {
70
66
  return `Span${json}`
71
67
  }
72
68
 
73
- _createContext (parent) {
74
- let spanContext
75
-
76
- if (parent) {
77
- spanContext = new SpanContext({
78
- traceId: parent._traceId,
79
- spanId: id(),
80
- parentId: parent._spanId,
81
- sampling: parent._sampling,
82
- baggageItems: Object.assign({}, parent._baggageItems),
83
- trace: parent._trace
84
- })
85
- } else {
86
- const spanId = id()
87
- spanContext = new SpanContext({
88
- traceId: spanId,
89
- spanId
90
- })
91
- }
92
-
93
- spanContext._trace.started.push(this)
94
- spanContext._trace.startTime = spanContext._trace.startTime || Date.now()
95
- spanContext._trace.ticks = spanContext._trace.ticks || now()
96
-
97
- return spanContext
98
- }
99
-
100
- _getTime () {
101
- const { startTime, ticks } = this._spanContext._trace
102
-
103
- return startTime + now() - ticks
104
- }
105
-
106
- _context () {
69
+ context () {
107
70
  return this._spanContext
108
71
  }
109
72
 
110
- _tracer () {
73
+ tracer () {
111
74
  return this._parentTracer
112
75
  }
113
76
 
114
- _setOperationName (name) {
77
+ setOperationName (name) {
115
78
  this._spanContext._name = name
79
+ return this
116
80
  }
117
81
 
118
- _setBaggageItem (key, value) {
82
+ setBaggageItem (key, value) {
119
83
  this._spanContext._baggageItems[key] = value
84
+ return this
120
85
  }
121
86
 
122
- _getBaggageItem (key) {
87
+ getBaggageItem (key) {
123
88
  return this._spanContext._baggageItems[key]
124
89
  }
125
90
 
126
- _addTags (keyValuePairs) {
127
- tagger.add(this._spanContext._tags, keyValuePairs)
91
+ setTag (key, value) {
92
+ this._addTags({ [key]: value })
93
+ return this
94
+ }
128
95
 
129
- this._prioritySampler.sample(this, false)
96
+ addTags (keyValueMap) {
97
+ this._addTags(keyValueMap)
98
+ return this
99
+ }
100
+
101
+ log () {
102
+ return this
130
103
  }
131
104
 
132
- _finish (finishTime) {
105
+ logEvent () {}
106
+
107
+ finish (finishTime) {
133
108
  if (this._duration !== undefined) {
134
109
  return
135
110
  }
@@ -157,6 +132,45 @@ class DatadogSpan extends Span {
157
132
  this._spanContext._isFinished = true
158
133
  this._processor.process(this)
159
134
  }
135
+
136
+ _createContext (parent) {
137
+ let spanContext
138
+
139
+ if (parent) {
140
+ spanContext = new SpanContext({
141
+ traceId: parent._traceId,
142
+ spanId: id(),
143
+ parentId: parent._spanId,
144
+ sampling: parent._sampling,
145
+ baggageItems: Object.assign({}, parent._baggageItems),
146
+ trace: parent._trace
147
+ })
148
+ } else {
149
+ const spanId = id()
150
+ spanContext = new SpanContext({
151
+ traceId: spanId,
152
+ spanId
153
+ })
154
+ }
155
+
156
+ spanContext._trace.started.push(this)
157
+ spanContext._trace.startTime = spanContext._trace.startTime || dateNow()
158
+ spanContext._trace.ticks = spanContext._trace.ticks || now()
159
+
160
+ return spanContext
161
+ }
162
+
163
+ _getTime () {
164
+ const { startTime, ticks } = this._spanContext._trace
165
+
166
+ return startTime + now() - ticks
167
+ }
168
+
169
+ _addTags (keyValuePairs) {
170
+ tagger.add(this._spanContext._tags, keyValuePairs)
171
+
172
+ this._prioritySampler.sample(this, false)
173
+ }
160
174
  }
161
175
 
162
176
  function createRegistry (type) {
@@ -1,11 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const SpanContext = require('opentracing').SpanContext
4
-
5
- class DatadogSpanContext extends SpanContext {
3
+ class DatadogSpanContext {
6
4
  constructor (props) {
7
- super()
8
-
9
5
  props = props || {}
10
6
 
11
7
  this._traceId = props.traceId
@@ -1,11 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const opentracing = require('opentracing')
4
3
  const os = require('os')
5
- const Tracer = opentracing.Tracer
6
- const Reference = opentracing.Reference
7
4
  const Span = require('./span')
8
- const SpanContext = require('./span_context')
9
5
  const SpanProcessor = require('../span_processor')
10
6
  const PrioritySampler = require('../priority_sampler')
11
7
  const TextMapPropagator = require('./propagation/text_map')
@@ -17,14 +13,13 @@ const formats = require('../../../../ext/formats')
17
13
  const log = require('../log')
18
14
  const metrics = require('../metrics')
19
15
  const getExporter = require('../exporter')
16
+ const SpanContext = require('./span_context')
20
17
 
21
- const REFERENCE_CHILD_OF = opentracing.REFERENCE_CHILD_OF
22
- const REFERENCE_FOLLOWS_FROM = opentracing.REFERENCE_FOLLOWS_FROM
18
+ const REFERENCE_CHILD_OF = 'child_of'
19
+ const REFERENCE_FOLLOWS_FROM = 'follows_from'
23
20
 
24
- class DatadogTracer extends Tracer {
21
+ class DatadogTracer {
25
22
  constructor (config) {
26
- super()
27
-
28
23
  const Exporter = getExporter(config.experimental.exporter)
29
24
 
30
25
  this._service = config.service
@@ -49,32 +44,34 @@ class DatadogTracer extends Tracer {
49
44
  }
50
45
  }
51
46
 
52
- _startSpan (name, fields) {
53
- const reference = getParent(fields.references)
54
- const parent = reference && reference.referencedContext()
55
- return this._startSpanInternal(name, fields, parent)
56
- }
47
+ startSpan (name, options = {}) {
48
+ const parent = options.childOf
49
+ ? getContext(options.childOf)
50
+ : getParent(options.references)
57
51
 
58
- _startSpanInternal (name, fields = {}, parent) {
59
52
  const tags = {
60
53
  'service.name': this._service
61
54
  }
62
55
 
63
56
  const span = new Span(this, this._processor, this._prioritySampler, {
64
- operationName: fields.operationName || name,
57
+ operationName: options.operationName || name,
65
58
  parent,
66
59
  tags,
67
- startTime: fields.startTime,
60
+ startTime: options.startTime,
68
61
  hostname: this._hostname
69
62
  }, this._debug)
70
63
 
71
64
  span.addTags(this._tags)
72
- span.addTags(fields.tags)
65
+ span.addTags(options.tags)
73
66
 
74
67
  return span
75
68
  }
76
69
 
77
- _inject (spanContext, format, carrier) {
70
+ inject (spanContext, format, carrier) {
71
+ if (spanContext instanceof Span) {
72
+ spanContext = spanContext.context()
73
+ }
74
+
78
75
  try {
79
76
  this._prioritySampler.sample(spanContext)
80
77
  this._propagators[format].inject(spanContext, carrier)
@@ -82,11 +79,9 @@ class DatadogTracer extends Tracer {
82
79
  log.error(e)
83
80
  metrics.increment('datadog.tracer.node.inject.errors', true)
84
81
  }
85
-
86
- return this
87
82
  }
88
83
 
89
- _extract (format, carrier) {
84
+ extract (format, carrier) {
90
85
  try {
91
86
  return this._propagators[format].extract(carrier)
92
87
  } catch (e) {
@@ -97,31 +92,31 @@ class DatadogTracer extends Tracer {
97
92
  }
98
93
  }
99
94
 
95
+ function getContext (spanContext) {
96
+ if (spanContext instanceof Span) {
97
+ spanContext = spanContext.context()
98
+ }
99
+
100
+ if (!(spanContext instanceof SpanContext)) {
101
+ spanContext = null
102
+ }
103
+
104
+ return spanContext
105
+ }
106
+
100
107
  function getParent (references = []) {
101
108
  let parent = null
102
109
 
103
110
  for (let i = 0; i < references.length; i++) {
104
111
  const ref = references[i]
105
-
106
- if (!(ref instanceof Reference)) {
107
- log.error(() => `Expected ${ref} to be an instance of opentracing.Reference`)
108
- continue
109
- }
110
-
111
- const spanContext = ref.referencedContext()
112
112
  const type = ref.type()
113
113
 
114
- if (spanContext && !(spanContext instanceof SpanContext)) {
115
- log.error(() => `Expected ${spanContext} to be an instance of SpanContext`)
116
- continue
117
- }
118
-
119
114
  if (type === REFERENCE_CHILD_OF) {
120
- parent = ref
115
+ parent = ref.referencedContext()
121
116
  break
122
117
  } else if (type === REFERENCE_FOLLOWS_FROM) {
123
118
  if (!parent) {
124
- parent = ref
119
+ parent = ref.referencedContext()
125
120
  }
126
121
  }
127
122
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  const uniq = require('lodash.uniq')
4
4
  const analyticsSampler = require('../../analytics_sampler')
5
- const FORMAT_HTTP_HEADERS = require('opentracing').FORMAT_HTTP_HEADERS
5
+ const FORMAT_HTTP_HEADERS = 'http_headers'
6
6
  const log = require('../../log')
7
7
  const tags = require('../../../../../ext/tags')
8
8
  const types = require('../../../../../ext/types')
@@ -20,7 +20,7 @@ function getStartedSpans (activeSpan) {
20
20
  }
21
21
 
22
22
  function getSpanContextTags (span) {
23
- return span._context()._tags
23
+ return span.context()._tags
24
24
  }
25
25
 
26
26
  function isWebServerSpan (tags) {
@@ -55,13 +55,13 @@ class NativeCpuProfiler {
55
55
  const active = getActiveSpan()
56
56
  if (!active) return
57
57
 
58
- const activeCtx = active._context()
58
+ const activeCtx = active.context()
59
59
  if (!activeCtx) return
60
60
 
61
61
  const spans = getStartedSpans(active)
62
62
  if (!spans || !spans.length) return
63
63
 
64
- const firstCtx = spans[0]._context()
64
+ const firstCtx = spans[0].context()
65
65
  if (!firstCtx) return
66
66
 
67
67
  const labels = {
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const BaseTracer = require('opentracing').Tracer
4
3
  const NoopTracer = require('./noop/tracer')
5
4
  const DatadogTracer = require('./tracer')
6
5
  const Config = require('./config')
@@ -14,10 +13,8 @@ const telemetry = require('./telemetry')
14
13
 
15
14
  const noop = new NoopTracer()
16
15
 
17
- class Tracer extends BaseTracer {
16
+ class Tracer {
18
17
  constructor () {
19
- super()
20
-
21
18
  this._initialized = false
22
19
  this._tracer = noop
23
20
  this._instrumenter = new Instrumenter(this)