diff --git a/.github/workflows/appsec.yml b/.github/workflows/appsec.yml index 3a0cde972da..19470023010 100644 --- a/.github/workflows/appsec.yml +++ b/.github/workflows/appsec.yml @@ -209,6 +209,7 @@ jobs: version: - 18 - latest + range: ['9.5.0', '11.1.4', '13.2.0', '14.2.6'] runs-on: ubuntu-latest env: PLUGINS: next diff --git a/.github/workflows/plugins.yml b/.github/workflows/plugins.yml index 3cd18cddb8d..f464887e9e2 100644 --- a/.github/workflows/plugins.yml +++ b/.github/workflows/plugins.yml @@ -656,6 +656,7 @@ jobs: version: - 18 - latest + range: ['9.5.0', '11.1.4', '13.2.0', '14.2.6'] runs-on: ubuntu-latest env: PLUGINS: next @@ -868,7 +869,7 @@ jobs: runs-on: ubuntu-latest services: mssql: - image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu + image: mcr.microsoft.com/mssql/server:2019-latest env: ACCEPT_EULA: 'Y' SA_PASSWORD: DD_HUNTER2 diff --git a/integration-tests/ci-visibility/test-api-manual/test.fake.js b/integration-tests/ci-visibility/test-api-manual/test.fake.js index 11f35dd8e87..a3256bc6f42 100644 --- a/integration-tests/ci-visibility/test-api-manual/test.fake.js +++ b/integration-tests/ci-visibility/test-api-manual/test.fake.js @@ -31,7 +31,7 @@ describe('can run tests', () => { }) test('integration test', () => { // Just for testing purposes, so we don't create a custom span - if (!process.env.DD_CIVISIBILITY_MANUAL_API_ENABLED) { + if (process.env.DD_CIVISIBILITY_MANUAL_API_ENABLED === 'false') { return Promise.resolve() } const testSpan = tracer.scope().active() diff --git a/integration-tests/cucumber/cucumber.spec.js b/integration-tests/cucumber/cucumber.spec.js index 79295467ae7..bcf768883e8 100644 --- a/integration-tests/cucumber/cucumber.spec.js +++ b/integration-tests/cucumber/cucumber.spec.js @@ -38,6 +38,7 @@ const { TEST_SESSION_NAME, TEST_LEVEL_EVENT_TYPES } = require('../../packages/dd-trace/src/plugins/util/test') +const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env') const isOldNode = semver.satisfies(process.version, '<=16') const versions = ['7.0.0', isOldNode ? '9' : 'latest'] @@ -181,6 +182,7 @@ versions.forEach(version => { assert.equal(testSessionId.toString(10), testSessionEventContent.test_session_id.toString(10)) assert.isTrue(meta[TEST_SOURCE_FILE].startsWith(featuresPath)) assert.equal(metrics[TEST_SOURCE_START], 1) + assert.exists(metrics[DD_HOST_CPU_COUNT]) }) assert.includeMembers(testEvents.map(test => test.content.resource), [ @@ -201,6 +203,7 @@ versions.forEach(version => { testEvents.forEach(({ content: { meta, + metrics, test_suite_id: testSuiteId, test_module_id: testModuleId, test_session_id: testSessionId @@ -218,6 +221,7 @@ versions.forEach(version => { if (runMode === 'parallel') { assert.propertyVal(meta, CUCUMBER_IS_PARALLEL, 'true') } + assert.exists(metrics[DD_HOST_CPU_COUNT]) }) stepEvents.forEach(stepEvent => { @@ -233,7 +237,7 @@ versions.forEach(version => { env: { ...envVars, DD_TAGS: 'test.customtag:customvalue,test.customtag2:customvalue2', - DD_SESSION_NAME: 'my-test-session' + DD_TEST_SESSION_NAME: 'my-test-session' }, stdio: 'pipe' } diff --git a/integration-tests/cypress/cypress.spec.js b/integration-tests/cypress/cypress.spec.js index 6144618f6c3..afc79b2ebe5 100644 --- a/integration-tests/cypress/cypress.spec.js +++ b/integration-tests/cypress/cypress.spec.js @@ -37,6 +37,7 @@ const { TEST_SESSION_NAME, TEST_LEVEL_EVENT_TYPES } = require('../../packages/dd-trace/src/plugins/util/test') +const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env') const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants') const { NODE_MAJOR } = require('../../version') @@ -289,6 +290,7 @@ moduleTypes.forEach(({ assert.equal(testSessionId.toString(10), testSessionEventContent.test_session_id.toString(10)) assert.isTrue(meta[TEST_SOURCE_FILE].startsWith('cypress/e2e/')) assert.equal(metrics[TEST_SOURCE_START], 1) + assert.exists(metrics[DD_HOST_CPU_COUNT]) }) assert.includeMembers(testEvents.map(test => test.content.resource), [ @@ -306,6 +308,7 @@ moduleTypes.forEach(({ testEvents.forEach(({ content: { meta, + metrics, test_suite_id: testSuiteId, test_module_id: testModuleId, test_session_id: testSessionId @@ -320,6 +323,7 @@ moduleTypes.forEach(({ // Can read DD_TAGS assert.propertyVal(meta, 'test.customtag', 'customvalue') assert.propertyVal(meta, 'test.customtag2', 'customvalue2') + assert.exists(metrics[DD_HOST_CPU_COUNT]) }) }, 25000) @@ -336,7 +340,7 @@ moduleTypes.forEach(({ ...restEnvVars, CYPRESS_BASE_URL: `http://localhost:${webAppPort}`, DD_TAGS: 'test.customtag:customvalue,test.customtag2:customvalue2', - DD_SESSION_NAME: 'my-test-session' + DD_TEST_SESSION_NAME: 'my-test-session' }, stdio: 'pipe' } diff --git a/integration-tests/jest/jest.spec.js b/integration-tests/jest/jest.spec.js index fac07b540f2..789019100da 100644 --- a/integration-tests/jest/jest.spec.js +++ b/integration-tests/jest/jest.spec.js @@ -35,6 +35,7 @@ const { TEST_SESSION_NAME, TEST_LEVEL_EVENT_TYPES } = require('../../packages/dd-trace/src/plugins/util/test') +const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env') const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants') const testFile = 'ci-visibility/run-jest.js' @@ -169,11 +170,13 @@ describe('jest CommonJS', () => { // Can read DD_TAGS assert.propertyVal(testEvent.meta, 'test.customtag', 'customvalue') assert.propertyVal(testEvent.meta, 'test.customtag2', 'customvalue2') + assert.exists(testEvent.metrics[DD_HOST_CPU_COUNT]) }) suites.forEach(testSuite => { assert.isTrue(testSuite.meta[TEST_SOURCE_FILE].startsWith('ci-visibility/test/ci-visibility-test')) assert.equal(testSuite.metrics[TEST_SOURCE_START], 1) + assert.exists(testSuite.metrics[DD_HOST_CPU_COUNT]) }) done() @@ -184,7 +187,7 @@ describe('jest CommonJS', () => { env: { ...envVars, DD_TAGS: 'test.customtag:customvalue,test.customtag2:customvalue2', - DD_SESSION_NAME: 'my-test-session' + DD_TEST_SESSION_NAME: 'my-test-session' }, stdio: 'pipe' }) @@ -444,7 +447,7 @@ describe('jest CommonJS', () => { env: { ...getCiVisAgentlessConfig(receiver.port), RUN_IN_PARALLEL: true, - DD_SESSION_NAME: 'my-test-session' + DD_TEST_SESSION_NAME: 'my-test-session' }, stdio: 'pipe' }) diff --git a/integration-tests/mocha/mocha.spec.js b/integration-tests/mocha/mocha.spec.js index af3a1e827d1..e04dd85dad8 100644 --- a/integration-tests/mocha/mocha.spec.js +++ b/integration-tests/mocha/mocha.spec.js @@ -36,6 +36,7 @@ const { TEST_SESSION_NAME, TEST_LEVEL_EVENT_TYPES } = require('../../packages/dd-trace/src/plugins/util/test') +const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env') const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants') const runTestsWithCoverageCommand = './node_modules/nyc/bin/nyc.js -r=text-summary node ./ci-visibility/run-mocha.js' @@ -169,11 +170,13 @@ describe('mocha CommonJS', function () { // Can read DD_TAGS assert.propertyVal(testEvent.meta, 'test.customtag', 'customvalue') assert.propertyVal(testEvent.meta, 'test.customtag2', 'customvalue2') + assert.exists(testEvent.metrics[DD_HOST_CPU_COUNT]) }) suites.forEach(testSuite => { assert.isTrue(testSuite.meta[TEST_SOURCE_FILE].startsWith('ci-visibility/test/ci-visibility-test')) assert.equal(testSuite.metrics[TEST_SOURCE_START], 1) + assert.exists(testSuite.metrics[DD_HOST_CPU_COUNT]) }) done() @@ -184,7 +187,7 @@ describe('mocha CommonJS', function () { env: { ...envVars, DD_TAGS: 'test.customtag:customvalue,test.customtag2:customvalue2', - DD_SESSION_NAME: 'my-test-session' + DD_TEST_SESSION_NAME: 'my-test-session' }, stdio: 'pipe' }) @@ -378,7 +381,7 @@ describe('mocha CommonJS', function () { RUN_IN_PARALLEL: true, DD_TRACE_DEBUG: 1, DD_TRACE_LOG_LEVEL: 'warn', - DD_SESSION_NAME: 'my-test-session' + DD_TEST_SESSION_NAME: 'my-test-session' }, stdio: 'pipe' }) diff --git a/integration-tests/playwright/playwright.spec.js b/integration-tests/playwright/playwright.spec.js index 683969dce6b..440cf13d637 100644 --- a/integration-tests/playwright/playwright.spec.js +++ b/integration-tests/playwright/playwright.spec.js @@ -26,6 +26,7 @@ const { TEST_SESSION_NAME, TEST_LEVEL_EVENT_TYPES } = require('../../packages/dd-trace/src/plugins/util/test') +const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env') const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants') const NUM_RETRIES_EFD = 3 @@ -118,6 +119,7 @@ versions.forEach((version) => { } assert.isTrue(testSuiteEvent.content.meta[TEST_SOURCE_FILE].endsWith('-test.js')) assert.equal(testSuiteEvent.content.metrics[TEST_SOURCE_START], 1) + assert.exists(testSuiteEvent.content.metrics[DD_HOST_CPU_COUNT]) }) assert.includeMembers(testEvents.map(test => test.content.resource), [ @@ -145,6 +147,7 @@ versions.forEach((version) => { assert.propertyVal(testEvent.content.meta, 'test.customtag2', 'customvalue2') // Adds the browser used assert.propertyVal(testEvent.content.meta, TEST_CONFIGURATION_BROWSER_NAME, 'chromium') + assert.exists(testEvent.content.metrics[DD_HOST_CPU_COUNT]) }) stepEvents.forEach(stepEvent => { @@ -168,7 +171,7 @@ versions.forEach((version) => { ...envVars, PW_BASE_URL: `http://localhost:${webAppPort}`, DD_TAGS: 'test.customtag:customvalue,test.customtag2:customvalue2', - DD_SESSION_NAME: 'my-test-session' + DD_TEST_SESSION_NAME: 'my-test-session' }, stdio: 'pipe' } diff --git a/integration-tests/test-api-manual.spec.js b/integration-tests/test-api-manual.spec.js index 8335745e2a6..419c7c736c5 100644 --- a/integration-tests/test-api-manual.spec.js +++ b/integration-tests/test-api-manual.spec.js @@ -73,7 +73,7 @@ describe('test-api-manual', () => { '--require ./ci-visibility/test-api-manual/test.fake.js ./ci-visibility/test-api-manual/run-fake-test-framework', { cwd, - env: { ...getCiVisAgentlessConfig(receiver.port), DD_CIVISIBILITY_MANUAL_API_ENABLED: '1' }, + env: getCiVisAgentlessConfig(receiver.port), stdio: 'pipe' } ) @@ -82,7 +82,7 @@ describe('test-api-manual', () => { }) }) - it('does not report test spans if DD_CIVISIBILITY_MANUAL_API_ENABLED is not set', (done) => { + it('does not report test spans if DD_CIVISIBILITY_MANUAL_API_ENABLED is set to false', (done) => { receiver.assertPayloadReceived(() => { const error = new Error('should not report spans') done(error) @@ -93,7 +93,10 @@ describe('test-api-manual', () => { '--require ./ci-visibility/test-api-manual/test.fake.js ./ci-visibility/test-api-manual/run-fake-test-framework', { cwd, - env: getCiVisAgentlessConfig(receiver.port), + env: { + ...getCiVisAgentlessConfig(receiver.port), + DD_CIVISIBILITY_MANUAL_API_ENABLED: 'false' + }, stdio: 'pipe' } ) diff --git a/integration-tests/vitest/vitest.spec.js b/integration-tests/vitest/vitest.spec.js index 05a5fe42061..f2fb9a6ef12 100644 --- a/integration-tests/vitest/vitest.spec.js +++ b/integration-tests/vitest/vitest.spec.js @@ -21,6 +21,7 @@ const { TEST_SOURCE_FILE, TEST_SOURCE_START } = require('../../packages/dd-trace/src/plugins/util/test') +const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env') const versions = ['1.6.0', 'latest'] @@ -145,6 +146,7 @@ versions.forEach((version) => { testEvents.forEach(test => { assert.equal(test.content.meta[TEST_COMMAND], 'vitest run') + assert.exists(test.content.metrics[DD_HOST_CPU_COUNT]) }) testSuiteEvents.forEach(testSuite => { @@ -153,6 +155,7 @@ versions.forEach((version) => { testSuite.content.meta[TEST_SOURCE_FILE].startsWith('ci-visibility/vitest-tests/test-visibility') ) assert.equal(testSuite.content.metrics[TEST_SOURCE_START], 1) + assert.exists(testSuite.content.metrics[DD_HOST_CPU_COUNT]) }) // TODO: check error messages }).then(() => done()).catch(done) @@ -164,7 +167,7 @@ versions.forEach((version) => { env: { ...getCiVisAgentlessConfig(receiver.port), NODE_OPTIONS: '--import dd-trace/register.js -r dd-trace/ci/init', // ESM requires more flags - DD_SESSION_NAME: 'my-test-session' + DD_TEST_SESSION_NAME: 'my-test-session' }, stdio: 'pipe' } diff --git a/packages/datadog-plugin-fastify/test/integration-test/helper.mjs b/packages/datadog-plugin-fastify/test/integration-test/helper.mjs index 2c9c2ee8da0..e818008c977 100644 --- a/packages/datadog-plugin-fastify/test/integration-test/helper.mjs +++ b/packages/datadog-plugin-fastify/test/integration-test/helper.mjs @@ -4,7 +4,7 @@ export async function createAndStartServer (app) { }) try { - await app.listen(0) + await app.listen({ port: 0 }) const address = app.server.address() const port = address.port process.send({ port }) diff --git a/packages/datadog-plugin-openai/src/index.js b/packages/datadog-plugin-openai/src/index.js index 5eef54a8de5..f96b44543d2 100644 --- a/packages/datadog-plugin-openai/src/index.js +++ b/packages/datadog-plugin-openai/src/index.js @@ -276,25 +276,34 @@ class OpenApiPlugin extends TracingPlugin { const completionTokens = spanTags['openai.response.usage.completion_tokens'] const completionTokensEstimated = spanTags['openai.response.usage.completion_tokens_estimated'] + const totalTokens = spanTags['openai.response.usage.total_tokens'] + if (!error) { - if (promptTokensEstimated) { - this.metrics.distribution( - 'openai.tokens.prompt', promptTokens, [...tags, 'openai.estimated:true']) - } else { - this.metrics.distribution('openai.tokens.prompt', promptTokens, tags) + if (promptTokens != null) { + if (promptTokensEstimated) { + this.metrics.distribution( + 'openai.tokens.prompt', promptTokens, [...tags, 'openai.estimated:true']) + } else { + this.metrics.distribution('openai.tokens.prompt', promptTokens, tags) + } } - if (completionTokensEstimated) { - this.metrics.distribution( - 'openai.tokens.completion', completionTokens, [...tags, 'openai.estimated:true']) - } else { - this.metrics.distribution('openai.tokens.completion', completionTokens, tags) + + if (completionTokens != null) { + if (completionTokensEstimated) { + this.metrics.distribution( + 'openai.tokens.completion', completionTokens, [...tags, 'openai.estimated:true']) + } else { + this.metrics.distribution('openai.tokens.completion', completionTokens, tags) + } } - if (promptTokensEstimated || completionTokensEstimated) { - this.metrics.distribution( - 'openai.tokens.total', promptTokens + completionTokens, [...tags, 'openai.estimated:true']) - } else { - this.metrics.distribution('openai.tokens.total', promptTokens + completionTokens, tags) + if (totalTokens != null) { + if (promptTokensEstimated || completionTokensEstimated) { + this.metrics.distribution( + 'openai.tokens.total', totalTokens, [...tags, 'openai.estimated:true']) + } else { + this.metrics.distribution('openai.tokens.total', totalTokens, tags) + } } } @@ -777,9 +786,9 @@ function usageExtraction (tags, body, methodName, openaiStore) { if (completionEstimated) tags['openai.response.usage.completion_tokens_estimated'] = true } - if (promptTokens) tags['openai.response.usage.prompt_tokens'] = promptTokens - if (completionTokens) tags['openai.response.usage.completion_tokens'] = completionTokens - if (totalTokens) tags['openai.response.usage.total_tokens'] = totalTokens + if (promptTokens != null) tags['openai.response.usage.prompt_tokens'] = promptTokens + if (completionTokens != null) tags['openai.response.usage.completion_tokens'] = completionTokens + if (totalTokens != null) tags['openai.response.usage.total_tokens'] = totalTokens } function truncateApiKey (apiKey) { diff --git a/packages/datadog-plugin-openai/test/index.spec.js b/packages/datadog-plugin-openai/test/index.spec.js index b10b912dbb4..8df38a11650 100644 --- a/packages/datadog-plugin-openai/test/index.spec.js +++ b/packages/datadog-plugin-openai/test/index.spec.js @@ -560,6 +560,57 @@ describe('Plugin', () => { }) }) + describe('embedding with missing usages', () => { + afterEach(() => { + nock.cleanAll() + }) + + it('makes a successful call', async () => { + nock('https://api.openai.com:443') + .post('/v1/embeddings') + .reply(200, { + object: 'list', + data: [{ + object: 'embedding', + index: 0, + embedding: [-0.0034387498, -0.026400521] + }], + model: 'text-embedding-ada-002-v2', + usage: { + prompt_tokens: 0 + } + }, []) + + const checkTraces = agent + .use(traces => { + expect(traces[0][0].metrics).to.have.property('openai.response.usage.prompt_tokens', 0) + expect(traces[0][0].metrics).to.not.have.property('openai.response.usage.completion_tokens') + expect(traces[0][0].metrics).to.not.have.property('openai.response.usage.total_tokens') + }) + + const params = { + model: 'text-embedding-ada-002', + input: '', + user: 'hunter2' + } + + if (semver.satisfies(realVersion, '>=4.0.0')) { + const result = await openai.embeddings.create(params) + expect(result.model).to.eql('text-embedding-ada-002-v2') + } else { + const result = await openai.createEmbedding(params) + expect(result.data.model).to.eql('text-embedding-ada-002-v2') + } + + await checkTraces + + expect(metricStub).to.have.been.calledWith('openai.request.duration') // timing value not guaranteed + expect(metricStub).to.have.been.calledWith('openai.tokens.prompt') + expect(metricStub).to.not.have.been.calledWith('openai.tokens.completion') + expect(metricStub).to.not.have.been.calledWith('openai.tokens.total') + }) + }) + describe('list models', () => { let scope diff --git a/packages/dd-trace/src/config.js b/packages/dd-trace/src/config.js index 0060062b4eb..dc5bb524d1a 100644 --- a/packages/dd-trace/src/config.js +++ b/packages/dd-trace/src/config.js @@ -497,7 +497,7 @@ class Config { this._setValue(defaults, 'isGitUploadEnabled', false) this._setValue(defaults, 'isIntelligentTestRunnerEnabled', false) this._setValue(defaults, 'isManualApiEnabled', false) - this._setValue(defaults, 'ciVisibilitySessionName', '') + this._setValue(defaults, 'ciVisibilityTestSessionName', '') this._setValue(defaults, 'logInjection', false) this._setValue(defaults, 'lookup', undefined) this._setValue(defaults, 'memcachedCommandEnabled', false) @@ -536,7 +536,7 @@ class Config { this._setValue(defaults, 'telemetry.dependencyCollection', true) this._setValue(defaults, 'telemetry.enabled', true) this._setValue(defaults, 'telemetry.heartbeatInterval', 60000) - this._setValue(defaults, 'telemetry.logCollection', true) + this._setValue(defaults, 'telemetry.logCollection', false) this._setValue(defaults, 'telemetry.metrics', true) this._setValue(defaults, 'traceId128BitGenerationEnabled', true) this._setValue(defaults, 'traceId128BitLoggingEnabled', false) @@ -1003,10 +1003,10 @@ class Config { } _isCiVisibilityManualApiEnabled () { - return isTrue(coalesce( + return coalesce( process.env.DD_CIVISIBILITY_MANUAL_API_ENABLED, - false - )) + true + ) } _isTraceStatsComputationEnabled () { @@ -1035,7 +1035,7 @@ class Config { DD_CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED, DD_CIVISIBILITY_FLAKY_RETRY_ENABLED, DD_CIVISIBILITY_FLAKY_RETRY_COUNT, - DD_SESSION_NAME + DD_TEST_SESSION_NAME } = process.env if (DD_CIVISIBILITY_AGENTLESS_URL) { @@ -1050,8 +1050,8 @@ class Config { coalesce(DD_CIVISIBILITY_FLAKY_RETRY_ENABLED, true)) this._setValue(calc, 'flakyTestRetriesCount', coalesce(maybeInt(DD_CIVISIBILITY_FLAKY_RETRY_COUNT), 5)) this._setBoolean(calc, 'isIntelligentTestRunnerEnabled', isTrue(this._isCiVisibilityItrEnabled())) - this._setBoolean(calc, 'isManualApiEnabled', this._isCiVisibilityManualApiEnabled()) - this._setString(calc, 'ciVisibilitySessionName', DD_SESSION_NAME) + this._setBoolean(calc, 'isManualApiEnabled', !isFalse(this._isCiVisibilityManualApiEnabled())) + this._setString(calc, 'ciVisibilityTestSessionName', DD_TEST_SESSION_NAME) } this._setString(calc, 'dogstatsd.hostname', this._getHostname()) this._setBoolean(calc, 'isGitUploadEnabled', @@ -1071,6 +1071,13 @@ class Config { calc['tracePropagationStyle.inject'] = calc['tracePropagationStyle.inject'] || defaultPropagationStyle calc['tracePropagationStyle.extract'] = calc['tracePropagationStyle.extract'] || defaultPropagationStyle } + + const iastEnabled = coalesce(this._options['iast.enabled'], this._env['iast.enabled']) + const profilingEnabled = coalesce(this._options['profiling.enabled'], this._env['profiling.enabled']) + const injectionIncludesProfiler = (this._env.injectionEnabled || []).includes('profiler') + if (iastEnabled || ['auto', 'true'].includes(profilingEnabled) || injectionIncludesProfiler) { + this._setBoolean(calc, 'telemetry.logCollection', true) + } } _applyRemote (options) { diff --git a/packages/dd-trace/src/plugin_manager.js b/packages/dd-trace/src/plugin_manager.js index 9c871291c22..80e87ce545e 100644 --- a/packages/dd-trace/src/plugin_manager.js +++ b/packages/dd-trace/src/plugin_manager.js @@ -137,7 +137,7 @@ module.exports = class PluginManager { dsmEnabled, clientIpEnabled, memcachedCommandEnabled, - ciVisibilitySessionName + ciVisibilityTestSessionName } = this._tracerConfig const sharedConfig = { @@ -147,7 +147,7 @@ module.exports = class PluginManager { site, url, headers: headerTags || [], - ciVisibilitySessionName + ciVisibilityTestSessionName } if (logInjection !== undefined) { diff --git a/packages/dd-trace/src/plugins/util/env.js b/packages/dd-trace/src/plugins/util/env.js index c53c0956e53..c1721c4bb11 100644 --- a/packages/dd-trace/src/plugins/util/env.js +++ b/packages/dd-trace/src/plugins/util/env.js @@ -5,6 +5,7 @@ const OS_VERSION = 'os.version' const OS_ARCHITECTURE = 'os.architecture' const RUNTIME_NAME = 'runtime.name' const RUNTIME_VERSION = 'runtime.version' +const DD_HOST_CPU_COUNT = '_dd.host.vcpu_count' function getRuntimeAndOSMetadata () { return { @@ -12,7 +13,8 @@ function getRuntimeAndOSMetadata () { [OS_ARCHITECTURE]: process.arch, [OS_PLATFORM]: process.platform, [RUNTIME_NAME]: 'node', - [OS_VERSION]: os.release() + [OS_VERSION]: os.release(), + [DD_HOST_CPU_COUNT]: os.cpus().length } } @@ -22,5 +24,6 @@ module.exports = { OS_VERSION, OS_ARCHITECTURE, RUNTIME_NAME, - RUNTIME_VERSION + RUNTIME_VERSION, + DD_HOST_CPU_COUNT } diff --git a/packages/dd-trace/src/plugins/util/test.js b/packages/dd-trace/src/plugins/util/test.js index 6d2e367c09c..3cf1421ad15 100644 --- a/packages/dd-trace/src/plugins/util/test.js +++ b/packages/dd-trace/src/plugins/util/test.js @@ -631,8 +631,8 @@ function getIsFaultyEarlyFlakeDetection (projectSuites, testsBySuiteName, faulty } function getTestSessionName (config, testCommand, envTags) { - if (config.ciVisibilitySessionName) { - return config.ciVisibilitySessionName + if (config.ciVisibilityTestSessionName) { + return config.ciVisibilityTestSessionName } if (envTags[CI_JOB_NAME]) { return `${envTags[CI_JOB_NAME]}-${testCommand}` diff --git a/packages/dd-trace/src/telemetry/index.js b/packages/dd-trace/src/telemetry/index.js index a0b0619a11d..612c23b7ca1 100644 --- a/packages/dd-trace/src/telemetry/index.js +++ b/packages/dd-trace/src/telemetry/index.js @@ -137,7 +137,6 @@ function appClosing () { sendData(config, application, host, reqType, payload) // We flush before shutting down. metricsManager.send(config, application, host) - telemetryLogger.send(config, application, host) } function onBeforeExit () { diff --git a/packages/dd-trace/test/config.spec.js b/packages/dd-trace/test/config.spec.js index e047ab74e9d..ca4d8b142d3 100644 --- a/packages/dd-trace/test/config.spec.js +++ b/packages/dd-trace/test/config.spec.js @@ -323,7 +323,7 @@ describe('Config', () => { { name: 'isGitUploadEnabled', value: false, origin: 'default' }, { name: 'isIntelligentTestRunnerEnabled', value: false, origin: 'default' }, { name: 'isManualApiEnabled', value: false, origin: 'default' }, - { name: 'ciVisibilitySessionName', value: '', origin: 'default' }, + { name: 'ciVisibilityTestSessionName', value: '', origin: 'default' }, { name: 'logInjection', value: false, origin: 'default' }, { name: 'lookup', value: undefined, origin: 'default' }, { name: 'openAiLogsEnabled', value: false, origin: 'default' }, @@ -362,7 +362,7 @@ describe('Config', () => { { name: 'telemetry.dependencyCollection', value: true, origin: 'default' }, { name: 'telemetry.enabled', value: true, origin: 'env_var' }, { name: 'telemetry.heartbeatInterval', value: 60000, origin: 'default' }, - { name: 'telemetry.logCollection', value: true, origin: 'default' }, + { name: 'telemetry.logCollection', value: false, origin: 'default' }, { name: 'telemetry.metrics', value: true, origin: 'default' }, { name: 'traceId128BitGenerationEnabled', value: true, origin: 'default' }, { name: 'traceId128BitLoggingEnabled', value: false, origin: 'default' }, @@ -1461,7 +1461,7 @@ describe('Config', () => { expect(config.telemetry).to.not.be.undefined expect(config.telemetry.enabled).to.be.true expect(config.telemetry.heartbeatInterval).to.eq(60000) - expect(config.telemetry.logCollection).to.be.true + expect(config.telemetry.logCollection).to.be.false expect(config.telemetry.debug).to.be.false expect(config.telemetry.metrics).to.be.true }) @@ -1499,7 +1499,7 @@ describe('Config', () => { process.env.DD_TELEMETRY_METRICS_ENABLED = origTelemetryMetricsEnabledValue }) - it('should disable log collection if DD_TELEMETRY_LOG_COLLECTION_ENABLED is false', () => { + it('should not set DD_TELEMETRY_LOG_COLLECTION_ENABLED', () => { const origLogsValue = process.env.DD_TELEMETRY_LOG_COLLECTION_ENABLED process.env.DD_TELEMETRY_LOG_COLLECTION_ENABLED = 'false' @@ -1510,6 +1510,17 @@ describe('Config', () => { process.env.DD_TELEMETRY_LOG_COLLECTION_ENABLED = origLogsValue }) + it('should set DD_TELEMETRY_LOG_COLLECTION_ENABLED if DD_IAST_ENABLED', () => { + const origIastEnabledValue = process.env.DD_IAST_ENABLED + process.env.DD_IAST_ENABLED = 'true' + + const config = new Config() + + expect(config.telemetry.logCollection).to.be.true + + process.env.DD_IAST_ENABLED = origIastEnabledValue + }) + it('should set DD_TELEMETRY_DEBUG', () => { const origTelemetryDebugValue = process.env.DD_TELEMETRY_DEBUG process.env.DD_TELEMETRY_DEBUG = 'true' @@ -1798,7 +1809,7 @@ describe('Config', () => { delete process.env.DD_CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED delete process.env.DD_CIVISIBILITY_FLAKY_RETRY_ENABLED delete process.env.DD_CIVISIBILITY_FLAKY_RETRY_COUNT - delete process.env.DD_SESSION_NAME + delete process.env.DD_TEST_SESSION_NAME delete process.env.JEST_WORKER_ID options = {} }) @@ -1824,14 +1835,14 @@ describe('Config', () => { const config = new Config(options) expect(config).to.have.property('isIntelligentTestRunnerEnabled', false) }) - it('should disable manual testing API by default', () => { + it('should enable manual testing API by default', () => { const config = new Config(options) - expect(config).to.have.property('isManualApiEnabled', false) + expect(config).to.have.property('isManualApiEnabled', true) }) - it('should enable manual testing API if DD_CIVISIBILITY_MANUAL_API_ENABLED is passed', () => { - process.env.DD_CIVISIBILITY_MANUAL_API_ENABLED = 'true' + it('should disable manual testing API if DD_CIVISIBILITY_MANUAL_API_ENABLED is set to false', () => { + process.env.DD_CIVISIBILITY_MANUAL_API_ENABLED = 'false' const config = new Config(options) - expect(config).to.have.property('isManualApiEnabled', true) + expect(config).to.have.property('isManualApiEnabled', false) }) it('should disable memcached command tagging by default', () => { const config = new Config(options) @@ -1883,10 +1894,10 @@ describe('Config', () => { const config = new Config(options) expect(config).to.have.property('flakyTestRetriesCount', 5) }) - it('should set the session name if DD_SESSION_NAME is set', () => { - process.env.DD_SESSION_NAME = 'my-test-session' + it('should set the session name if DD_TEST_SESSION_NAME is set', () => { + process.env.DD_TEST_SESSION_NAME = 'my-test-session' const config = new Config(options) - expect(config).to.have.property('ciVisibilitySessionName', 'my-test-session') + expect(config).to.have.property('ciVisibilityTestSessionName', 'my-test-session') }) }) context('ci visibility mode is not enabled', () => { diff --git a/packages/dd-trace/test/plugins/util/env.spec.js b/packages/dd-trace/test/plugins/util/env.spec.js index d3cd7bf47e3..5a799897df4 100644 --- a/packages/dd-trace/test/plugins/util/env.spec.js +++ b/packages/dd-trace/test/plugins/util/env.spec.js @@ -9,7 +9,8 @@ const { OS_PLATFORM, OS_VERSION, RUNTIME_NAME, - RUNTIME_VERSION + RUNTIME_VERSION, + DD_HOST_CPU_COUNT } = require('../../../src/plugins/util/env') describe('env', () => { @@ -22,7 +23,8 @@ describe('env', () => { [OS_ARCHITECTURE]: process.arch, [OS_PLATFORM]: process.platform, [RUNTIME_NAME]: 'node', - [OS_VERSION]: os.release() + [OS_VERSION]: os.release(), + [DD_HOST_CPU_COUNT]: os.cpus().length } ) })