Skip to content

Commit 48d7fbf

Browse files
authored
Added flush interval option as env variable and use it for ESM tests (#6723)
* Added flush interval option as env variable and use it for ESM tests * added missing env into spawnPlugin function * Defaulted resolveAtFirstSuccess to 1 * Reinstated flushInterval for prisma and azure ESM tests * Changed to use spread operator
1 parent 6c552cb commit 48d7fbf

File tree

8 files changed

+21
-9
lines changed

8 files changed

+21
-9
lines changed

integration-tests/helpers/fake-agent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module.exports = class FakeAgent extends EventEmitter {
123123
// where multiple payloads are generated, and only one is expected to have the proper span (ie next.request),
124124
// but it't not guaranteed to be the last one (so, expectedMessageCount would not be helpful).
125125
// It can still fail if it takes longer than `timeout` duration or if none pass the assertions (timeout still called)
126-
assertMessageReceived (fn, timeout, expectedMessageCount = 1, resolveAtFirstSuccess) {
126+
assertMessageReceived (fn, timeout, expectedMessageCount = 1, resolveAtFirstSuccess = true) {
127127
timeout = timeout || 30000
128128
let resultResolve
129129
let resultReject

integration-tests/helpers/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdio
544544
additionalEnvArgs = additionalEnvArgs || {}
545545
let env = /** @type {Record<string, string|undefined>} */ ({
546546
NODE_OPTIONS: `--loader=${hookFile}`,
547-
DD_TRACE_AGENT_PORT: String(agentPort)
547+
DD_TRACE_AGENT_PORT: String(agentPort),
548+
DD_TRACE_FLUSH_INTERVAL: '0'
548549
})
549550
env = { ...process.env, ...env, ...additionalEnvArgs }
550551
return spawnProc(path.join(cwd, serverFile), {

packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const {
99
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1010
const { assert, expect } = require('chai')
1111

12+
const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' }
13+
1214
describe('esm', () => {
1315
let agent
1416
let proc
@@ -42,7 +44,7 @@ describe('esm', () => {
4244
assert.strictEqual(checkSpansForServiceName(payload, 'azure.eventhubs.send'), true)
4345
})
4446

45-
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
47+
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, spawnEnv)
4648
await res
4749
}).timeout(20000)
4850

@@ -86,15 +88,15 @@ describe('esm', () => {
8688
assert.strictEqual(parseLinks(payload[4][0]).length, 2)
8789
})
8890

89-
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
91+
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, spawnEnv)
9092
await res
9193
}).timeout(60000)
9294

9395
it('does not add span links when they are disabled', async () => {
9496
const res = agent.assertMessageReceived(({ headers, payload }) => {
9597
expect(payload[2][0]).to.not.have.property('_dd.span_links')
9698
})
97-
const envVar = { DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED: false }
99+
const envVar = { DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED: false, ...spawnEnv }
98100
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, undefined, envVar)
99101
await res
100102
}).timeout(60000)

packages/datadog-plugin-azure-service-bus/test/integration-test/client.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const {
88
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
99
const { assert } = require('chai')
1010

11+
const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' }
12+
1113
describe('esm', () => {
1214
let agent
1315
let proc
@@ -40,7 +42,7 @@ describe('esm', () => {
4042
assert.isArray(payload)
4143
})
4244

43-
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
45+
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, spawnEnv)
4446

4547
await res
4648
}).timeout(20000)
@@ -151,7 +153,7 @@ describe('esm', () => {
151153
assert.strictEqual(parseLinks(payload[22][0]).length, 2)
152154
})
153155

154-
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
156+
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, spawnEnv)
155157

156158
await res
157159
}).timeout(60000)

