dd-trace 2.4.2 → 2.7.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/LICENSE-3rdparty.csv +1 -2
- package/ci/init.js +6 -0
- package/ci/jest/env.js +16 -3
- package/ext/exporters.d.ts +2 -1
- package/ext/exporters.js +2 -1
- package/index.d.ts +17 -8
- package/package.json +20 -23
- package/packages/datadog-instrumentations/index.js +14 -0
- package/packages/datadog-instrumentations/src/connect.js +111 -0
- package/packages/datadog-instrumentations/src/cypress.js +8 -0
- package/packages/datadog-instrumentations/src/express.js +27 -0
- package/packages/datadog-instrumentations/src/fastify.js +187 -0
- package/packages/datadog-instrumentations/src/find-my-way.js +30 -0
- package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +100 -0
- package/packages/datadog-instrumentations/src/http/server.js +1 -1
- package/packages/datadog-instrumentations/src/jest.js +175 -0
- package/packages/datadog-instrumentations/src/kafkajs.js +112 -0
- package/packages/datadog-instrumentations/src/knex.js +20 -0
- package/packages/datadog-instrumentations/src/koa.js +159 -0
- package/packages/datadog-instrumentations/src/limitd-client.js +21 -0
- package/packages/datadog-instrumentations/src/oracledb.js +128 -0
- package/packages/datadog-instrumentations/src/paperplane.js +77 -0
- package/packages/datadog-instrumentations/src/pg.js +2 -2
- package/packages/datadog-instrumentations/src/restify.js +58 -0
- package/packages/datadog-instrumentations/src/rhea.js +1 -1
- package/packages/datadog-instrumentations/src/router.js +177 -0
- package/packages/datadog-plugin-aws-sdk/src/helpers.js +4 -4
- package/packages/datadog-plugin-aws-sdk/src/index.js +1 -1
- package/packages/datadog-plugin-connect/src/index.js +10 -114
- package/packages/datadog-plugin-cucumber/src/index.js +16 -16
- package/packages/datadog-plugin-cypress/src/index.js +10 -5
- package/packages/datadog-plugin-cypress/src/plugin.js +18 -17
- package/packages/datadog-plugin-dns/src/index.js +12 -1
- package/packages/datadog-plugin-express/src/index.js +11 -25
- package/packages/datadog-plugin-fastify/src/index.js +17 -4
- package/packages/datadog-plugin-find-my-way/src/index.js +20 -0
- package/packages/datadog-plugin-fs/src/index.js +2 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +56 -111
- package/packages/datadog-plugin-http/src/server.js +2 -10
- package/packages/datadog-plugin-jest/src/index.js +101 -3
- package/packages/datadog-plugin-jest/src/util.js +1 -29
- package/packages/datadog-plugin-kafkajs/src/index.js +64 -90
- package/packages/datadog-plugin-koa/src/index.js +12 -164
- package/packages/datadog-plugin-mocha/src/index.js +14 -15
- package/packages/datadog-plugin-oracledb/src/index.js +34 -100
- package/packages/datadog-plugin-paperplane/src/index.js +14 -100
- package/packages/datadog-plugin-paperplane/src/logger.js +11 -0
- package/packages/datadog-plugin-paperplane/src/server.js +24 -0
- package/packages/datadog-plugin-restify/src/index.js +13 -75
- package/packages/datadog-plugin-router/src/index.js +67 -164
- package/packages/datadog-plugin-web/src/index.js +20 -0
- package/packages/dd-trace/lib/version.js +1 -1
- package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +34 -12
- package/packages/dd-trace/src/appsec/index.js +7 -3
- package/packages/dd-trace/src/appsec/recommended.json +15 -5
- package/packages/dd-trace/src/appsec/reporter.js +33 -3
- package/packages/dd-trace/src/appsec/rule_manager.js +2 -2
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +32 -0
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +51 -0
- package/packages/dd-trace/src/config.js +33 -4
- package/packages/dd-trace/src/encode/0.4.js +0 -1
- package/packages/dd-trace/src/encode/agentless-ci-visibility.js +193 -0
- package/packages/dd-trace/src/encode/tags-processors.js +116 -0
- package/packages/dd-trace/src/exporter.js +3 -0
- package/packages/dd-trace/src/exporters/agent/index.js +1 -1
- package/packages/dd-trace/src/exporters/agent/writer.js +7 -32
- package/packages/dd-trace/src/exporters/{agent → common}/docker.js +0 -0
- package/packages/dd-trace/src/exporters/common/request.js +83 -0
- package/packages/dd-trace/src/exporters/common/writer.js +36 -0
- package/packages/dd-trace/src/exporters/{agent/scheduler.js → scheduler.js} +0 -0
- package/packages/dd-trace/src/format.js +9 -5
- package/packages/dd-trace/src/instrumenter.js +3 -0
- package/packages/dd-trace/src/pkg.js +11 -6
- package/packages/dd-trace/src/plugin_manager.js +13 -7
- package/packages/dd-trace/src/plugins/index.js +1 -2
- package/packages/dd-trace/src/plugins/log_plugin.js +8 -4
- package/packages/dd-trace/src/plugins/plugin.js +8 -0
- package/packages/dd-trace/src/plugins/util/test.js +79 -1
- package/packages/dd-trace/src/plugins/util/web.js +41 -12
- package/packages/dd-trace/src/profiling/config.js +8 -8
- package/packages/dd-trace/src/profiling/exporters/agent.js +1 -1
- package/packages/dd-trace/src/profiling/index.js +4 -4
- package/packages/dd-trace/src/profiling/profilers/{heap.js → space.js} +2 -2
- package/packages/dd-trace/src/profiling/profilers/{cpu.js → wall.js} +3 -3
- package/packages/dd-trace/src/proxy.js +2 -0
- package/packages/dd-trace/src/span_processor.js +4 -1
- package/packages/dd-trace/src/telemetry.js +187 -0
- package/scripts/install_plugin_modules.js +1 -0
- package/packages/datadog-plugin-fastify/src/fastify.js +0 -198
- package/packages/datadog-plugin-fastify/src/find-my-way.js +0 -37
- package/packages/datadog-plugin-jest/src/jest-environment.js +0 -272
- package/packages/datadog-plugin-jest/src/jest-jasmine2.js +0 -185
- package/packages/datadog-plugin-knex/src/index.js +0 -23
- package/packages/datadog-plugin-limitd-client/src/index.js +0 -30
- package/packages/dd-trace/src/exporters/agent/request.js +0 -86
- package/scripts/postpublish.js +0 -24
|
@@ -1,90 +1,85 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const Plugin = require('../../dd-trace/src/plugins/plugin')
|
|
4
|
+
const { storage } = require('../../datadog-core')
|
|
3
5
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
const producer = createProducer.apply(this, arguments)
|
|
10
|
-
|
|
11
|
-
const send = producer.send
|
|
12
|
-
|
|
13
|
-
const tags = {
|
|
14
|
-
'service.name': serviceName,
|
|
15
|
-
'span.kind': 'producer',
|
|
16
|
-
'component': 'kafkajs'
|
|
17
|
-
}
|
|
7
|
+
class KafkajsPlugin extends Plugin {
|
|
8
|
+
static get name () {
|
|
9
|
+
return 'kafkajs'
|
|
10
|
+
}
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
constructor (...args) {
|
|
13
|
+
super(...args)
|
|
14
|
+
|
|
15
|
+
this.addSub(`apm:kafkajs:produce:start`, ({ topic, messages }) => {
|
|
16
|
+
const store = storage.getStore()
|
|
17
|
+
const childOf = store ? store.span : store
|
|
18
|
+
const span = this.tracer.startSpan('kafka.produce', {
|
|
19
|
+
childOf,
|
|
20
|
+
tags: {
|
|
21
|
+
'service.name': this.config.service || `${this.tracer._service}-kafka`,
|
|
22
|
+
'span.kind': 'producer',
|
|
23
|
+
'component': 'kafkajs'
|
|
24
|
+
}
|
|
25
|
+
})
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
analyticsSampler.sample(span, this.config.measured)
|
|
28
|
+
this.enter(span, store)
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
span.addTags({
|
|
31
|
+
'resource.name': topic,
|
|
32
|
+
'kafka.topic': topic,
|
|
33
|
+
'kafka.batch_size': messages.length
|
|
34
|
+
})
|
|
35
|
+
for (const message of messages) {
|
|
36
|
+
if (typeof message === 'object') {
|
|
37
|
+
this.tracer.inject(span, 'text_map', message.headers)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
this.addSub(`apm:kafkajs:consume:start`, ({ topic, partition, message }) => {
|
|
43
|
+
const store = storage.getStore()
|
|
44
|
+
const childOf = extract(this.tracer, message.headers)
|
|
45
|
+
const span = this.tracer.startSpan('kafka.consume', {
|
|
46
|
+
childOf,
|
|
47
|
+
tags: {
|
|
48
|
+
'service.name': this.config.service || `${this.tracer._service}-kafka`,
|
|
49
|
+
'span.kind': 'consumer',
|
|
50
|
+
'span.type': 'worker',
|
|
51
|
+
'component': 'kafkajs',
|
|
26
52
|
'resource.name': topic,
|
|
27
53
|
'kafka.topic': topic,
|
|
28
|
-
'kafka.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for (const message of messages) {
|
|
32
|
-
message.headers = message.headers || {}
|
|
33
|
-
tracer.inject(currentSpan, 'text_map', message.headers)
|
|
54
|
+
'kafka.partition': partition,
|
|
55
|
+
'kafka.message.offset': message.offset
|
|
34
56
|
}
|
|
35
|
-
|
|
36
|
-
return send.apply(this, args)
|
|
37
57
|
})
|
|
38
58
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
59
|
+
analyticsSampler.sample(span, this.config.measured, true)
|
|
60
|
+
this.enter(span, store)
|
|
61
|
+
})
|
|
43
62
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const serviceName = config.service || `${tracer._service}-kafka`
|
|
48
|
-
const consumer = createConsumer.apply(this, arguments)
|
|
49
|
-
const run = consumer.run
|
|
50
|
-
|
|
51
|
-
const tags = {
|
|
52
|
-
'service.name': serviceName,
|
|
53
|
-
'span.kind': 'consumer',
|
|
54
|
-
'span.type': 'worker',
|
|
55
|
-
'component': 'kafkajs'
|
|
56
|
-
}
|
|
63
|
+
this.addSub(`apm:kafkajs:end`, () => {
|
|
64
|
+
this.exit()
|
|
65
|
+
})
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
if (typeof eachMessage !== 'function') return run({ eachMessage, ...runArgs })
|
|
67
|
+
this.addSub(`apm:kafkajs:consume:error`, errorHandler)
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
eachMessage: function (...eachMessageArgs) {
|
|
63
|
-
const { topic, partition, message } = eachMessageArgs[0]
|
|
64
|
-
const childOf = extract(tracer, message.headers)
|
|
69
|
+
this.addSub(`apm:kafkajs:consume:finish`, finishHandler)
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
const currentSpan = tracer.scope().active()
|
|
71
|
+
this.addSub(`apm:kafkajs:produce:error`, errorHandler)
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
'resource.name': topic,
|
|
73
|
-
'kafka.topic': topic,
|
|
74
|
-
'kafka.partition': partition,
|
|
75
|
-
'kafka.message.offset': message.offset
|
|
76
|
-
})
|
|
73
|
+
this.addSub(`apm:kafkajs:produce:finish`, finishHandler)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
...runArgs
|
|
82
|
-
})
|
|
83
|
-
}
|
|
77
|
+
function finishHandler () {
|
|
78
|
+
storage.getStore().span.finish()
|
|
79
|
+
}
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
81
|
+
function errorHandler (error) {
|
|
82
|
+
storage.getStore().span.setTag('error', error)
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
function extract (tracer, bufferMap) {
|
|
@@ -99,25 +94,4 @@ function extract (tracer, bufferMap) {
|
|
|
99
94
|
return tracer.extract('text_map', textMap)
|
|
100
95
|
}
|
|
101
96
|
|
|
102
|
-
module.exports =
|
|
103
|
-
{
|
|
104
|
-
name: 'kafkajs',
|
|
105
|
-
versions: ['>=1.4'],
|
|
106
|
-
patch ({ Kafka }, tracer, config) {
|
|
107
|
-
this.wrap(
|
|
108
|
-
Kafka.prototype,
|
|
109
|
-
'producer',
|
|
110
|
-
createWrapProducer(tracer, config)
|
|
111
|
-
)
|
|
112
|
-
this.wrap(
|
|
113
|
-
Kafka.prototype,
|
|
114
|
-
'consumer',
|
|
115
|
-
createWrapConsumer(tracer, config)
|
|
116
|
-
)
|
|
117
|
-
},
|
|
118
|
-
unpatch ({ Kafka }) {
|
|
119
|
-
this.unwrap(Kafka.prototype, 'producer')
|
|
120
|
-
this.unwrap(Kafka.prototype, 'consumer')
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
]
|
|
97
|
+
module.exports = KafkajsPlugin
|
|
@@ -1,176 +1,24 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const RouterPlugin = require('../../datadog-plugin-router/src')
|
|
3
4
|
const web = require('../../dd-trace/src/plugins/util/web')
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
config = web.normalizeConfig(config)
|
|
9
|
-
|
|
10
|
-
return function wrapCallback (callback) {
|
|
11
|
-
return function callbackWithTrace () {
|
|
12
|
-
const handleRequest = callback.apply(this, arguments)
|
|
13
|
-
|
|
14
|
-
if (typeof handleRequest !== 'function') return handleRequest
|
|
15
|
-
|
|
16
|
-
return function handleRequestWithTrace (req, res) {
|
|
17
|
-
web.instrument(tracer, config, req, res, 'koa.request')
|
|
18
|
-
|
|
19
|
-
return handleRequest.apply(this, arguments)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function createWrapCreateContext () {
|
|
26
|
-
return function wrapCreateContext (createContext) {
|
|
27
|
-
return function createContextWithTrace (req, res) {
|
|
28
|
-
const ctx = createContext.apply(this, arguments)
|
|
29
|
-
|
|
30
|
-
if (!ctx) return ctx
|
|
31
|
-
|
|
32
|
-
web.patch(req)
|
|
33
|
-
web.beforeEnd(req, () => {
|
|
34
|
-
web.enterRoute(req, ctx.routePath)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
return ctx
|
|
38
|
-
}
|
|
6
|
+
class KoaPlugin extends RouterPlugin {
|
|
7
|
+
static get name () {
|
|
8
|
+
return 'koa'
|
|
39
9
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function createWrapUse () {
|
|
43
|
-
return function wrapUse (use) {
|
|
44
|
-
return function useWithTrace () {
|
|
45
|
-
const result = use.apply(this, arguments)
|
|
46
|
-
|
|
47
|
-
if (!Array.isArray(this.middleware)) return result
|
|
48
10
|
|
|
49
|
-
|
|
11
|
+
constructor (...args) {
|
|
12
|
+
super(...args)
|
|
50
13
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function createWrapRegister (tracer, config) {
|
|
59
|
-
return function wrapRegister (register) {
|
|
60
|
-
return function registerWithTrace (path, methods, middleware, opts) {
|
|
61
|
-
const route = register.apply(this, arguments)
|
|
62
|
-
|
|
63
|
-
if (!Array.isArray(path) && route && Array.isArray(route.stack)) {
|
|
64
|
-
wrapStack(route)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return route
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function createWrapRouterUse (tracer, config) {
|
|
73
|
-
return function wrapUse (use) {
|
|
74
|
-
return function useWithTrace () {
|
|
75
|
-
const router = use.apply(this, arguments)
|
|
76
|
-
|
|
77
|
-
router.stack.forEach(wrapStack)
|
|
78
|
-
|
|
79
|
-
return router
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function wrapStack (layer) {
|
|
85
|
-
layer.stack = layer.stack.map(middleware => {
|
|
86
|
-
if (typeof middleware !== 'function') return middleware
|
|
87
|
-
|
|
88
|
-
const original = originals.get(middleware)
|
|
89
|
-
|
|
90
|
-
middleware = original || middleware
|
|
91
|
-
|
|
92
|
-
const wrappedMiddleware = wrapMiddleware(middleware)
|
|
93
|
-
|
|
94
|
-
const handler = function (ctx, next) {
|
|
95
|
-
if (!ctx || !web.active(ctx.req)) return middleware.apply(this, arguments)
|
|
96
|
-
|
|
97
|
-
web.exitRoute(ctx.req)
|
|
98
|
-
web.enterRoute(ctx.req, layer.path)
|
|
99
|
-
|
|
100
|
-
return wrappedMiddleware.apply(this, arguments)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
originals.set(handler, middleware)
|
|
104
|
-
|
|
105
|
-
return handler
|
|
106
|
-
})
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function wrapMiddleware (fn) {
|
|
110
|
-
if (typeof fn !== 'function') return fn
|
|
111
|
-
|
|
112
|
-
return function (ctx, next) {
|
|
113
|
-
if (!ctx) return fn.apply(this, arguments)
|
|
114
|
-
|
|
115
|
-
return web.wrapMiddleware(ctx.req, fn, 'koa.middleware', () => {
|
|
116
|
-
try {
|
|
117
|
-
const result = fn.apply(this, arguments)
|
|
118
|
-
|
|
119
|
-
if (result && typeof result.then === 'function') {
|
|
120
|
-
result.then(
|
|
121
|
-
() => web.finish(ctx.req),
|
|
122
|
-
err => web.finish(ctx.req, err)
|
|
123
|
-
)
|
|
124
|
-
} else {
|
|
125
|
-
web.finish(ctx.req)
|
|
126
|
-
}
|
|
14
|
+
this.addSub('apm:koa:request:handle', ({ req }) => {
|
|
15
|
+
this.setFramework(req, 'koa', this.config)
|
|
16
|
+
})
|
|
127
17
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
web.finish(ctx.req, e)
|
|
131
|
-
throw e
|
|
132
|
-
}
|
|
18
|
+
this.addSub('apm:koa:request:route', ({ req, route }) => {
|
|
19
|
+
web.setRoute(req, route)
|
|
133
20
|
})
|
|
134
21
|
}
|
|
135
22
|
}
|
|
136
23
|
|
|
137
|
-
module.exports =
|
|
138
|
-
{
|
|
139
|
-
name: 'koa',
|
|
140
|
-
versions: ['>=2'],
|
|
141
|
-
patch (Koa, tracer, config) {
|
|
142
|
-
this.wrap(Koa.prototype, 'callback', createWrapCallback(tracer, config))
|
|
143
|
-
this.wrap(Koa.prototype, 'createContext', createWrapCreateContext(tracer, config))
|
|
144
|
-
this.wrap(Koa.prototype, 'use', createWrapUse(tracer, config))
|
|
145
|
-
},
|
|
146
|
-
unpatch (Koa) {
|
|
147
|
-
this.unwrap(Koa.prototype, 'callback')
|
|
148
|
-
this.unwrap(Koa.prototype, 'createContext')
|
|
149
|
-
this.unwrap(Koa.prototype, 'use')
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: '@koa/router',
|
|
154
|
-
versions: ['>=8'],
|
|
155
|
-
patch (Router, tracer, config) {
|
|
156
|
-
this.wrap(Router.prototype, 'register', createWrapRegister(tracer, config))
|
|
157
|
-
this.wrap(Router.prototype, 'use', createWrapRouterUse(tracer, config))
|
|
158
|
-
},
|
|
159
|
-
unpatch (Router) {
|
|
160
|
-
this.unwrap(Router.prototype, 'register')
|
|
161
|
-
this.unwrap(Router.prototype, 'use')
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: 'koa-router',
|
|
166
|
-
versions: ['>=7'],
|
|
167
|
-
patch (Router, tracer, config) {
|
|
168
|
-
this.wrap(Router.prototype, 'register', createWrapRegister(tracer, config))
|
|
169
|
-
this.wrap(Router.prototype, 'use', createWrapRouterUse(tracer, config))
|
|
170
|
-
},
|
|
171
|
-
unpatch (Router) {
|
|
172
|
-
this.unwrap(Router.prototype, 'register')
|
|
173
|
-
this.unwrap(Router.prototype, 'use')
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
]
|
|
24
|
+
module.exports = KoaPlugin
|
|
@@ -5,21 +5,19 @@ const { storage } = require('../../datadog-core')
|
|
|
5
5
|
|
|
6
6
|
const {
|
|
7
7
|
CI_APP_ORIGIN,
|
|
8
|
-
|
|
9
|
-
TEST_NAME,
|
|
8
|
+
TEST_CODE_OWNERS,
|
|
10
9
|
TEST_SUITE,
|
|
11
|
-
TEST_FRAMEWORK_VERSION,
|
|
12
10
|
TEST_STATUS,
|
|
13
11
|
TEST_PARAMETERS,
|
|
14
12
|
finishAllTraceSpans,
|
|
15
13
|
getTestEnvironmentMetadata,
|
|
16
14
|
getTestSuitePath,
|
|
17
15
|
getTestParentSpan,
|
|
18
|
-
getTestParametersString
|
|
16
|
+
getTestParametersString,
|
|
17
|
+
getCodeOwnersFileEntries,
|
|
18
|
+
getCodeOwnersForFilename,
|
|
19
|
+
getTestCommonTags
|
|
19
20
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
20
|
-
const { SPAN_TYPE, RESOURCE_NAME, SAMPLING_PRIORITY } = require('../../../ext/tags')
|
|
21
|
-
const { SAMPLING_RULE_DECISION } = require('../../dd-trace/src/constants')
|
|
22
|
-
const { AUTO_KEEP } = require('../../../ext/priority')
|
|
23
21
|
|
|
24
22
|
const skippedTests = new WeakSet()
|
|
25
23
|
|
|
@@ -30,16 +28,11 @@ function getTestSpanMetadata (tracer, test, sourceRoot) {
|
|
|
30
28
|
const fullTestName = test.fullTitle()
|
|
31
29
|
const testSuite = getTestSuitePath(testSuiteAbsolutePath, sourceRoot)
|
|
32
30
|
|
|
31
|
+
const commonTags = getTestCommonTags(fullTestName, testSuite, tracer._version)
|
|
32
|
+
|
|
33
33
|
return {
|
|
34
34
|
childOf,
|
|
35
|
-
|
|
36
|
-
[TEST_TYPE]: 'test',
|
|
37
|
-
[TEST_NAME]: fullTestName,
|
|
38
|
-
[TEST_SUITE]: testSuite,
|
|
39
|
-
[SAMPLING_RULE_DECISION]: 1,
|
|
40
|
-
[SAMPLING_PRIORITY]: AUTO_KEEP,
|
|
41
|
-
[TEST_FRAMEWORK_VERSION]: tracer._version,
|
|
42
|
-
[RESOURCE_NAME]: `${testSuite}.${fullTestName}`
|
|
35
|
+
...commonTags
|
|
43
36
|
}
|
|
44
37
|
}
|
|
45
38
|
|
|
@@ -54,6 +47,7 @@ class MochaPlugin extends Plugin {
|
|
|
54
47
|
this._testNameToParams = {}
|
|
55
48
|
this.testEnvironmentMetadata = getTestEnvironmentMetadata('mocha', this.config)
|
|
56
49
|
this.sourceRoot = process.cwd()
|
|
50
|
+
this.codeOwnersEntries = getCodeOwnersFileEntries(this.sourceRoot)
|
|
57
51
|
|
|
58
52
|
this.addSub('ci:mocha:test:start', (test) => {
|
|
59
53
|
const store = storage.getStore()
|
|
@@ -139,6 +133,11 @@ class MochaPlugin extends Plugin {
|
|
|
139
133
|
if (testParametersString) {
|
|
140
134
|
testSpanMetadata[TEST_PARAMETERS] = testParametersString
|
|
141
135
|
}
|
|
136
|
+
const codeOwners = getCodeOwnersForFilename(testSpanMetadata[TEST_SUITE], this.codeOwnersEntries)
|
|
137
|
+
|
|
138
|
+
if (codeOwners) {
|
|
139
|
+
testSpanMetadata[TEST_CODE_OWNERS] = codeOwners
|
|
140
|
+
}
|
|
142
141
|
|
|
143
142
|
const testSpan = this.tracer
|
|
144
143
|
.startSpan('mocha.test', {
|
|
@@ -1,105 +1,54 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const Plugin = require('../../dd-trace/src/plugins/plugin')
|
|
4
|
+
const { storage } = require('../../datadog-core')
|
|
3
5
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
class OracledbPlugin extends Plugin {
|
|
8
|
+
static get name () {
|
|
9
|
+
return 'oracledb'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
constructor (...args) {
|
|
13
|
+
super(...args)
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return function executeWithTrace (dbQuery, ...args) {
|
|
11
|
-
const connAttrs = connectionAttributes.get(this)
|
|
12
|
-
const service = getServiceName(tracer, config, connAttrs)
|
|
15
|
+
this.addSub('apm:oracledb:execute:start', ({ query, connAttrs }) => {
|
|
16
|
+
const service = getServiceName(this.tracer, this.config, connAttrs)
|
|
13
17
|
const connectStringObj = new URL('http://' + connAttrs.connectString)
|
|
14
18
|
const tags = {
|
|
15
19
|
'span.kind': 'client',
|
|
16
20
|
'span.type': 'sql',
|
|
17
|
-
'sql.query':
|
|
21
|
+
'sql.query': query,
|
|
18
22
|
'db.instance': connectStringObj.pathname.substring(1),
|
|
19
23
|
'db.hostname': connectStringObj.hostname,
|
|
20
|
-
'db.user': config.user,
|
|
24
|
+
'db.user': this.config.user,
|
|
21
25
|
'db.port': connectStringObj.port,
|
|
22
|
-
'resource.name':
|
|
26
|
+
'resource.name': query,
|
|
23
27
|
'service.name': service
|
|
24
28
|
}
|
|
29
|
+
const store = storage.getStore()
|
|
30
|
+
const childOf = store ? store.span : store
|
|
31
|
+
const span = this.tracer.startSpan('oracle.query', {
|
|
32
|
+
childOf,
|
|
33
|
+
tags
|
|
34
|
+
})
|
|
35
|
+
analyticsSampler.sample(span, this.config.measured)
|
|
36
|
+
this.enter(span, store)
|
|
37
|
+
})
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return execute.apply(this, args)
|
|
32
|
-
}).apply(this, arguments)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function createWrapGetConnection (tracer, config) {
|
|
38
|
-
return function wrapGetConnection (getConnection) {
|
|
39
|
-
return function getConnectionWithTrace (connAttrs, callback) {
|
|
40
|
-
if (callback) {
|
|
41
|
-
arguments[1] = (err, connection) => {
|
|
42
|
-
if (connection) {
|
|
43
|
-
connectionAttributes.set(connection, connAttrs)
|
|
44
|
-
}
|
|
45
|
-
callback(err, connection)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getConnection.apply(this, arguments)
|
|
49
|
-
} else {
|
|
50
|
-
return getConnection.apply(this, arguments).then((connection) => {
|
|
51
|
-
connectionAttributes.set(connection, connAttrs)
|
|
52
|
-
return connection
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function createWrapCreatePool (tracer, config) {
|
|
60
|
-
return function wrapCreatePool (createPool) {
|
|
61
|
-
return function createPoolWithTrace (poolAttrs, callback) {
|
|
62
|
-
if (callback) {
|
|
63
|
-
arguments[1] = (err, pool) => {
|
|
64
|
-
if (pool) {
|
|
65
|
-
poolAttributes.set(pool, poolAttrs)
|
|
66
|
-
}
|
|
67
|
-
callback(err, pool)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
createPool.apply(this, arguments)
|
|
71
|
-
} else {
|
|
72
|
-
return createPool.apply(this, arguments).then((pool) => {
|
|
73
|
-
poolAttributes.set(pool, poolAttrs)
|
|
74
|
-
return pool
|
|
75
|
-
})
|
|
39
|
+
this.addSub('apm:oracledb:execute:error', err => {
|
|
40
|
+
const store = storage.getStore()
|
|
41
|
+
if (store && store.span) {
|
|
42
|
+
store.span.setTag('error', err)
|
|
76
43
|
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
44
|
+
})
|
|
80
45
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (typeof arguments[arguments.length - 1] === 'function') {
|
|
86
|
-
callback = arguments[arguments.length - 1]
|
|
87
|
-
}
|
|
88
|
-
if (callback) {
|
|
89
|
-
arguments[arguments.length - 1] = (err, connection) => {
|
|
90
|
-
if (connection) {
|
|
91
|
-
connectionAttributes.set(connection, poolAttributes.get(this))
|
|
92
|
-
}
|
|
93
|
-
callback(err, connection)
|
|
94
|
-
}
|
|
95
|
-
getConnection.apply(this, arguments)
|
|
96
|
-
} else {
|
|
97
|
-
return getConnection.apply(this, arguments).then((connection) => {
|
|
98
|
-
connectionAttributes.set(connection, poolAttributes.get(this))
|
|
99
|
-
return connection
|
|
100
|
-
})
|
|
46
|
+
this.addSub('apm:oracledb:execute:finish', () => {
|
|
47
|
+
const store = storage.getStore()
|
|
48
|
+
if (store && store.span) {
|
|
49
|
+
store.span.finish()
|
|
101
50
|
}
|
|
102
|
-
}
|
|
51
|
+
})
|
|
103
52
|
}
|
|
104
53
|
}
|
|
105
54
|
|
|
@@ -113,19 +62,4 @@ function getServiceName (tracer, config, connAttrs) {
|
|
|
113
62
|
}
|
|
114
63
|
}
|
|
115
64
|
|
|
116
|
-
module.exports =
|
|
117
|
-
name: 'oracledb',
|
|
118
|
-
versions: ['5'],
|
|
119
|
-
patch (oracledb, tracer, config) {
|
|
120
|
-
this.wrap(oracledb.Connection.prototype, 'execute', createWrapExecute(tracer, config))
|
|
121
|
-
this.wrap(oracledb, 'getConnection', createWrapGetConnection(tracer, config))
|
|
122
|
-
this.wrap(oracledb, 'createPool', createWrapCreatePool(tracer, config))
|
|
123
|
-
this.wrap(oracledb.Pool.prototype, 'getConnection', createWrapPoolGetConnection(tracer, config))
|
|
124
|
-
},
|
|
125
|
-
unpatch (oracledb) {
|
|
126
|
-
this.unwrap(oracledb.Connection.prototype, 'execute')
|
|
127
|
-
this.unwrap(oracledb, 'getConnection')
|
|
128
|
-
this.unwrap(oracledb, 'createPool')
|
|
129
|
-
this.unwrap(oracledb.Pool.prototype, 'getConnection')
|
|
130
|
-
}
|
|
131
|
-
}
|
|
65
|
+
module.exports = OracledbPlugin
|