dd-trace 1.5.1 → 1.6.0-beta.0

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": "1.5.1",
3
+ "version": "1.6.0-beta.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -1 +1 @@
1
- module.exports = '1.5.1'
1
+ module.exports = '1.6.0-beta.0'
@@ -2,16 +2,21 @@
2
2
 
3
3
  const opentracing = require('opentracing')
4
4
  const now = require('performance-now')
5
+ const semver = require('semver')
5
6
  const Span = opentracing.Span
6
7
  const SpanContext = require('./span_context')
7
8
  const constants = require('../constants')
8
9
  const id = require('../id')
9
10
  const tagger = require('../tagger')
11
+ const metrics = require('../metrics')
10
12
  const log = require('../log')
11
13
 
12
14
  const SAMPLE_RATE_METRIC_KEY = constants.SAMPLE_RATE_METRIC_KEY
13
15
  const { DD_TRACE_EXPERIMENTAL_STATE_TRACKING } = process.env
14
16
 
17
+ const unfinishedRegistry = createRegistry('unfinished')
18
+ const finishedRegistry = createRegistry('finished')
19
+
15
20
  class DatadogSpan extends Span {
16
21
  constructor (tracer, processor, sampler, prioritySampler, fields, debug) {
17
22
  super()
@@ -28,6 +33,7 @@ class DatadogSpan extends Span {
28
33
  this._sampler = sampler
29
34
  this._processor = processor
30
35
  this._prioritySampler = prioritySampler
36
+ this._name = operationName
31
37
 
32
38
  this._spanContext = this._createContext(parent)
33
39
  this._spanContext._name = operationName
@@ -35,6 +41,13 @@ class DatadogSpan extends Span {
35
41
  this._spanContext._hostname = hostname
36
42
 
37
43
  this._startTime = fields.startTime || this._getTime()
44
+
45
+ if (this._debug && unfinishedRegistry) {
46
+ metrics.increment('runtime.node.spans.unfinished')
47
+ metrics.increment('runtime.node.spans.unfinished.by.name', `span_name:${operationName}`)
48
+
49
+ unfinishedRegistry.register(this, operationName, this)
50
+ }
38
51
  }
39
52
 
40
53
  toString () {
@@ -125,6 +138,16 @@ class DatadogSpan extends Span {
125
138
  }
126
139
  }
127
140
 
141
+ if (this._debug && finishedRegistry) {
142
+ metrics.decrement('runtime.node.spans.unfinished')
143
+ metrics.decrement('runtime.node.spans.unfinished.by.name', `span_name:${this._name}`)
144
+ metrics.increment('runtime.node.spans.finished')
145
+ metrics.increment('runtime.node.spans.finished.by.name', `span_name:${this._name}`)
146
+
147
+ unfinishedRegistry.unregister(this)
148
+ finishedRegistry.register(this, this._name)
149
+ }
150
+
128
151
  finishTime = parseFloat(finishTime) || this._getTime()
129
152
 
130
153
  this._duration = finishTime - this._startTime
@@ -134,4 +157,13 @@ class DatadogSpan extends Span {
134
157
  }
135
158
  }
136
159
 
160
+ function createRegistry (type) {
161
+ if (!semver.satisfies(process.version, '>=14.6')) return
162
+
163
+ return new global.FinalizationRegistry(name => {
164
+ metrics.decrement(`runtime.node.spans.${type}`)
165
+ metrics.decrement(`runtime.node.spans.${type}.by.name`, `span_name:${name}`)
166
+ })
167
+ }
168
+
137
169
  module.exports = DatadogSpan
@@ -1,7 +1,9 @@
1
1
  'use strict'
2
2
 
3
3
  const { createHook, executionAsyncResource } = require('async_hooks')
4
+ const semver = require('semver')
4
5
  const Base = require('./base')
6
+ const metrics = require('../metrics')
5
7
 
6
8
  let singleton = null
7
9
 
@@ -14,6 +16,7 @@ class Scope extends Base {
14
16
  singleton = this
15
17
 
16
18
  this._ddResourceStore = Symbol('ddResourceStore')
19
+ this._registry = this._createRegistry()
17
20
  this._config = config
18
21
  this._stack = []
19
22
  this._hook = createHook({
@@ -76,6 +79,22 @@ class Scope extends Base {
76
79
  if (span) {
77
80
  resource[this._ddResourceStore] = span
78
81
  }
82
+
83
+ if (this._registry) {
84
+ metrics.increment('runtime.node.async.resources')
85
+ metrics.increment('runtime.node.async.resources.by.type', `resource_type:${type}`)
86
+
87
+ this._registry.register(resource, type)
88
+ }
89
+ }
90
+
91
+ _createRegistry () {
92
+ if (!this._debug || !semver.satisfies(process.version, '>=14.6')) return
93
+
94
+ return new global.FinalizationRegistry(type => {
95
+ metrics.decrement('runtime.node.async.resources')
96
+ metrics.decrement('runtime.node.async.resources.by.type', `resource_type:${type}`)
97
+ })
79
98
  }
80
99
  }
81
100