packages/datadog-plugin-prisma/test/integration-test/client.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ describe('esm', () => {
7272
// TODO: Integrate the assertions into the spawn command by adding a
7373
// callback. It should end the process when the assertions are met. That
7474
// way we can remove the Promise.all and the procPromise.then().
75-
const procPromise = spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
75+
const procPromise = spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, {
76+
DD_TRACE_FLUSH_INTERVAL: '2000'
77+
})
7678

7779
await Promise.all([
7880
procPromise.then((res) => {

packages/dd-trace/src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ class Config {
602602
DD_TRACE_MIDDLEWARE_TRACING_ENABLED,
603603
DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP,
604604
DD_TRACE_PARTIAL_FLUSH_MIN_SPANS,
605+
DD_TRACE_FLUSH_INTERVAL,
605606
DD_TRACE_PEER_SERVICE_MAPPING,
606607
DD_TRACE_PROPAGATION_EXTRACT_FIRST,
607608
DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT,
@@ -758,7 +759,7 @@ class Config {
758759
this.#envUnprocessed['experimental.aiguard.timeout'] = DD_AI_GUARD_TIMEOUT
759760
this.#setBoolean(env, 'experimental.enableGetRumData', DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED)
760761
this.#setString(env, 'experimental.exporter', DD_TRACE_EXPERIMENTAL_EXPORTER)
761-
if (AWS_LAMBDA_FUNCTION_NAME) env.flushInterval = 0
762+
env.flushInterval = AWS_LAMBDA_FUNCTION_NAME ? 0 : maybeInt(DD_TRACE_FLUSH_INTERVAL)
762763
env.flushMinSpans = maybeInt(DD_TRACE_PARTIAL_FLUSH_MIN_SPANS)
763764
this.#envUnprocessed.flushMinSpans = DD_TRACE_PARTIAL_FLUSH_MIN_SPANS
764765
this.#setBoolean(env, 'gitMetadataEnabled', DD_TRACE_GIT_METADATA_ENABLED)

packages/dd-trace/src/supported-configurations.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
"DD_TRACE_FASTIFY_ENABLED": ["A"],
283283
"DD_TRACE_FETCH_ENABLED": ["A"],
284284
"DD_TRACE_FIND_MY_WAY_ENABLED": ["A"],
285+
"DD_TRACE_FLUSH_INTERVAL": ["A"],
285286
"DD_TRACE_FS_ENABLED": ["A"],
286287
"DD_TRACE_GENERIC_POOL_ENABLED": ["A"],
287288
"DD_TRACE_GIT_METADATA_ENABLED": ["A"],

packages/dd-trace/test/config.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,7 @@ describe('Config', () => {
15031503
process.env.DD_TRACE_GLOBAL_TAGS = 'foo:bar,baz:qux'
15041504
process.env.DD_TRACE_MIDDLEWARE_TRACING_ENABLED = 'false'
15051505
process.env.DD_TRACE_PARTIAL_FLUSH_MIN_SPANS = '2000'
1506+
process.env.DD_TRACE_FLUSH_INTERVAL = '2000'
15061507
process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'false'
15071508
process.env.DD_TRACE_PEER_SERVICE_MAPPING = 'c:cc'
15081509
process.env.DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT = 'restart'
@@ -1583,6 +1584,7 @@ describe('Config', () => {
15831584
enableGetRumData: false
15841585
},
15851586
flushMinSpans: 500,
1587+
flushInterval: 500,
15861588
hostname: 'server',
15871589
iast: {
15881590
dbRowsToTaint: 3,
@@ -1673,6 +1675,7 @@ describe('Config', () => {
16731675
expect(config).to.have.nested.property('experimental.enableGetRumData', false)
16741676
expect(config).to.have.nested.property('experimental.exporter', 'agent')
16751677
expect(config).to.have.property('flushMinSpans', 500)
1678+
expect(config).to.have.property('flushInterval', 500)
16761679
expect(config).to.have.nested.property('iast.dbRowsToTaint', 3)
16771680
expect(config).to.have.nested.property('iast.deduplicationEnabled', true)
16781681
expect(config).to.have.nested.property('iast.enabled', true)

0 commit comments

Comments
 (0)