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,272 +0,0 @@
|
|
|
1
|
-
const { promisify } = require('util')
|
|
2
|
-
|
|
3
|
-
const { RESOURCE_NAME } = require('../../../ext/tags')
|
|
4
|
-
const {
|
|
5
|
-
TEST_NAME,
|
|
6
|
-
TEST_SUITE,
|
|
7
|
-
TEST_STATUS,
|
|
8
|
-
TEST_FRAMEWORK_VERSION,
|
|
9
|
-
JEST_TEST_RUNNER,
|
|
10
|
-
ERROR_MESSAGE,
|
|
11
|
-
ERROR_TYPE,
|
|
12
|
-
TEST_PARAMETERS,
|
|
13
|
-
CI_APP_ORIGIN,
|
|
14
|
-
getTestEnvironmentMetadata,
|
|
15
|
-
getTestParametersString,
|
|
16
|
-
finishAllTraceSpans,
|
|
17
|
-
getTestSuitePath
|
|
18
|
-
} = require('../../dd-trace/src/plugins/util/test')
|
|
19
|
-
const {
|
|
20
|
-
getFormattedJestTestParameters,
|
|
21
|
-
getTestSpanTags,
|
|
22
|
-
setSuppressedErrors
|
|
23
|
-
} = require('./util')
|
|
24
|
-
|
|
25
|
-
const originals = new WeakMap()
|
|
26
|
-
|
|
27
|
-
function getVmContext (environment) {
|
|
28
|
-
if (typeof environment.getVmContext === 'function') {
|
|
29
|
-
return environment.getVmContext()
|
|
30
|
-
}
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function wrapEnvironment (BaseEnvironment) {
|
|
35
|
-
return class DatadogJestEnvironment extends BaseEnvironment {
|
|
36
|
-
constructor (config, context) {
|
|
37
|
-
super(config, context)
|
|
38
|
-
this.testSuite = getTestSuitePath(context.testPath, config.rootDir)
|
|
39
|
-
this.testSpansByTestName = {}
|
|
40
|
-
this.originalTestFnByTestName = {}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function createWrapTeardown (tracer, instrumenter) {
|
|
46
|
-
return function wrapTeardown (teardown) {
|
|
47
|
-
return async function teardownWithTrace () {
|
|
48
|
-
instrumenter.unwrap(this.global.test, 'each')
|
|
49
|
-
nameToParams = {}
|
|
50
|
-
// for jest-jasmine2
|
|
51
|
-
if (this.global.jasmine) {
|
|
52
|
-
instrumenter.unwrap(this.global.jasmine.Spec.prototype, 'onException')
|
|
53
|
-
instrumenter.unwrap(this.global, 'it')
|
|
54
|
-
instrumenter.unwrap(this.global, 'fit')
|
|
55
|
-
instrumenter.unwrap(this.global, 'xit')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
instrumenter.unwrap(this.global.test, 'each')
|
|
59
|
-
|
|
60
|
-
return teardown.apply(this, arguments).finally(() => {
|
|
61
|
-
return new Promise(resolve => tracer._exporter._writer.flush(resolve))
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let nameToParams = {}
|
|
68
|
-
|
|
69
|
-
const isTimeout = (event) => {
|
|
70
|
-
return event.error &&
|
|
71
|
-
typeof event.error === 'string' &&
|
|
72
|
-
event.error.startsWith('Exceeded timeout')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function createHandleTestEvent (tracer, testEnvironmentMetadata, instrumenter) {
|
|
76
|
-
return async function handleTestEventWithTrace (event) {
|
|
77
|
-
if (event.name === 'test_retry') {
|
|
78
|
-
let testName = event.test && event.test.name
|
|
79
|
-
const context = getVmContext(this)
|
|
80
|
-
if (context) {
|
|
81
|
-
const { currentTestName } = context.expect.getState()
|
|
82
|
-
testName = currentTestName
|
|
83
|
-
}
|
|
84
|
-
// If it's a retry, we restore the original test function so that it is not wrapped again
|
|
85
|
-
if (this.originalTestFnByTestName[testName]) {
|
|
86
|
-
event.test.fn = this.originalTestFnByTestName[testName]
|
|
87
|
-
}
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
if (event.name === 'test_fn_failure') {
|
|
91
|
-
if (!isTimeout(event)) {
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
const context = getVmContext(this)
|
|
95
|
-
if (context) {
|
|
96
|
-
const { currentTestName } = context.expect.getState()
|
|
97
|
-
const testSpan = this.testSpansByTestName[`${currentTestName}_${event.test.invocations}`]
|
|
98
|
-
if (testSpan) {
|
|
99
|
-
testSpan.setTag(ERROR_TYPE, 'Timeout')
|
|
100
|
-
testSpan.setTag(ERROR_MESSAGE, event.error)
|
|
101
|
-
testSpan.setTag(TEST_STATUS, 'fail')
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
if (event.name === 'setup') {
|
|
107
|
-
instrumenter.wrap(this.global.test, 'each', function (original) {
|
|
108
|
-
return function () {
|
|
109
|
-
const testParameters = getFormattedJestTestParameters(arguments)
|
|
110
|
-
const eachBind = original.apply(this, arguments)
|
|
111
|
-
return function () {
|
|
112
|
-
const [testName] = arguments
|
|
113
|
-
nameToParams[testName] = testParameters
|
|
114
|
-
return eachBind.apply(this, arguments)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (event.name !== 'test_skip' &&
|
|
122
|
-
event.name !== 'test_todo' &&
|
|
123
|
-
event.name !== 'test_start' &&
|
|
124
|
-
event.name !== 'hook_failure') {
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
// for hook_failure events the test entry might not be defined, because the hook
|
|
128
|
-
// is not necessarily associated to a test:
|
|
129
|
-
if (!event.test) {
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const { childOf, commonSpanTags } = getTestSpanTags(tracer, testEnvironmentMetadata)
|
|
134
|
-
|
|
135
|
-
let testName = event.test.name
|
|
136
|
-
const context = getVmContext(this)
|
|
137
|
-
|
|
138
|
-
if (context) {
|
|
139
|
-
const { currentTestName } = context.expect.getState()
|
|
140
|
-
testName = currentTestName
|
|
141
|
-
}
|
|
142
|
-
const spanTags = {
|
|
143
|
-
...commonSpanTags,
|
|
144
|
-
[TEST_NAME]: testName,
|
|
145
|
-
[TEST_SUITE]: this.testSuite,
|
|
146
|
-
[TEST_FRAMEWORK_VERSION]: tracer._version,
|
|
147
|
-
[JEST_TEST_RUNNER]: 'jest-circus'
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const testParametersString = getTestParametersString(nameToParams, event.test.name)
|
|
151
|
-
if (testParametersString) {
|
|
152
|
-
spanTags[TEST_PARAMETERS] = testParametersString
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const resource = `${this.testSuite}.${testName}`
|
|
156
|
-
if (event.name === 'test_skip' || event.name === 'test_todo') {
|
|
157
|
-
const testSpan = tracer.startSpan(
|
|
158
|
-
'jest.test',
|
|
159
|
-
{
|
|
160
|
-
childOf,
|
|
161
|
-
tags: {
|
|
162
|
-
...spanTags,
|
|
163
|
-
[RESOURCE_NAME]: resource,
|
|
164
|
-
[TEST_STATUS]: 'skip'
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
)
|
|
168
|
-
testSpan.context()._trace.origin = CI_APP_ORIGIN
|
|
169
|
-
testSpan.finish()
|
|
170
|
-
return
|
|
171
|
-
}
|
|
172
|
-
if (event.name === 'hook_failure') {
|
|
173
|
-
const testSpan = tracer.startSpan(
|
|
174
|
-
'jest.test',
|
|
175
|
-
{
|
|
176
|
-
childOf,
|
|
177
|
-
tags: {
|
|
178
|
-
...spanTags,
|
|
179
|
-
[RESOURCE_NAME]: resource,
|
|
180
|
-
[TEST_STATUS]: 'fail'
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
)
|
|
184
|
-
testSpan.context()._trace.origin = CI_APP_ORIGIN
|
|
185
|
-
if (event.test.errors && event.test.errors.length) {
|
|
186
|
-
const error = new Error(event.test.errors[0][0])
|
|
187
|
-
error.stack = event.test.errors[0][1].stack
|
|
188
|
-
testSpan.setTag('error', error)
|
|
189
|
-
}
|
|
190
|
-
testSpan.finish()
|
|
191
|
-
return
|
|
192
|
-
}
|
|
193
|
-
// event.name === test_start at this point
|
|
194
|
-
const environment = this
|
|
195
|
-
environment.originalTestFnByTestName[testName] = event.test.fn
|
|
196
|
-
|
|
197
|
-
let specFunction = event.test.fn
|
|
198
|
-
if (specFunction.length) {
|
|
199
|
-
specFunction = promisify(specFunction)
|
|
200
|
-
}
|
|
201
|
-
event.test.fn = tracer.wrap(
|
|
202
|
-
'jest.test',
|
|
203
|
-
{
|
|
204
|
-
type: 'test',
|
|
205
|
-
childOf,
|
|
206
|
-
resource,
|
|
207
|
-
tags: spanTags
|
|
208
|
-
},
|
|
209
|
-
async () => {
|
|
210
|
-
let result
|
|
211
|
-
const testSpan = tracer.scope().active()
|
|
212
|
-
environment.testSpansByTestName[`${testName}_${event.test.invocations}`] = testSpan
|
|
213
|
-
testSpan.context()._trace.origin = CI_APP_ORIGIN
|
|
214
|
-
try {
|
|
215
|
-
result = await specFunction()
|
|
216
|
-
// it may have been set already if the test timed out
|
|
217
|
-
let suppressedErrors = []
|
|
218
|
-
const context = getVmContext(environment)
|
|
219
|
-
if (context) {
|
|
220
|
-
suppressedErrors = context.expect.getState().suppressedErrors
|
|
221
|
-
}
|
|
222
|
-
setSuppressedErrors(suppressedErrors, testSpan)
|
|
223
|
-
if (!testSpan._spanContext._tags[TEST_STATUS]) {
|
|
224
|
-
testSpan.setTag(TEST_STATUS, 'pass')
|
|
225
|
-
}
|
|
226
|
-
} catch (error) {
|
|
227
|
-
testSpan.setTag(TEST_STATUS, 'fail')
|
|
228
|
-
testSpan.setTag('error', error)
|
|
229
|
-
throw error
|
|
230
|
-
} finally {
|
|
231
|
-
finishAllTraceSpans(testSpan)
|
|
232
|
-
}
|
|
233
|
-
return result
|
|
234
|
-
}
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function patch (Environment, tracer, config) {
|
|
240
|
-
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest', config)
|
|
241
|
-
const proto = Environment.prototype
|
|
242
|
-
|
|
243
|
-
this.wrap(proto, 'teardown', createWrapTeardown(tracer, this))
|
|
244
|
-
|
|
245
|
-
const newHandleTestEvent = createHandleTestEvent(tracer, testEnvironmentMetadata, this)
|
|
246
|
-
originals.set(newHandleTestEvent, proto.handleTestEvent)
|
|
247
|
-
proto.handleTestEvent = newHandleTestEvent
|
|
248
|
-
|
|
249
|
-
return wrapEnvironment(Environment)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function unpatch (Environment) {
|
|
253
|
-
const proto = Environment.prototype
|
|
254
|
-
|
|
255
|
-
this.unwrap(Environment.prototype, 'teardown')
|
|
256
|
-
proto.handleTestEvent = originals.get(proto.handleTestEvent)
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
module.exports = [
|
|
260
|
-
{
|
|
261
|
-
name: 'jest-environment-node',
|
|
262
|
-
versions: ['>=24.8.0'],
|
|
263
|
-
patch,
|
|
264
|
-
unpatch
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
name: 'jest-environment-jsdom',
|
|
268
|
-
versions: ['>=24.8.0'],
|
|
269
|
-
patch,
|
|
270
|
-
unpatch
|
|
271
|
-
}
|
|
272
|
-
]
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
const { promisify } = require('util')
|
|
2
|
-
|
|
3
|
-
const { RESOURCE_NAME } = require('../../../ext/tags')
|
|
4
|
-
const {
|
|
5
|
-
TEST_NAME,
|
|
6
|
-
TEST_SUITE,
|
|
7
|
-
TEST_STATUS,
|
|
8
|
-
TEST_FRAMEWORK_VERSION,
|
|
9
|
-
JEST_TEST_RUNNER,
|
|
10
|
-
CI_APP_ORIGIN,
|
|
11
|
-
getTestEnvironmentMetadata,
|
|
12
|
-
finishAllTraceSpans,
|
|
13
|
-
getTestSuitePath
|
|
14
|
-
} = require('../../dd-trace/src/plugins/util/test')
|
|
15
|
-
const { getTestSpanTags, setSuppressedErrors } = require('./util')
|
|
16
|
-
|
|
17
|
-
function createWrapIt (tracer, globalConfig, globalInput, testEnvironmentMetadata) {
|
|
18
|
-
return function wrapIt (it) {
|
|
19
|
-
return function itWithTrace (description, specFunction, timeout) {
|
|
20
|
-
let oldSpecFunction = specFunction
|
|
21
|
-
if (specFunction.length) {
|
|
22
|
-
oldSpecFunction = promisify(oldSpecFunction)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const { childOf, commonSpanTags } = getTestSpanTags(tracer, testEnvironmentMetadata)
|
|
26
|
-
|
|
27
|
-
const testSuite = getTestSuitePath(globalInput.jasmine.testPath, globalConfig.rootDir)
|
|
28
|
-
|
|
29
|
-
const newSpecFunction = tracer.wrap(
|
|
30
|
-
'jest.test',
|
|
31
|
-
{
|
|
32
|
-
type: 'test',
|
|
33
|
-
childOf,
|
|
34
|
-
tags: {
|
|
35
|
-
...commonSpanTags,
|
|
36
|
-
[TEST_SUITE]: testSuite,
|
|
37
|
-
[TEST_FRAMEWORK_VERSION]: tracer._version,
|
|
38
|
-
[JEST_TEST_RUNNER]: 'jest-jasmine2'
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
async (done) => {
|
|
42
|
-
const testSpan = tracer.scope().active()
|
|
43
|
-
const { currentTestName } = globalInput.expect.getState()
|
|
44
|
-
const resource = `${testSuite}.${currentTestName}`
|
|
45
|
-
testSpan.setTag(TEST_NAME, currentTestName)
|
|
46
|
-
testSpan.setTag(RESOURCE_NAME, resource)
|
|
47
|
-
testSpan.context()._trace.origin = CI_APP_ORIGIN
|
|
48
|
-
let result
|
|
49
|
-
globalInput.jasmine.testSpanByTestName[currentTestName] = testSpan
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
result = await oldSpecFunction()
|
|
53
|
-
const suppressedErrors = globalInput.expect.getState().suppressedErrors
|
|
54
|
-
setSuppressedErrors(suppressedErrors, testSpan)
|
|
55
|
-
if (!testSpan._spanContext._tags[TEST_STATUS]) {
|
|
56
|
-
testSpan.setTag(TEST_STATUS, 'pass')
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
testSpan.setTag(TEST_STATUS, 'fail')
|
|
60
|
-
testSpan.setTag('error', error)
|
|
61
|
-
if (done) {
|
|
62
|
-
done(error)
|
|
63
|
-
}
|
|
64
|
-
throw error
|
|
65
|
-
} finally {
|
|
66
|
-
finishAllTraceSpans(testSpan)
|
|
67
|
-
}
|
|
68
|
-
if (done) {
|
|
69
|
-
done(result)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
)
|
|
73
|
-
return it(description, newSpecFunction, timeout)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function createWrapOnException (tracer, globalInput) {
|
|
79
|
-
return function wrapOnException (onException) {
|
|
80
|
-
return function onExceptionWithTrace (err) {
|
|
81
|
-
let activeTestSpan = tracer.scope().active()
|
|
82
|
-
if (!activeTestSpan) {
|
|
83
|
-
activeTestSpan = globalInput.jasmine.testSpanByTestName[this.getFullName()]
|
|
84
|
-
}
|
|
85
|
-
if (!activeTestSpan) {
|
|
86
|
-
return onException.apply(this, arguments)
|
|
87
|
-
}
|
|
88
|
-
const {
|
|
89
|
-
[TEST_NAME]: testName,
|
|
90
|
-
[TEST_SUITE]: testSuite,
|
|
91
|
-
[TEST_STATUS]: testStatus
|
|
92
|
-
} = activeTestSpan._spanContext._tags
|
|
93
|
-
|
|
94
|
-
const isActiveSpanFailing = this.getFullName() === testName &&
|
|
95
|
-
this.result.testPath.endsWith(testSuite)
|
|
96
|
-
|
|
97
|
-
if (isActiveSpanFailing && !testStatus) {
|
|
98
|
-
activeTestSpan.setTag(TEST_STATUS, 'fail')
|
|
99
|
-
// If we don't do this, jest will show this file on its error message
|
|
100
|
-
if (err.stack) {
|
|
101
|
-
const stackFrames = err.stack.split('\n')
|
|
102
|
-
const filteredStackFrames = stackFrames.filter(frame => !frame.includes(__dirname)).join('\n')
|
|
103
|
-
err.stack = filteredStackFrames
|
|
104
|
-
}
|
|
105
|
-
activeTestSpan.setTag('error', err)
|
|
106
|
-
// need to manually finish, as it will not be caught in `itWithTrace`
|
|
107
|
-
activeTestSpan.finish()
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return onException.apply(this, arguments)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function createWrapItSkip (tracer, globalConfig, globalInput, testEnvironmentMetadata) {
|
|
116
|
-
return function wrapItSkip (it) {
|
|
117
|
-
return function itSkipWithTrace () {
|
|
118
|
-
const { childOf, commonSpanTags } = getTestSpanTags(tracer, testEnvironmentMetadata)
|
|
119
|
-
|
|
120
|
-
const testSuite = getTestSuitePath(globalInput.jasmine.testPath, globalConfig.rootDir)
|
|
121
|
-
|
|
122
|
-
const spec = it.apply(this, arguments)
|
|
123
|
-
|
|
124
|
-
const testName = spec.getFullName()
|
|
125
|
-
const resource = `${testSuite}.${testName}`
|
|
126
|
-
|
|
127
|
-
const testSpan = tracer.startSpan(
|
|
128
|
-
'jest.test',
|
|
129
|
-
{
|
|
130
|
-
childOf,
|
|
131
|
-
tags: {
|
|
132
|
-
...commonSpanTags,
|
|
133
|
-
[RESOURCE_NAME]: resource,
|
|
134
|
-
[TEST_NAME]: testName,
|
|
135
|
-
[TEST_SUITE]: testSuite,
|
|
136
|
-
[TEST_STATUS]: 'skip',
|
|
137
|
-
[TEST_FRAMEWORK_VERSION]: tracer._version,
|
|
138
|
-
[JEST_TEST_RUNNER]: 'jest-jasmine2'
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
)
|
|
142
|
-
testSpan.context()._trace.origin = CI_APP_ORIGIN
|
|
143
|
-
testSpan.finish()
|
|
144
|
-
|
|
145
|
-
return spec
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function createWrapJasmineAsyncInstall (tracer, instrumenter, testEnvironmentMetadata) {
|
|
151
|
-
return function jasmineAsyncInstallWithTrace (jasmineAsyncInstall) {
|
|
152
|
-
return function (globalConfig, globalInput) {
|
|
153
|
-
globalInput.jasmine.testSpanByTestName = {}
|
|
154
|
-
instrumenter.wrap(globalInput.jasmine.Spec.prototype, 'onException', createWrapOnException(tracer, globalInput))
|
|
155
|
-
instrumenter.wrap(globalInput, 'it', createWrapIt(tracer, globalConfig, globalInput, testEnvironmentMetadata))
|
|
156
|
-
// instruments 'it.only'
|
|
157
|
-
instrumenter.wrap(globalInput, 'fit', createWrapIt(tracer, globalConfig, globalInput, testEnvironmentMetadata))
|
|
158
|
-
// instruments 'it.skip'
|
|
159
|
-
instrumenter.wrap(
|
|
160
|
-
globalInput,
|
|
161
|
-
'xit',
|
|
162
|
-
createWrapItSkip(tracer, globalConfig, globalInput, testEnvironmentMetadata)
|
|
163
|
-
)
|
|
164
|
-
return jasmineAsyncInstall(globalConfig, globalInput)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
module.exports = [
|
|
170
|
-
{
|
|
171
|
-
name: 'jest-jasmine2',
|
|
172
|
-
versions: ['>=24.8.0'],
|
|
173
|
-
file: 'build/jasmineAsyncInstall.js',
|
|
174
|
-
patch: function (jasmineAsyncInstallExport, tracer, config) {
|
|
175
|
-
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest', config)
|
|
176
|
-
return this.wrapExport(
|
|
177
|
-
jasmineAsyncInstallExport.default,
|
|
178
|
-
createWrapJasmineAsyncInstall(tracer, this, testEnvironmentMetadata)(jasmineAsyncInstallExport.default)
|
|
179
|
-
)
|
|
180
|
-
},
|
|
181
|
-
unpatch: function (jasmineAsyncInstallExport) {
|
|
182
|
-
this.unwrapExport(jasmineAsyncInstallExport.default)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
]
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { wrapThen } = require('../../datadog-instrumentations/src/helpers/promise')
|
|
4
|
-
|
|
5
|
-
function createPatch (file) {
|
|
6
|
-
return {
|
|
7
|
-
name: 'knex',
|
|
8
|
-
versions: ['>=0.8.0'],
|
|
9
|
-
file,
|
|
10
|
-
patch (Builder) {
|
|
11
|
-
this.wrap(Builder.prototype, 'then', wrapThen)
|
|
12
|
-
},
|
|
13
|
-
unpatch (Builder) {
|
|
14
|
-
this.unwrap(Builder.prototype, 'then')
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = [
|
|
20
|
-
createPatch('lib/query/builder.js'),
|
|
21
|
-
createPatch('lib/raw.js'),
|
|
22
|
-
createPatch('lib/schema/builder.js')
|
|
23
|
-
]
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
function createWrapRequest (tracer) {
|
|
4
|
-
const scope = tracer.scope()
|
|
5
|
-
|
|
6
|
-
return function wrapRequest (original) {
|
|
7
|
-
return function requestWithTrace (request, callback) {
|
|
8
|
-
const index = arguments.length - 1
|
|
9
|
-
|
|
10
|
-
arguments[index] = scope.bind(arguments[index])
|
|
11
|
-
|
|
12
|
-
return original.apply(this, arguments)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = [
|
|
18
|
-
{
|
|
19
|
-
name: 'limitd-client',
|
|
20
|
-
versions: ['>=2.8'],
|
|
21
|
-
patch (LimitdClient, tracer) {
|
|
22
|
-
this.wrap(LimitdClient.prototype, '_directRequest', createWrapRequest(tracer))
|
|
23
|
-
this.wrap(LimitdClient.prototype, '_retriedRequest', createWrapRequest(tracer))
|
|
24
|
-
},
|
|
25
|
-
unpatch (LimitdClient) {
|
|
26
|
-
this.unwrap(LimitdClient.prototype, '_directRequest')
|
|
27
|
-
this.unwrap(LimitdClient.prototype, '_retriedRequest')
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
]
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const http = require('http')
|
|
4
|
-
const https = require('https')
|
|
5
|
-
const docker = require('./docker')
|
|
6
|
-
const log = require('../../log')
|
|
7
|
-
const { storage } = require('../../../../datadog-core')
|
|
8
|
-
|
|
9
|
-
const httpAgent = new http.Agent({ keepAlive: true })
|
|
10
|
-
const httpsAgent = new https.Agent({ keepAlive: true })
|
|
11
|
-
const containerId = docker.id()
|
|
12
|
-
|
|
13
|
-
function retriableRequest (options, callback, client, data) {
|
|
14
|
-
const store = storage.getStore()
|
|
15
|
-
|
|
16
|
-
storage.enterWith({ noop: true })
|
|
17
|
-
|
|
18
|
-
const req = client.request(options, res => {
|
|
19
|
-
let data = ''
|
|
20
|
-
|
|
21
|
-
res.setTimeout(options.timeout)
|
|
22
|
-
|
|
23
|
-
res.on('data', chunk => { data += chunk })
|
|
24
|
-
res.on('end', () => {
|
|
25
|
-
if (res.statusCode >= 200 && res.statusCode <= 299) {
|
|
26
|
-
callback(null, data, res.statusCode)
|
|
27
|
-
} else {
|
|
28
|
-
const error = new Error(`Error from the agent: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}`)
|
|
29
|
-
error.status = res.statusCode
|
|
30
|
-
|
|
31
|
-
callback(error, null, res.statusCode)
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
req.setTimeout(options.timeout, req.abort)
|
|
36
|
-
data.forEach(buffer => req.write(buffer))
|
|
37
|
-
|
|
38
|
-
storage.enterWith(store)
|
|
39
|
-
|
|
40
|
-
return req
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function request (options, callback) {
|
|
44
|
-
options = Object.assign({
|
|
45
|
-
headers: {},
|
|
46
|
-
data: [],
|
|
47
|
-
timeout: 2000
|
|
48
|
-
}, options)
|
|
49
|
-
|
|
50
|
-
const data = [].concat(options.data)
|
|
51
|
-
const isSecure = options.protocol === 'https:'
|
|
52
|
-
const client = isSecure ? https : http
|
|
53
|
-
const agent = isSecure ? httpsAgent : httpAgent
|
|
54
|
-
|
|
55
|
-
options.agent = agent
|
|
56
|
-
options.headers['Content-Length'] = byteLength(data)
|
|
57
|
-
|
|
58
|
-
if (containerId) {
|
|
59
|
-
options.headers['Datadog-Container-ID'] = containerId
|
|
60
|
-
}
|
|
61
|
-
const firstRequest = retriableRequest(options, callback, client, data)
|
|
62
|
-
|
|
63
|
-
// The first request will be retried if it fails due to a socket connection close
|
|
64
|
-
const firstRequestErrorHandler = error => {
|
|
65
|
-
if (firstRequest.reusedSocket && (error.code === 'ECONNRESET' || error.code === 'EPIPE')) {
|
|
66
|
-
log.debug('Retrying request due to socket connection error')
|
|
67
|
-
const retriedReq = retriableRequest(options, callback, client, data)
|
|
68
|
-
// The retried request will fail normally
|
|
69
|
-
retriedReq.on('error', e => callback(new Error(`Network error trying to reach the agent: ${e.message}`)))
|
|
70
|
-
retriedReq.end()
|
|
71
|
-
} else {
|
|
72
|
-
callback(new Error(`Network error trying to reach the agent: ${error.message}`))
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
firstRequest.on('error', firstRequestErrorHandler)
|
|
77
|
-
firstRequest.end()
|
|
78
|
-
|
|
79
|
-
return firstRequest
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function byteLength (data) {
|
|
83
|
-
return data.length > 0 ? data.reduce((prev, next) => prev + next.length, 0) : 0
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
module.exports = request
|
package/scripts/postpublish.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const exec = require('./helpers/exec')
|
|
4
|
-
|
|
5
|
-
const pkg = require('../package.json')
|
|
6
|
-
|
|
7
|
-
const betaExpr = /\d+\.\d+\.\d+-.*/
|
|
8
|
-
const legacyExpr = /0\.\d+\.\d+/
|
|
9
|
-
|
|
10
|
-
if (!betaExpr.test(pkg.version) && !legacyExpr.test(pkg.version)) {
|
|
11
|
-
const releaseBranches = exec.pipe('git fetch && git branch -a | grep -E "/v\\d+\\.x"')
|
|
12
|
-
.trim()
|
|
13
|
-
.split(/\s+/)
|
|
14
|
-
const releaseMajors = releaseBranches
|
|
15
|
-
.map(branch => parseInt(branch.replace(/[^0-9]/g, '')))
|
|
16
|
-
.sort()
|
|
17
|
-
.reverse()
|
|
18
|
-
const latestMajor = releaseMajors[0]
|
|
19
|
-
const currentMajor = parseInt(pkg.version.split('.')[0])
|
|
20
|
-
|
|
21
|
-
if (currentMajor === latestMajor) {
|
|
22
|
-
exec(`node scripts/publish_docs.js "v${pkg.version}"`)
|
|
23
|
-
}
|
|
24
|
-
}
|