dd-trace 4.5.0 → 4.6.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 +1 -1
- package/packages/datadog-instrumentations/src/kafkajs.js +11 -2
- package/packages/datadog-instrumentations/src/redis.js +48 -5
- package/packages/datadog-plugin-kafkajs/src/producer.js +6 -1
- package/packages/datadog-plugin-openai/src/services.js +14 -10
- package/packages/dd-trace/src/dogstatsd.js +14 -1
- package/packages/dd-trace/src/metrics.js +2 -2
package/package.json
CHANGED
|
@@ -16,10 +16,19 @@ const consumerFinishCh = channel('apm:kafkajs:consume:finish')
|
|
|
16
16
|
const consumerErrorCh = channel('apm:kafkajs:consume:error')
|
|
17
17
|
|
|
18
18
|
addHook({ name: 'kafkajs', versions: ['>=1.4'] }, (obj) => {
|
|
19
|
-
|
|
19
|
+
class Kafka extends obj.Kafka {
|
|
20
|
+
constructor (options) {
|
|
21
|
+
super(options)
|
|
22
|
+
this._brokers = (options.brokers && typeof options.brokers !== 'function')
|
|
23
|
+
? options.brokers.join(',') : undefined
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
obj.Kafka = Kafka
|
|
27
|
+
|
|
20
28
|
shimmer.wrap(Kafka.prototype, 'producer', createProducer => function () {
|
|
21
29
|
const producer = createProducer.apply(this, arguments)
|
|
22
30
|
const send = producer.send
|
|
31
|
+
const bootstrapServers = this._brokers
|
|
23
32
|
|
|
24
33
|
producer.send = function () {
|
|
25
34
|
const innerAsyncResource = new AsyncResource('bound-anonymous-fn')
|
|
@@ -36,7 +45,7 @@ addHook({ name: 'kafkajs', versions: ['>=1.4'] }, (obj) => {
|
|
|
36
45
|
message.headers = message.headers || {}
|
|
37
46
|
}
|
|
38
47
|
}
|
|
39
|
-
producerStartCh.publish({ topic, messages })
|
|
48
|
+
producerStartCh.publish({ topic, messages, bootstrapServers })
|
|
40
49
|
|
|
41
50
|
const result = send.apply(this, arguments)
|
|
42
51
|
|
|
@@ -11,6 +11,8 @@ const startCh = channel('apm:redis:command:start')
|
|
|
11
11
|
const finishCh = channel('apm:redis:command:finish')
|
|
12
12
|
const errorCh = channel('apm:redis:command:error')
|
|
13
13
|
|
|
14
|
+
let createClientUrl
|
|
15
|
+
|
|
14
16
|
function wrapAddCommand (addCommand) {
|
|
15
17
|
return function (command) {
|
|
16
18
|
if (!startCh.hasSubscribers) {
|
|
@@ -22,7 +24,7 @@ function wrapAddCommand (addCommand) {
|
|
|
22
24
|
|
|
23
25
|
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
24
26
|
return asyncResource.runInAsyncScope(() => {
|
|
25
|
-
start(this, name, args)
|
|
27
|
+
start(this, name, args, this._url)
|
|
26
28
|
|
|
27
29
|
const res = addCommand.apply(this, arguments)
|
|
28
30
|
const onResolve = asyncResource.bind(() => finish(finishCh, errorCh))
|
|
@@ -35,12 +37,53 @@ function wrapAddCommand (addCommand) {
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
function wrapCommandQueueClass (cls) {
|
|
41
|
+
const ret = class RedisCommandQueue extends cls {
|
|
42
|
+
constructor () {
|
|
43
|
+
super(arguments)
|
|
44
|
+
if (createClientUrl) {
|
|
45
|
+
try {
|
|
46
|
+
const parsed = new URL(createClientUrl)
|
|
47
|
+
if (parsed) {
|
|
48
|
+
this._url = { host: parsed.hostname, port: +parsed.port || 6379 }
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
// ignore
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this._url = this._url || { host: 'localhost', port: 6379 }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return ret
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function wrapCreateClient (request) {
|
|
61
|
+
return function (opts) {
|
|
62
|
+
createClientUrl = opts && opts.url
|
|
63
|
+
const ret = request.apply(this, arguments)
|
|
64
|
+
createClientUrl = undefined
|
|
65
|
+
return ret
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
addHook({ name: '@node-redis/client', file: 'dist/lib/client/commands-queue.js', versions: ['>=1'] }, redis => {
|
|
70
|
+
redis.default = wrapCommandQueueClass(redis.default)
|
|
39
71
|
shimmer.wrap(redis.default.prototype, 'addCommand', wrapAddCommand)
|
|
40
72
|
return redis
|
|
41
73
|
})
|
|
42
74
|
|
|
43
|
-
addHook({ name: '@node-redis/client', file: 'dist/lib/client/
|
|
75
|
+
addHook({ name: '@node-redis/client', file: 'dist/lib/client/index.js', versions: ['>=1'] }, redis => {
|
|
76
|
+
shimmer.wrap(redis.default, 'create', wrapCreateClient)
|
|
77
|
+
return redis
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
addHook({ name: '@redis/client', file: 'dist/lib/client/index.js', versions: ['>=1.1'] }, redis => {
|
|
81
|
+
shimmer.wrap(redis.default, 'create', wrapCreateClient)
|
|
82
|
+
return redis
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
addHook({ name: '@redis/client', file: 'dist/lib/client/commands-queue.js', versions: ['>=1.1'] }, redis => {
|
|
86
|
+
redis.default = wrapCommandQueueClass(redis.default)
|
|
44
87
|
shimmer.wrap(redis.default.prototype, 'addCommand', wrapAddCommand)
|
|
45
88
|
return redis
|
|
46
89
|
})
|
|
@@ -106,9 +149,9 @@ addHook({ name: 'redis', versions: ['>=0.12 <2.6'] }, redis => {
|
|
|
106
149
|
return redis
|
|
107
150
|
})
|
|
108
151
|
|
|
109
|
-
function start (client, command, args) {
|
|
152
|
+
function start (client, command, args, url = {}) {
|
|
110
153
|
const db = client.selected_db
|
|
111
|
-
const connectionOptions = client.connection_options || client.connection_option || client.connectionOption ||
|
|
154
|
+
const connectionOptions = client.connection_options || client.connection_option || client.connectionOption || url
|
|
112
155
|
startCh.publish({ db, command, args, connectionOptions })
|
|
113
156
|
}
|
|
114
157
|
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
|
|
4
4
|
const { encodePathwayContext } = require('../../dd-trace/src/datastreams/pathway')
|
|
5
|
+
const BOOTSTRAP_SERVERS_KEY = 'messaging.kafka.bootstrap.servers'
|
|
5
6
|
|
|
6
7
|
class KafkajsProducerPlugin extends ProducerPlugin {
|
|
7
8
|
static get id () { return 'kafkajs' }
|
|
8
9
|
static get operation () { return 'produce' }
|
|
10
|
+
static get peerServicePrecursors () { return [BOOTSTRAP_SERVERS_KEY] }
|
|
9
11
|
|
|
10
|
-
start ({ topic, messages }) {
|
|
12
|
+
start ({ topic, messages, bootstrapServers }) {
|
|
11
13
|
let pathwayCtx
|
|
12
14
|
if (this.config.dsmEnabled) {
|
|
13
15
|
const dataStreamsContext = this.tracer
|
|
@@ -24,6 +26,9 @@ class KafkajsProducerPlugin extends ProducerPlugin {
|
|
|
24
26
|
'kafka.batch_size': messages.length
|
|
25
27
|
}
|
|
26
28
|
})
|
|
29
|
+
if (bootstrapServers) {
|
|
30
|
+
span.setTag(BOOTSTRAP_SERVERS_KEY, bootstrapServers)
|
|
31
|
+
}
|
|
27
32
|
for (const message of messages) {
|
|
28
33
|
if (typeof message === 'object') {
|
|
29
34
|
if (this.config.dsmEnabled) message.headers['dd-pathway-ctx'] = pathwayCtx
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const DogStatsDClient = require('../../dd-trace/src/dogstatsd')
|
|
3
|
+
const { DogStatsDClient, NoopDogStatsDClient } = require('../../dd-trace/src/dogstatsd')
|
|
4
4
|
const ExternalLogger = require('../../dd-trace/src/external-logger/src')
|
|
5
5
|
|
|
6
6
|
const FLUSH_INTERVAL = 10 * 1000
|
|
@@ -10,15 +10,19 @@ let logger = null
|
|
|
10
10
|
let interval = null
|
|
11
11
|
|
|
12
12
|
module.exports.init = function (tracerConfig) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
if (tracerConfig.dogstatsd) {
|
|
14
|
+
metrics = new DogStatsDClient({
|
|
15
|
+
host: tracerConfig.dogstatsd.hostname,
|
|
16
|
+
port: tracerConfig.dogstatsd.port,
|
|
17
|
+
tags: [
|
|
18
|
+
`service:${tracerConfig.tags.service}`,
|
|
19
|
+
`env:${tracerConfig.tags.env}`,
|
|
20
|
+
`version:${tracerConfig.tags.version}`
|
|
21
|
+
]
|
|
22
|
+
})
|
|
23
|
+
} else {
|
|
24
|
+
metrics = new NoopDogStatsDClient()
|
|
25
|
+
}
|
|
22
26
|
|
|
23
27
|
logger = new ExternalLogger({
|
|
24
28
|
ddsource: 'openai',
|
|
@@ -143,4 +143,17 @@ class DogStatsDClient {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
class NoopDogStatsDClient {
|
|
147
|
+
gauge () { }
|
|
148
|
+
|
|
149
|
+
increment () { }
|
|
150
|
+
|
|
151
|
+
distribution () { }
|
|
152
|
+
|
|
153
|
+
flush () { }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = {
|
|
157
|
+
DogStatsDClient,
|
|
158
|
+
NoopDogStatsDClient
|
|
159
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
const { URL, format } = require('url')
|
|
6
6
|
const v8 = require('v8')
|
|
7
7
|
const os = require('os')
|
|
8
|
-
const
|
|
8
|
+
const { DogStatsDClient } = require('./dogstatsd')
|
|
9
9
|
const log = require('./log')
|
|
10
10
|
const Histogram = require('./histogram')
|
|
11
11
|
const { performance } = require('perf_hooks')
|
|
@@ -67,7 +67,7 @@ module.exports = {
|
|
|
67
67
|
}))
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
client = new
|
|
70
|
+
client = new DogStatsDClient(clientConfig)
|
|
71
71
|
|
|
72
72
|
time = process.hrtime()
|
|
73
73
|
|