Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/dd-trace/src/startup-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ function configInfo () {
profiling_enabled: profilingEnabled === 'true' || profilingEnabled === 'auto',
appsec_enabled: config.appsec.enabled,
data_streams_enabled: !!config.dsmEnabled,
otlp_traces_export_enabled: config.OTEL_TRACES_EXPORTER === 'otlp' && !config.isCiVisibility,
otlp_metrics_export_enabled: !!config.DD_METRICS_OTEL_ENABLED,
otlp_logs_export_enabled: !!config.DD_LOGS_OTEL_ENABLED,
}
}

Expand Down
72 changes: 71 additions & 1 deletion packages/dd-trace/test/startup-log.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('node:assert')
const os = require('node:os')

const { describe, it, before, afterEach } = require('mocha')
const { describe, it, before, beforeEach, afterEach } = require('mocha')
const sinon = require('sinon')

require('./setup/core')
Expand Down Expand Up @@ -80,6 +80,9 @@ describe('startup logging', () => {
assert.strictEqual(logObj.debug, true)
assert.strictEqual(logObj.appsec_enabled, true)
assert.strictEqual(logObj.data_streams_enabled, true)
assert.strictEqual('otlp_traces_export_enabled' in logObj, true)
assert.strictEqual('otlp_metrics_export_enabled' in logObj, true)
assert.strictEqual('otlp_logs_export_enabled' in logObj, true)
})

it('logIntegrations should output loaded integrations', () => {
Expand Down Expand Up @@ -121,6 +124,9 @@ describe('startup logging', () => {
integrations_loaded: ['http', 'fs', 'semver'],
appsec_enabled: true,
data_streams_enabled: true,
otlp_traces_export_enabled: false,
otlp_metrics_export_enabled: false,
otlp_logs_export_enabled: false,
})
})
})
Expand Down Expand Up @@ -314,3 +320,67 @@ describe('profiling_enabled', () => {
})
})
})

describe('otlp export flags', () => {
function clearOtlpEnv () {
delete process.env.OTEL_TRACES_EXPORTER
delete process.env.DD_METRICS_OTEL_ENABLED
delete process.env.DD_LOGS_OTEL_ENABLED
}

// Clear before each test too: this repo's dev shells export OTEL_TRACES_EXPORTER=otlp,
// which would otherwise leak into the default-state assertion.
beforeEach(clearOtlpEnv)
afterEach(clearOtlpEnv)

function startupLogObj (configOptions) {
sinon.stub(console, 'warn')
delete require.cache[require.resolve('../src/startup-log')]
const {
setStartupLogConfig,
startupLog,
} = require('../src/startup-log')
process.env.DD_TRACE_STARTUP_LOGS = 'true'
setStartupLogConfig(getConfigFresh(configOptions))
startupLog()
/* eslint-disable-next-line no-console */
const warnStub = /** @type {sinon.SinonStub} */ (console.warn)
const logObj = JSON.parse(warnStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
warnStub.restore()
return logObj
}

it('should default to false when no OTLP env vars are set', () => {
const logObj = startupLogObj()
assert.strictEqual(logObj.otlp_traces_export_enabled, false)
assert.strictEqual(logObj.otlp_metrics_export_enabled, false)
assert.strictEqual(logObj.otlp_logs_export_enabled, false)
})

it('otlp_traces_export_enabled should be true when OTEL_TRACES_EXPORTER is otlp', () => {
process.env.OTEL_TRACES_EXPORTER = 'otlp'
assert.strictEqual(startupLogObj().otlp_traces_export_enabled, true)
})

it('otlp_traces_export_enabled should be false when OTEL_TRACES_EXPORTER is none', () => {
process.env.OTEL_TRACES_EXPORTER = 'none'
assert.strictEqual(startupLogObj().otlp_traces_export_enabled, false)
})

it('otlp_traces_export_enabled should be false in Test Optimization mode even when exporter is otlp', () => {
// Test Optimization keeps test spans on the citestcycle endpoint, so the OTLP
// trace exporter is not used regardless of OTEL_TRACES_EXPORTER (see opentracing/tracer.js).
process.env.OTEL_TRACES_EXPORTER = 'otlp'
assert.strictEqual(startupLogObj({ isCiVisibility: true }).otlp_traces_export_enabled, false)
})

it('otlp_metrics_export_enabled should be true when DD_METRICS_OTEL_ENABLED is true', () => {
process.env.DD_METRICS_OTEL_ENABLED = 'true'
assert.strictEqual(startupLogObj().otlp_metrics_export_enabled, true)
})

it('otlp_logs_export_enabled should be true when DD_LOGS_OTEL_ENABLED is true', () => {
process.env.DD_LOGS_OTEL_ENABLED = 'true'
assert.strictEqual(startupLogObj().otlp_logs_export_enabled, true)
})
})
Loading