From 8bf0769d63f787990217ecbfde3f85b402ca7926 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 17 Nov 2025 09:44:14 -0500 Subject: [PATCH 01/18] initial --- .../src/producer.js | 18 +++++++++++++----- .../test/integration-test/client.spec.js | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/datadog-plugin-azure-event-hubs/src/producer.js b/packages/datadog-plugin-azure-event-hubs/src/producer.js index 44e38aba99d..b13f09ebb68 100644 --- a/packages/datadog-plugin-azure-event-hubs/src/producer.js +++ b/packages/datadog-plugin-azure-event-hubs/src/producer.js @@ -2,7 +2,7 @@ const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper') const ProducerPlugin = require('../../dd-trace/src/plugins/producer') - +const spanContexts = new WeakMap() class AzureEventHubsProducerPlugin extends ProducerPlugin { static get id () { return 'azure-event-hubs' } static get operation () { return 'send' } @@ -36,7 +36,12 @@ class AzureEventHubsProducerPlugin extends ProducerPlugin { } if (batchLinksAreEnabled()) { - ctx.batch._spanContexts.push(span.context()) + const spanContext = spanContexts.get(ctx.batch) + if (spanContext) { + spanContext.push(span.context()) + } else { + spanContexts.set(ctx.batch, [span.context()]) + } injectTraceContext(this.tracer, span, ctx.eventData) } } @@ -53,9 +58,12 @@ class AzureEventHubsProducerPlugin extends ProducerPlugin { }) } else { if (batchLinksAreEnabled()) { - eventData._spanContexts.forEach(spanContext => { - span.addLink(spanContext) - }) + const contexts = spanContexts.get(eventData) + if (contexts) { + for (const spanContext of contexts) { + span.addLink(spanContext) + } + } } } } diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js index 6cedeb8dd43..32f24d5668e 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ const { withVersions } = require('../../../dd-trace/test/setup/mocha') const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' } // TODO: Fix this test / esm issue -describe.skip('esm', () => { +describe('esm', () => { let agent let proc From ab4ce0d7211842681f013d522c03bac2a3669732 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 17 Nov 2025 09:44:55 -0500 Subject: [PATCH 02/18] skip this test --- .../test/integration-test/client.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js index 32f24d5668e..6cedeb8dd43 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ const { withVersions } = require('../../../dd-trace/test/setup/mocha') const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' } // TODO: Fix this test / esm issue -describe('esm', () => { +describe.skip('esm', () => { let agent let proc From 24b049cf56e00b7412b3fb1c1e8f059dcc01a946 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 11 Dec 2025 16:26:34 -0500 Subject: [PATCH 03/18] fix patching and test --- .../datadog-instrumentations/src/azure-event-hubs.js | 10 ++++++++-- .../datadog-plugin-azure-event-hubs/src/producer.js | 4 ++++ .../test/integration-test/client.spec.js | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/datadog-instrumentations/src/azure-event-hubs.js b/packages/datadog-instrumentations/src/azure-event-hubs.js index 2d339bcc7f1..eea693707db 100644 --- a/packages/datadog-instrumentations/src/azure-event-hubs.js +++ b/packages/datadog-instrumentations/src/azure-event-hubs.js @@ -6,13 +6,19 @@ const { const shimmer = require('../../datadog-shimmer') const dc = require('dc-polyfill') +const isItDefault = new WeakSet() const producerCh = dc.tracingChannel('apm:azure-event-hubs:send') addHook({ name: '@azure/event-hubs', - versions: ['>=6.0.0'] + versions: ['>=6.0.0'], }, obj => { const EventHubProducerClient = obj.EventHubProducerClient + + if (!isItDefault.has(EventHubProducerClient.prototype)) { + isItDefault.add(EventHubProducerClient.prototype) + } + shimmer.wrap(EventHubProducerClient.prototype, 'createBatch', createBatch => async function () { const batch = await createBatch.apply(this, arguments) @@ -20,7 +26,7 @@ addHook({ tryAdd => function (eventData) { const config = this._context.config const functionName = tryAdd.name - return producerCh.tracePromise( + return producerCh.traceSync( tryAdd, { functionName, eventData, batch: this, config }, this, ...arguments) diff --git a/packages/datadog-plugin-azure-event-hubs/src/producer.js b/packages/datadog-plugin-azure-event-hubs/src/producer.js index b13f09ebb68..32a8da43f00 100644 --- a/packages/datadog-plugin-azure-event-hubs/src/producer.js +++ b/packages/datadog-plugin-azure-event-hubs/src/producer.js @@ -73,6 +73,10 @@ class AzureEventHubsProducerPlugin extends ProducerPlugin { asyncEnd (ctx) { super.finish() } + + end (ctx) { + super.finish() + } } function injectTraceContext (tracer, span, event) { diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js index 6cedeb8dd43..32f24d5668e 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ const { withVersions } = require('../../../dd-trace/test/setup/mocha') const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' } // TODO: Fix this test / esm issue -describe.skip('esm', () => { +describe('esm', () => { let agent let proc From 1032aceac7d4830c80d1f56087f73e2cc1a40d8b Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 12 Dec 2025 09:57:16 -0500 Subject: [PATCH 04/18] try patch default --- packages/datadog-instrumentations/src/azure-event-hubs.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/datadog-instrumentations/src/azure-event-hubs.js b/packages/datadog-instrumentations/src/azure-event-hubs.js index eea693707db..c0c4e22495d 100644 --- a/packages/datadog-instrumentations/src/azure-event-hubs.js +++ b/packages/datadog-instrumentations/src/azure-event-hubs.js @@ -6,19 +6,14 @@ const { const shimmer = require('../../datadog-shimmer') const dc = require('dc-polyfill') -const isItDefault = new WeakSet() const producerCh = dc.tracingChannel('apm:azure-event-hubs:send') addHook({ name: '@azure/event-hubs', versions: ['>=6.0.0'], + patchDefault: false }, obj => { const EventHubProducerClient = obj.EventHubProducerClient - - if (!isItDefault.has(EventHubProducerClient.prototype)) { - isItDefault.add(EventHubProducerClient.prototype) - } - shimmer.wrap(EventHubProducerClient.prototype, 'createBatch', createBatch => async function () { const batch = await createBatch.apply(this, arguments) From 40b037f720c4452b34644b2edf45914ea25fc212 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 12 Dec 2025 10:45:42 -0500 Subject: [PATCH 05/18] remove patchdefault --- .../datadog-instrumentations/src/azure-event-hubs.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/datadog-instrumentations/src/azure-event-hubs.js b/packages/datadog-instrumentations/src/azure-event-hubs.js index c0c4e22495d..7c7000c2105 100644 --- a/packages/datadog-instrumentations/src/azure-event-hubs.js +++ b/packages/datadog-instrumentations/src/azure-event-hubs.js @@ -6,14 +6,19 @@ const { const shimmer = require('../../datadog-shimmer') const dc = require('dc-polyfill') +const isItDefault = new WeakSet() const producerCh = dc.tracingChannel('apm:azure-event-hubs:send') addHook({ name: '@azure/event-hubs', - versions: ['>=6.0.0'], - patchDefault: false + versions: ['>=6.0.0'] }, obj => { const EventHubProducerClient = obj.EventHubProducerClient + + if (!isItDefault.has(EventHubProducerClient.prototype)) { + isItDefault.add(EventHubProducerClient.prototype) + } + shimmer.wrap(EventHubProducerClient.prototype, 'createBatch', createBatch => async function () { const batch = await createBatch.apply(this, arguments) From 0158c73261965f5b1436e62161ee360aae1c5739 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 Dec 2025 11:38:09 -0500 Subject: [PATCH 06/18] add experimental crypto for node18 --- integration-tests/helpers/index.js | 8 ++++++-- .../test/integration-test/client.spec.js | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index 4aa5b7d257a..82987c08326 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -563,6 +563,8 @@ function checkSpansForServiceName (spans, name) { * @param {string} serverFile * @param {string|number} agentPort * @param {Record} [additionalEnvArgs] + * @param {string} [additionalNodeOptions] [additionalNodeOptions] + * */ /** * @param {string} cwd @@ -570,15 +572,17 @@ function checkSpansForServiceName (spans, name) { * @param {string|number} agentPort * @param {(data: Buffer) => void} [stdioHandler] * @param {Record} [additionalEnvArgs] + * @param {string} [additionalNodeOptions] */ -async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs) { +async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs, additionalNodeOptions) { if (typeof stdioHandler !== 'function' && !additionalEnvArgs) { additionalEnvArgs = stdioHandler stdioHandler = undefined } additionalEnvArgs = additionalEnvArgs || {} + additionalNodeOptions = additionalNodeOptions || '' let env = /** @type {Record} */ ({ - NODE_OPTIONS: `--loader=${hookFile}`, + NODE_OPTIONS: `--loader=${hookFile} ${additionalNodeOptions}`, DD_TRACE_AGENT_PORT: String(agentPort), DD_TRACE_FLUSH_INTERVAL: '0' }) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js index 32f24d5668e..154d7b106de 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js @@ -13,7 +13,11 @@ const { } = require('../../../../integration-tests/helpers') const { withVersions } = require('../../../dd-trace/test/setup/mocha') -const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' } +const spawnEnv = { + DD_TRACE_FLUSH_INTERVAL: '2000', +} + +const nodeOptions = '--experimental-global-webcrypto' // TODO: Fix this test / esm issue describe('esm', () => { @@ -41,7 +45,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'azure.eventhubs.send'), true) }) - proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, spawnEnv) + proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions) await res }).timeout(20000) @@ -108,7 +112,7 @@ describe('esm', () => { assert.strictEqual(parseLinks(payload[4][0]).length, 2) }) - proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, spawnEnv) + proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions) await res }).timeout(60000) @@ -117,7 +121,7 @@ describe('esm', () => { assert.ok(!('_dd.span_links' in payload[2][0])) }) const envVar = { DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED: 'false', ...spawnEnv } - proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, envVar) + proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, undefined, envVar, nodeOptions) await res }).timeout(60000) }) From 80544e1678fd45c3ea74250aa08a7c2c8b363c09 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 Dec 2025 11:49:36 -0500 Subject: [PATCH 07/18] lint --- integration-tests/helpers/index.js | 14 ++++++++------ .../test/integration-test/client.spec.js | 12 +++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index 82987c08326..2758fc8c834 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -64,7 +64,7 @@ async function runAndCheckOutput (filename, cwd, expectedOut, expectedSource) { if (expectedSource) { assert.match(out, new RegExp(`instrumentation source: ${expectedSource}`), - `Expected the process to output "${expectedSource}", but logs only contain: "${out}"`) + `Expected the process to output "${expectedSource}", but logs only contain: "${out}"`) } return pid } @@ -87,9 +87,9 @@ async function runAndCheckWithTelemetry (filename, expectedOut, expectedTelemetr const msgs = await cleanup() if (expectedTelemetryPoints.length === 0) { // assert no telemetry sent - assert.strictEqual(msgs.length, 0, `Expected no telemetry, but got:\n${ - msgs.map(msg => JSON.stringify(msg[1].points)).join('\n') - }`) + assert.strictEqual( + msgs.length, 0, `Expected no telemetry, but got:\n${msgs.map(msg => JSON.stringify(msg[1].points)).join('\n')}` + ) } else { assertTelemetryPoints(pid, msgs, expectedTelemetryPoints) } @@ -292,7 +292,7 @@ async function createSandbox ( execHelper('yarn link') execHelper('yarn link dd-trace') // ... run the tests in the current directory. - return { folder: path.join(process.cwd(), 'integration-tests'), remove: async () => {} } + return { folder: path.join(process.cwd(), 'integration-tests'), remove: async () => { } } } const folder = path.join(sandboxRoot, id().toString()) const out = path.join(sandboxRoot, 'dd-trace.tgz') @@ -574,7 +574,9 @@ function checkSpansForServiceName (spans, name) { * @param {Record} [additionalEnvArgs] * @param {string} [additionalNodeOptions] */ -async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs, additionalNodeOptions) { +async function spawnPluginIntegrationTestProc ( + cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs, additionalNodeOptions +) { if (typeof stdioHandler !== 'function' && !additionalEnvArgs) { additionalEnvArgs = stdioHandler stdioHandler = undefined diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js index 154d7b106de..24e015c9cc0 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js @@ -45,7 +45,9 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'azure.eventhubs.send'), true) }) - proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions) + proc = await spawnPluginIntegrationTestProc( + sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions + ) await res }).timeout(20000) @@ -112,7 +114,9 @@ describe('esm', () => { assert.strictEqual(parseLinks(payload[4][0]).length, 2) }) - proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions) + proc = await spawnPluginIntegrationTestProc( + sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions + ) await res }).timeout(60000) @@ -121,7 +125,9 @@ describe('esm', () => { assert.ok(!('_dd.span_links' in payload[2][0])) }) const envVar = { DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED: 'false', ...spawnEnv } - proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, undefined, envVar, nodeOptions) + proc = await spawnPluginIntegrationTestProc( + sandboxCwd(), 'server.mjs', agent.port, undefined, envVar, nodeOptions + ) await res }).timeout(60000) }) From e65f2b961beeebe109a71a93593f7febaad026ad Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 Dec 2025 16:09:06 -0500 Subject: [PATCH 08/18] fix incorrect path --- .../client.spec.js | 51 +++++++++++++++++++ .../batchSpanContextRegressionTest/server.mjs | 29 +++++++++++ .../{ => core-test}/client.spec.js | 6 +-- .../{ => core-test}/server.mjs | 0 .../tryAddRegressionTest/client.spec.js | 51 +++++++++++++++++++ .../tryAddRegressionTest/server.mjs | 49 ++++++++++++++++++ 6 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js create mode 100644 packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/server.mjs rename packages/datadog-plugin-azure-event-hubs/test/integration-test/{ => core-test}/client.spec.js (96%) rename packages/datadog-plugin-azure-event-hubs/test/integration-test/{ => core-test}/server.mjs (100%) create mode 100644 packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js create mode 100644 packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/server.mjs diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js new file mode 100644 index 00000000000..ed70c01d247 --- /dev/null +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js @@ -0,0 +1,51 @@ +'use strict' + +const { + FakeAgent, + sandboxCwd, + useSandbox, + spawnPluginIntegrationTestProc +} = require('../../../../../integration-tests/helpers') +const { withVersions } = require('../../../../dd-trace/test/setup/mocha') +const assert = require('assert') + +const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' } +const nodeOptions = '--experimental-global-webcrypto' + +describe('esm', () => { + let agent + let proc + + withVersions('azure-event-hubs', '@azure/event-hubs', version => { + useSandbox([`'@azure/event-hubs@${version}'`], false, [ + './packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/*']) + + beforeEach(async () => { + agent = await new FakeAgent().start() + process.env.DD_TRACE_DISABLED_PLUGINS = 'amqplib,amqp10,rhea,net' + }) + + afterEach(async () => { + proc && proc.kill() + await agent.stop() + }) + + it('tryAdd does not set context in the Azure eventDataBatch._spanContext', async () => { + const res = agent.assertMessageReceived(({ headers, payload }) => { + assert.ok(Array.isArray(payload)) + assert.strictEqual(payload.length, 3) + // Verify we got the expected spans from the test + assert.strictEqual(payload[0][0].name, 'azure.eventhubs.create') + assert.strictEqual(payload[1][0].name, 'azure.eventhubs.create') + assert.strictEqual(payload[2][0].name, 'azure.eventhubs.send') + }) + + // This test file will throw an error if tryAdd returns a Promise instead of a boolean + proc = await spawnPluginIntegrationTestProc( + sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions + ) + + await res + }).timeout(60000) + }) +}) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/server.mjs b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/server.mjs new file mode 100644 index 00000000000..15b63e7a05f --- /dev/null +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/server.mjs @@ -0,0 +1,29 @@ +import 'dd-trace/init.js' +import { EventHubProducerClient } from '@azure/event-hubs' + +const connectionString = 'Endpoint=sb://127.0.0.1:5673;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;' +const eventHubName = 'eh1' + +const producer = new EventHubProducerClient(connectionString, eventHubName) + +const events = [ + { body: 'Test event 1' }, + { body: 'Test event 2' } +] + +// Test that tryAdd returns a boolean, not a Promise +const batch = await producer.createBatch() + +batch.tryAdd(events[0]) +batch.tryAdd(events[1]) + +if (batch._spanContexts.length !== 0) { + throw new Error( + "We should not be using Azure's eventDataBatchspan context. Please use the weak map instead." + ) +} + +// Send the batch to complete the operation +await producer.sendBatch(batch) + +await producer.close() diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js similarity index 96% rename from packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js rename to packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js index 24e015c9cc0..28c73aa7915 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js @@ -10,8 +10,8 @@ const { assertObjectContains, checkSpansForServiceName, spawnPluginIntegrationTestProc -} = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') +} = require('../../../../../integration-tests/helpers') +const { withVersions } = require('../../../../dd-trace/test/setup/mocha') const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000', @@ -26,7 +26,7 @@ describe('esm', () => { withVersions('azure-event-hubs', '@azure/event-hubs', version => { useSandbox([`'@azure/event-hubs@${version}'`], false, [ - './packages/datadog-plugin-azure-event-hubs/test/integration-test/*']) + './packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/*']) beforeEach(async () => { agent = await new FakeAgent().start() diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/server.mjs b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/server.mjs similarity index 100% rename from packages/datadog-plugin-azure-event-hubs/test/integration-test/server.mjs rename to packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/server.mjs diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js new file mode 100644 index 00000000000..36d9f18f195 --- /dev/null +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js @@ -0,0 +1,51 @@ +'use strict' + +const { + FakeAgent, + sandboxCwd, + useSandbox, + spawnPluginIntegrationTestProc +} = require('../../../../../integration-tests/helpers') +const { withVersions } = require('../../../../dd-trace/test/setup/mocha') +const assert = require('assert') + +const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' } +const nodeOptions = '--experimental-global-webcrypto' + +describe('esm', () => { + let agent + let proc + + withVersions('azure-event-hubs', '@azure/event-hubs', version => { + useSandbox([`'@azure/event-hubs@${version}'`], false, [ + './packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/*']) + + beforeEach(async () => { + agent = await new FakeAgent().start() + process.env.DD_TRACE_DISABLED_PLUGINS = 'amqplib,amqp10,rhea,net' + }) + + afterEach(async () => { + proc && proc.kill() + await agent.stop() + }) + + it('tryAdd returns a boolean, not a Promise', async () => { + const res = agent.assertMessageReceived(({ headers, payload }) => { + assert.ok(Array.isArray(payload)) + assert.strictEqual(payload.length, 3) + // Verify we got the expected spans from the test + assert.strictEqual(payload[0][0].name, 'azure.eventhubs.create') + assert.strictEqual(payload[1][0].name, 'azure.eventhubs.create') + assert.strictEqual(payload[2][0].name, 'azure.eventhubs.send') + }) + + // This test file will throw an error if tryAdd returns a Promise instead of a boolean + proc = await spawnPluginIntegrationTestProc( + sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions + ) + + await res + }).timeout(60000) + }) +}) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/server.mjs b/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/server.mjs new file mode 100644 index 00000000000..4c24f27bd3c --- /dev/null +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/server.mjs @@ -0,0 +1,49 @@ +import 'dd-trace/init.js' +import { EventHubProducerClient } from '@azure/event-hubs' + +const connectionString = 'Endpoint=sb://127.0.0.1:5673;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;' +const eventHubName = 'eh1' + +const producer = new EventHubProducerClient(connectionString, eventHubName) + +const events = [ + { body: 'Test event 1' }, + { body: 'Test event 2' } +] + +// Test that tryAdd returns a boolean, not a Promise +const batch = await producer.createBatch() + +const result1 = batch.tryAdd(events[0]) +const result2 = batch.tryAdd(events[1]) + +// Verify the return types - throw error if not correct +if (typeof result1 !== 'boolean') { + throw new Error(`tryAdd should return a boolean, but returned ${typeof result1}`) +} + +if (result1 instanceof Promise) { + throw new Error('tryAdd should not return a Promise') +} + +if (typeof result2 !== 'boolean') { + throw new Error(`tryAdd should return a boolean, but returned ${typeof result2}`) +} + +if (result2 instanceof Promise) { + throw new Error('tryAdd should not return a Promise') +} + +// Verify the values are correct +if (result1 !== true) { + throw new Error(`Expected first tryAdd to return true, got ${result1}`) +} + +if (result2 !== true) { + throw new Error(`Expected second tryAdd to return true, got ${result2}`) +} + +// Send the batch to complete the operation +await producer.sendBatch(batch) + +await producer.close() From 34d77464aadcadb3c6337f652cf66c32d1010ccd Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 5 Jan 2026 14:16:54 -0500 Subject: [PATCH 09/18] comments and nits --- integration-tests/helpers/index.js | 15 ++++++++++----- .../src/azure-event-hubs.js | 5 ----- .../src/producer.js | 6 ++++-- .../batchSpanContextRegressionTest/client.spec.js | 7 ++----- .../integration-test/core-test/client.spec.js | 14 ++++---------- .../tryAddRegressionTest/client.spec.js | 5 ++--- 6 files changed, 22 insertions(+), 30 deletions(-) diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index 2758fc8c834..979404c56da 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -563,7 +563,6 @@ function checkSpansForServiceName (spans, name) { * @param {string} serverFile * @param {string|number} agentPort * @param {Record} [additionalEnvArgs] - * @param {string} [additionalNodeOptions] [additionalNodeOptions] * */ /** @@ -572,17 +571,23 @@ function checkSpansForServiceName (spans, name) { * @param {string|number} agentPort * @param {(data: Buffer) => void} [stdioHandler] * @param {Record} [additionalEnvArgs] - * @param {string} [additionalNodeOptions] + * */ async function spawnPluginIntegrationTestProc ( - cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs, additionalNodeOptions -) { + cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs) { if (typeof stdioHandler !== 'function' && !additionalEnvArgs) { additionalEnvArgs = stdioHandler stdioHandler = undefined } additionalEnvArgs = additionalEnvArgs || {} - additionalNodeOptions = additionalNodeOptions || '' + + // must delete the node options from the additional env args or it breaks spawnProc + let additionalNodeOptions = '' + if (additionalEnvArgs.NODE_OPTIONS !== undefined) { + additionalNodeOptions = additionalEnvArgs.NODE_OPTIONS + delete additionalEnvArgs.NODE_OPTIONS + } + let env = /** @type {Record} */ ({ NODE_OPTIONS: `--loader=${hookFile} ${additionalNodeOptions}`, DD_TRACE_AGENT_PORT: String(agentPort), diff --git a/packages/datadog-instrumentations/src/azure-event-hubs.js b/packages/datadog-instrumentations/src/azure-event-hubs.js index 7c7000c2105..b636c9e42d1 100644 --- a/packages/datadog-instrumentations/src/azure-event-hubs.js +++ b/packages/datadog-instrumentations/src/azure-event-hubs.js @@ -6,7 +6,6 @@ const { const shimmer = require('../../datadog-shimmer') const dc = require('dc-polyfill') -const isItDefault = new WeakSet() const producerCh = dc.tracingChannel('apm:azure-event-hubs:send') addHook({ @@ -15,10 +14,6 @@ addHook({ }, obj => { const EventHubProducerClient = obj.EventHubProducerClient - if (!isItDefault.has(EventHubProducerClient.prototype)) { - isItDefault.add(EventHubProducerClient.prototype) - } - shimmer.wrap(EventHubProducerClient.prototype, 'createBatch', createBatch => async function () { const batch = await createBatch.apply(this, arguments) diff --git a/packages/datadog-plugin-azure-event-hubs/src/producer.js b/packages/datadog-plugin-azure-event-hubs/src/producer.js index 32a8da43f00..5867edc2e5a 100644 --- a/packages/datadog-plugin-azure-event-hubs/src/producer.js +++ b/packages/datadog-plugin-azure-event-hubs/src/producer.js @@ -2,7 +2,9 @@ const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper') const ProducerPlugin = require('../../dd-trace/src/plugins/producer') + const spanContexts = new WeakMap() + class AzureEventHubsProducerPlugin extends ProducerPlugin { static get id () { return 'azure-event-hubs' } static get operation () { return 'send' } @@ -71,11 +73,11 @@ class AzureEventHubsProducerPlugin extends ProducerPlugin { } asyncEnd (ctx) { - super.finish() + super.finish(ctx) } end (ctx) { - super.finish() + super.finish(ctx) } } diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js index ed70c01d247..f835014ecbd 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js @@ -9,8 +9,7 @@ const { const { withVersions } = require('../../../../dd-trace/test/setup/mocha') const assert = require('assert') -const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' } -const nodeOptions = '--experimental-global-webcrypto' +const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' } describe('esm', () => { let agent @@ -42,9 +41,7 @@ describe('esm', () => { // This test file will throw an error if tryAdd returns a Promise instead of a boolean proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions - ) - + sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv) await res }).timeout(60000) }) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js index 28c73aa7915..0a99174470e 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js @@ -14,12 +14,9 @@ const { const { withVersions } = require('../../../../dd-trace/test/setup/mocha') const spawnEnv = { - DD_TRACE_FLUSH_INTERVAL: '2000', + DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' } -const nodeOptions = '--experimental-global-webcrypto' - -// TODO: Fix this test / esm issue describe('esm', () => { let agent let proc @@ -46,8 +43,7 @@ describe('esm', () => { }) proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions - ) + sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv) await res }).timeout(20000) @@ -115,8 +111,7 @@ describe('esm', () => { }) proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions - ) + sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv) await res }).timeout(60000) @@ -126,8 +121,7 @@ describe('esm', () => { }) const envVar = { DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED: 'false', ...spawnEnv } proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, envVar, nodeOptions - ) + sandboxCwd(), 'server.mjs', agent.port, undefined, envVar) await res }).timeout(60000) }) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js index 36d9f18f195..8b2bbc462aa 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js @@ -9,8 +9,7 @@ const { const { withVersions } = require('../../../../dd-trace/test/setup/mocha') const assert = require('assert') -const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000' } -const nodeOptions = '--experimental-global-webcrypto' +const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' } describe('esm', () => { let agent @@ -42,7 +41,7 @@ describe('esm', () => { // This test file will throw an error if tryAdd returns a Promise instead of a boolean proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv, nodeOptions + sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv ) await res From 0baaa0ddfe82d0241f891a9ff87e08fdc1c512ae Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 5 Jan 2026 15:29:04 -0500 Subject: [PATCH 10/18] fix test for node 18 --- .../batchSpanContextRegressionTest/client.spec.js | 4 ++-- .../test/integration-test/core-test/client.spec.js | 6 ++---- .../integration-test/tryAddRegressionTest/client.spec.js | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js index f835014ecbd..16597063edc 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js @@ -9,11 +9,10 @@ const { const { withVersions } = require('../../../../dd-trace/test/setup/mocha') const assert = require('assert') -const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' } - describe('esm', () => { let agent let proc + let spawnEnv withVersions('azure-event-hubs', '@azure/event-hubs', version => { useSandbox([`'@azure/event-hubs@${version}'`], false, [ @@ -22,6 +21,7 @@ describe('esm', () => { beforeEach(async () => { agent = await new FakeAgent().start() process.env.DD_TRACE_DISABLED_PLUGINS = 'amqplib,amqp10,rhea,net' + spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' } }) afterEach(async () => { diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js index 0a99174470e..2864e0f4e9e 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js @@ -13,13 +13,10 @@ const { } = require('../../../../../integration-tests/helpers') const { withVersions } = require('../../../../dd-trace/test/setup/mocha') -const spawnEnv = { - DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' -} - describe('esm', () => { let agent let proc + let spawnEnv withVersions('azure-event-hubs', '@azure/event-hubs', version => { useSandbox([`'@azure/event-hubs@${version}'`], false, [ @@ -28,6 +25,7 @@ describe('esm', () => { beforeEach(async () => { agent = await new FakeAgent().start() process.env.DD_TRACE_DISABLED_PLUGINS = 'amqplib,amqp10,rhea,net' + spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' } }) afterEach(async () => { diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js index 8b2bbc462aa..a628f22312a 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/tryAddRegressionTest/client.spec.js @@ -9,11 +9,10 @@ const { const { withVersions } = require('../../../../dd-trace/test/setup/mocha') const assert = require('assert') -const spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' } - describe('esm', () => { let agent let proc + let spawnEnv withVersions('azure-event-hubs', '@azure/event-hubs', version => { useSandbox([`'@azure/event-hubs@${version}'`], false, [ @@ -22,6 +21,7 @@ describe('esm', () => { beforeEach(async () => { agent = await new FakeAgent().start() process.env.DD_TRACE_DISABLED_PLUGINS = 'amqplib,amqp10,rhea,net' + spawnEnv = { DD_TRACE_FLUSH_INTERVAL: '2000', NODE_OPTIONS: '--experimental-global-webcrypto' } }) afterEach(async () => { From b42e8c7a8524ded54142e359be1937c29bb12838 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jan 2026 09:47:34 -0500 Subject: [PATCH 11/18] remove unnecessary lint fix --- integration-tests/helpers/index.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index 979404c56da..58f59092e5f 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -64,7 +64,7 @@ async function runAndCheckOutput (filename, cwd, expectedOut, expectedSource) { if (expectedSource) { assert.match(out, new RegExp(`instrumentation source: ${expectedSource}`), - `Expected the process to output "${expectedSource}", but logs only contain: "${out}"`) + `Expected the process to output "${expectedSource}", but logs only contain: "${out}"`) } return pid } @@ -87,9 +87,9 @@ async function runAndCheckWithTelemetry (filename, expectedOut, expectedTelemetr const msgs = await cleanup() if (expectedTelemetryPoints.length === 0) { // assert no telemetry sent - assert.strictEqual( - msgs.length, 0, `Expected no telemetry, but got:\n${msgs.map(msg => JSON.stringify(msg[1].points)).join('\n')}` - ) + assert.strictEqual(msgs.length, 0, `Expected no telemetry, but got:\n${ + msgs.map(msg => JSON.stringify(msg[1].points)).join('\n') + }`) } else { assertTelemetryPoints(pid, msgs, expectedTelemetryPoints) } @@ -292,7 +292,7 @@ async function createSandbox ( execHelper('yarn link') execHelper('yarn link dd-trace') // ... run the tests in the current directory. - return { folder: path.join(process.cwd(), 'integration-tests'), remove: async () => { } } + return { folder: path.join(process.cwd(), 'integration-tests'), remove: async () => {} } } const folder = path.join(sandboxRoot, id().toString()) const out = path.join(sandboxRoot, 'dd-trace.tgz') @@ -563,33 +563,21 @@ function checkSpansForServiceName (spans, name) { * @param {string} serverFile * @param {string|number} agentPort * @param {Record} [additionalEnvArgs] - * - */ /** * @param {string} cwd * @param {string} serverFile * @param {string|number} agentPort * @param {(data: Buffer) => void} [stdioHandler] * @param {Record} [additionalEnvArgs] - * */ -async function spawnPluginIntegrationTestProc ( - cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs) { +async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs) { if (typeof stdioHandler !== 'function' && !additionalEnvArgs) { additionalEnvArgs = stdioHandler stdioHandler = undefined } additionalEnvArgs = additionalEnvArgs || {} - - // must delete the node options from the additional env args or it breaks spawnProc - let additionalNodeOptions = '' - if (additionalEnvArgs.NODE_OPTIONS !== undefined) { - additionalNodeOptions = additionalEnvArgs.NODE_OPTIONS - delete additionalEnvArgs.NODE_OPTIONS - } - let env = /** @type {Record} */ ({ - NODE_OPTIONS: `--loader=${hookFile} ${additionalNodeOptions}`, + NODE_OPTIONS: `--loader=${hookFile}`, DD_TRACE_AGENT_PORT: String(agentPort), DD_TRACE_FLUSH_INTERVAL: '0' }) From 121ef67d8dca995b1017a755397c7fedb4542aea Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jan 2026 09:49:26 -0500 Subject: [PATCH 12/18] nit --- integration-tests/helpers/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index 58f59092e5f..4aa5b7d257a 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -563,6 +563,7 @@ function checkSpansForServiceName (spans, name) { * @param {string} serverFile * @param {string|number} agentPort * @param {Record} [additionalEnvArgs] + */ /** * @param {string} cwd * @param {string} serverFile From 8cdf1d8860a80d10f56c4a28a259ee9b830613e2 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jan 2026 09:51:28 -0500 Subject: [PATCH 13/18] readd node option logic --- integration-tests/helpers/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index 4aa5b7d257a..e19e4aafeb5 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -571,14 +571,23 @@ function checkSpansForServiceName (spans, name) { * @param {(data: Buffer) => void} [stdioHandler] * @param {Record} [additionalEnvArgs] */ -async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs) { +async function spawnPluginIntegrationTestProc ( + cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs) { if (typeof stdioHandler !== 'function' && !additionalEnvArgs) { additionalEnvArgs = stdioHandler stdioHandler = undefined } additionalEnvArgs = additionalEnvArgs || {} + + // must delete the node options from the additional env args or it breaks spawnProc + let additionalNodeOptions = '' + if (additionalEnvArgs.NODE_OPTIONS !== undefined) { + additionalNodeOptions = additionalEnvArgs.NODE_OPTIONS + delete additionalEnvArgs.NODE_OPTIONS + } + let env = /** @type {Record} */ ({ - NODE_OPTIONS: `--loader=${hookFile}`, + NODE_OPTIONS: `--loader=${hookFile} ${additionalNodeOptions}`, DD_TRACE_AGENT_PORT: String(agentPort), DD_TRACE_FLUSH_INTERVAL: '0' }) From bbf2a5acdbb0b78450779009fc5dc2743aec6851 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jan 2026 16:21:32 -0500 Subject: [PATCH 14/18] fix fastify test --- integration-tests/helpers/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index e19e4aafeb5..eb4f6562c5d 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -577,17 +577,20 @@ async function spawnPluginIntegrationTestProc ( additionalEnvArgs = stdioHandler stdioHandler = undefined } - additionalEnvArgs = additionalEnvArgs || {} + additionalEnvArgs = { ...additionalEnvArgs } - // must delete the node options from the additional env args or it breaks spawnProc - let additionalNodeOptions = '' + let NODE_OPTIONS = `--loader=${hookFile}` if (additionalEnvArgs.NODE_OPTIONS !== undefined) { - additionalNodeOptions = additionalEnvArgs.NODE_OPTIONS + if (additionalEnvArgs.NODE_OPTIONS.includes('--loader=')) { + NODE_OPTIONS = additionalEnvArgs.NODE_OPTIONS + } else { + NODE_OPTIONS += ` ${additionalEnvArgs.NODE_OPTIONS}` + } delete additionalEnvArgs.NODE_OPTIONS } let env = /** @type {Record} */ ({ - NODE_OPTIONS: `--loader=${hookFile} ${additionalNodeOptions}`, + NODE_OPTIONS, DD_TRACE_AGENT_PORT: String(agentPort), DD_TRACE_FLUSH_INTERVAL: '0' }) From 820fa6bd68a8a9472148a80c3d09ed0dfd317f4f Mon Sep 17 00:00:00 2001 From: Jordan Storms Date: Tue, 6 Jan 2026 09:59:57 -0500 Subject: [PATCH 15/18] Update packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js Co-authored-by: Ruben Bridgewater --- .../test/integration-test/core-test/client.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js index 2864e0f4e9e..0e0d32b0846 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js @@ -40,8 +40,7 @@ describe('esm', () => { assert.strictEqual(checkSpansForServiceName(payload, 'azure.eventhubs.send'), true) }) - proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv) + proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, spawnEnv) await res }).timeout(20000) From 896ab998246f2f8aee8d548ce5f12b2fd7a7af73 Mon Sep 17 00:00:00 2001 From: Jordan Storms Date: Tue, 6 Jan 2026 10:00:26 -0500 Subject: [PATCH 16/18] Update packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js Co-authored-by: Ruben Bridgewater --- .../test/integration-test/core-test/client.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js index 0e0d32b0846..02a3d32e863 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js @@ -117,8 +117,7 @@ describe('esm', () => { assert.ok(!('_dd.span_links' in payload[2][0])) }) const envVar = { DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED: 'false', ...spawnEnv } - proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, envVar) + proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, envVar) await res }).timeout(60000) }) From 4f24fbee9e87a52f10962678e0e375283947a4df Mon Sep 17 00:00:00 2001 From: Jordan Storms Date: Tue, 6 Jan 2026 10:00:35 -0500 Subject: [PATCH 17/18] Update packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js Co-authored-by: Ruben Bridgewater --- .../test/integration-test/core-test/client.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js index 02a3d32e863..a0747e3671f 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/core-test/client.spec.js @@ -107,8 +107,7 @@ describe('esm', () => { assert.strictEqual(parseLinks(payload[4][0]).length, 2) }) - proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv) + proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, spawnEnv) await res }).timeout(60000) From 42c74233ae46d562746270e80f895fed0d496ef3 Mon Sep 17 00:00:00 2001 From: Jordan Storms Date: Tue, 6 Jan 2026 10:00:41 -0500 Subject: [PATCH 18/18] Update packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js Co-authored-by: Ruben Bridgewater --- integration-tests/helpers/index.js | 2 +- .../batchSpanContextRegressionTest/client.spec.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index eb4f6562c5d..0272105e009 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -581,7 +581,7 @@ async function spawnPluginIntegrationTestProc ( let NODE_OPTIONS = `--loader=${hookFile}` if (additionalEnvArgs.NODE_OPTIONS !== undefined) { - if (additionalEnvArgs.NODE_OPTIONS.includes('--loader=')) { + if (/--(loader|import)/.test(additionalEnvArgs.NODE_OPTIONS ?? '')) { NODE_OPTIONS = additionalEnvArgs.NODE_OPTIONS } else { NODE_OPTIONS += ` ${additionalEnvArgs.NODE_OPTIONS}` diff --git a/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js index 16597063edc..d8d9bbe1845 100644 --- a/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js +++ b/packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js @@ -40,8 +40,7 @@ describe('esm', () => { }) // This test file will throw an error if tryAdd returns a Promise instead of a boolean - proc = await spawnPluginIntegrationTestProc( - sandboxCwd(), 'server.mjs', agent.port, undefined, spawnEnv) + proc = await spawnPluginIntegrationTestProc(sandboxCwd(), 'server.mjs', agent.port, spawnEnv) await res }).timeout(60000) })